工欲善其事, its prerequisite, first of all to prepare the development environment, since is the C language, that is not the winapi of mine, is pure C language development, but the previous C are TC development, now with must be outdated for a long time, but there are solutions, some great God developed easyx this library, Basically the function of the TC is restored, it can be used under a variety of Ides, and the following is and help, to help inside have all functions of the calling method
http://www.easyx.cn/
After the download unzip the include and Lib folders to your VC corresponding to the installation of the folder can be used, from vc++6.0 to vs2013 can be used
I'm using vs2013, which is the C11 standard, probably not the same as vc++6.0 and previous versions of the function.
The following is the beginning of development, the simplest idea is to draw a graphical interface, run the game, so you can directly start
#include <stdio.h> #include <graphics.h>//graph related functions Many functions include the mouse operation int main (void) { Initgraph (showconsole);//Initialize game interface and size game ();//Run Game closegraph ();//Close Graphical interface}
You can comment out the game () to test if your easyx is installed, and if it is installed, it will draw a 200*230 window.
Next is the need to use the variable declaration and use of functions, their own development can be developed side write, in order to facilitate the first list, and then direct write function
Struct{int num;//Lattice Current state, 1 means that there is thunder, 0 means no thunder or already shows the number int roundnum;//statistic lattice around the number of mines int flag;//right-click to display the red flag, 0 means no, 1 means there is}mine[10][10]; int play = 0;//is the first time to play the flag int flag = 1;//If the game fails to restart after the flag int AGAIN = 0;//Game restarts Midway Flag int MouseX, mousey;//mouse x, y coordinate int minenum ;//Statistics processed lattice number TCHAR randminenum[100];//display number of string mousemsg m;//mouse structure variable, accept mouse message void game (void);//game main program void Gamebegin (void) ;//The Game begins void Drawempty (int,int,int,int);//function void Drawsmile (void) to initialize the empty lattice interface;//the function to draw a smiley face is void drawredflag (int, int);// Right button to draw red flag function void Gameover (void);//game end void Gamewin (void);//game victory void GamePlay (void);//Game Execution process
Next talk about mouse processing events, the previous TC is DOS mode development, operation equivalent to Xie Mouse driver, need to check various interrupts, and EASYX now the mouse message processing is very convenient, and do not need like WIN32 message loop mechanism, convenient a lot of
The following is the official document of the mouse function
Mousemsg
This structure is used to save the mouse message, as defined below:
struct mousemsg{ UINT umsg; Current mouse message bool Mkctrl; The Ctrl key is pressed with bool Mkshift; The Shift key presses the bool Mklbutton;//The left mouse button presses bool Mkmbutton, or whether the middle mouse button presses bool Mkrbutton;//The right mouse button presses int x;< c10/>//current mouse x coordinate (physical coordinate) int y; Current mouse y coordinate (physical coordinates) int wheel; Mouse wheel Scroll value};
Umsg:
Specifies the mouse message type, which can be the following values:
Wm_mousemove
The mouse moves the message.
WM_MouseWheel
The mouse wheel toggles the message.
Wm_lbuttondown
Left-click the message.
Wm_lbuttonup
Left button to pop up the message.
Wm_lbuttondblclk
Left-click the message.
Wm_mbuttondown
Middle button to press the message.
Wm_mbuttonup
The middle key bounces up the message.
Wm_mbuttondblclk
Middle-Key Double-click the message.
Wm_rbuttondown
Right-click the message.
Wm_rbuttonup
Right-click to pop up the message.
Wm_rbuttondblclk
Right-click the message.
Mkctrl
Ctrl key is pressed
Mkshift
The Shift key is pressed
Mklbutton
Whether the left mouse button is pressed
Mkmbutton
Whether the middle mouse button is pressed
Mkrbutton
Whether the right mouse button is pressed
X
Current mouse x-coordinate (physical coordinate)
Y
Current Mouse y-coordinate (physical coordinate)
Wheel
The scroll value of the mouse wheel is a multiple of 120.
These are the mouse operation, the function is very powerful!
C Language New handwriting minesweeper Strategy 1