In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people don't understand the knowledge points of this article "How to realize fun minesweeping game in C++," so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "How to realize fun minesweeping game in C++."
process design
1. Initialize the array.
2. Enter coordinate points.
3. Choices: dig, mark, unmark, restart, exit game.
If mining is selected, the game ends if the coordinate point is a mine, the number is displayed and returns to 2 if it is a number, and the value of the surrounding 8 elements is displayed if it is a space until the associated space is displayed and returns to 2;
If the marker is selected, set the element value at that point to-2 and back to 2;
If cancel flag is selected, initialize the point and go back to 2;
If Restart is selected, initialize the array and go back to 2;
If you choose to quit the game, exit.
4. After digging all the non-mine points, the game wins, choose whether to play again, if yes, return to 1, otherwise exit
object-oriented design idea
Create a bombsweep class that stores several methods:
calculate: count the number of mines at eight points around (x,y).
Game: Simulate the game process.
print: Print an array.
check: Check whether the victory conditions are met.
In the main function, create bs objects from the bombsweep class when needed, and call the relevant methods in bs.
program code
#include #include #include #include using namespace std;int map[12][12]; // ??????????,???????????? 1int derection[3] = { 0, 1, -1 }; //???????? 8????? int type;class bombsweep{public: int calculate ( int x, int y ) { int counter = 0; for ( int i = 0; i < 3; i++ ) for ( int j = 0; j < 3; j++ ) if ( map[ x+derection[i]][ y+derection[j] ] == 9 ) counter++; // ??? (x,y)????? 8??????? return counter; } void game ( int x, int y ) { if ( calculate ( x, y ) == 0 ) { map[x][y] = 0; for ( int i = 0; i < 3; i++ ) { // ???????,????????? for ( int j = 0; j < 3; j++ ) if ( x+derection[i] = 1 && ! ( derection[i] == 0 && derection[j] == 0 ) && map[x+derection[i]][y+derection[j]] == -1 ) game( x+derection[i], y+derection[j] ); // ??????????????? 0,????????! } //????????.??????????? } else map[x][y] = calculate(x,y); } void print (int x,int y) { cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.