In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use C++ to achieve mine clearance game, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to know about it.
The original version of Minesweeper can be traced back to a game called "Box" in 1973. Soon, "Square" was rewritten into the game "Rlogic". In Rlogic, the player's task is to find a mine-free safe route for the command center as a member of the U.S. Marine Corps, and lose if the road is blocked by mines. Two years later, Tom Anderson wrote the game Mine on the basis of Rlogic, which established the embryonic form of the modern minesweeping game. The Minesweeper game was officially popularized around the world in 1981 when two engineers, Robert Doyle and Carter Johnson of Microsoft, loaded the game on Windows3.1.
The game is played by randomly placing a certain number of mines (10 for primary, 40 for intermediate, and 99 for advanced) in a matrix of 99,16,16,30 (advanced) or custom-sized squares. The player opens the box one by one to find out all the mines as the final goal of the game. If the player opens a square with mines, the game is over.
It is not very difficult for us to write the project "Minesweeper" today. Let's talk about it in detail from beginning to end. We must watch and learn!
All right, here we go.
Today we use Cpp to write, but not to use Windows to create the window, but to use his distant cousin EasyX graphics library to create the window, because it will be much easier to use the graphics library, just learned C can also understand, and C _ Windows + no separation, no problem, OK, we now start to write code, today I will also share the header file, mainly to teach you how to call the graphics library. (note: if there is no EasyX graphics library, you can download it from the official website or directly from the group.) first, our header file and some macro definitions.
# include#include// contains the number of graphics library header files # define ROW 9 / / row # define COL 9 / / columns in 81 squares # define MINE_NUM 18amp / mine # define IMG_SIZE 40
Initialization function is also an old friend of ours.
Void GameInit () {/ / 1, create window with nine pictures per line 40px, initgraph (IMG_SIZE*ROW, IMG_SIZE*COL,SHOWCONSOLE); / / load picture (assignment) load load the first parameter, the variable to store the image is incorrect: character set problem for (int I = 0; I < 12; iDiag+) {char file [20] = "" Sprintf (file, ". / image/%d.jpg", I); loadimage (& IMG [I], file, IMG_SIZE, IMG_SIZE);} / / Mine laying for (int I = 0; I < MINE_NUM;) {/ / excluding auxiliary area int row = rand ()% ROW+1 / / 0-8 1-9 int col = rand ()% COL+1; if (mine [row] [col] = = 0) {mine [row] [col] = 9; iTunes + }} / / the ninth palace grid where Lei is located, add 1 (except mine) for (int I = 1; I < ROW+1; iTunes +) {for (int k = 1; k < COL+1) ) {if (mine [I] [k] = = 9) {/ / traversing Lei's careful for (int a = I-1; a 9 & & mine [openr] [openc])
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.