"VC + + Game development" intelligence game--nitpick (imitation minesweeper)

Source: Internet
Author: User



In my Learning game development process, encountered the biggest trouble is not aware of a game complete implementation process, the code is second.

Here, summarize the games I have done. The main is to comb the whole of each step.


Let's look at the results.



1th step, prepare the material picture

Contains eggs, bones, and numbers as well as bone markers and small hammers for smashing eggs.


2nd step, declare the Egg class

It consists of only 2 member variables

Class Cegg{public:int bitmap;//bitmap int num;//number};


2nd step, Initialize the interface

1.1 Or do you want to set the form parameters and icons in CMainFrame

1.2 and Gobang game different, here, to delete the toolbar and the status bar.

(See the OnCreate () function in the CMainFrame class in the code)


2. Load each resource, initialize the number of bones, number of marked bones, time, etc.


3.1 Randomly set several positions for displaying eggs with bones (num-1 for eggs with bones)

Set 25 bone int aa=0;do{        //With the current number of seconds for generating the stochastic algorithm        int k= (rand () *s)%rownum;        int l= (rand () *s)%colnum;        if (egg[k][l].num!=-1)        {    egg[k][l].num=-1;             aa++;}         } while (Aa!=bone);

After 3.2 calculate the number of bones around each egg.

Assign a value to the grid, calculate the number of bones for (int a=0;a<rownum;a++) for (        int b=0;b<colnum;b++) if (egg[a][b].num==0) {for (int c=a-1;c <a+2;c++) for (int d=b-1;d<b+2;d++) if (c>=0&&c<rownum&&d>=0&&d<colnum) if (egg[c][d].num==-1) egg[a][b].num++;        }



3.3 Displays the number of mines in the OnDraw () function of C**view, displays the button bitmap, displays the colored egg bitmap (via random function)

Display button Dc.selectobject (button[0]);pD C->bitblt (250,10,160,160,&dc,0,0,srccopy);


The code is much larger. No, it's all posted.


3.4 Setting when the mouse moves to the view-class interface, the hammer is displayed

BOOL cboneineggview::onsetcursor (cwnd* pWnd, uint nhittest, UINT message) {//TODO: Add the message Handler code here and/or call the default value if (nhittest== Htclient) {setcursor (cur); return 1;} Return Cview::onsetcursor (pWnd, nhittest, message);}


3rd step, complete game action response function

Now the interface is ready. Just to complete the left button press, Zuo Open, right-click function function, as well as another start function, scanning function can be.


Analyze the functions that are required to complete each action

Left-click:

First infer the position that is pressed, only the button bitmap above and the egg above the left click is valid.

Let's say you click on the button bitmap. Change the picture of the button bitmap (when the left button is released and then initialized again)

Suppose you click on the egg bitmap, and if there is no bone in the egg, the corresponding number is displayed. and redraw the surrounding 8 positions. When there is bone in the egg. Game over, stop timing


Left button to release:

Assume that it is above the button bitmap. Once again, initialize the interface

Assuming it's on the egg bitmap, cue the player, the game is over


Right-click: (Only on the egg, and the egg is the initial bitmap-like body, the operation is effective)

If you press it for the first time. The current position displays a warning flag. Number of bones shown in upper left corner-1

If you press the second time. Remove the warning flag, the top left corner shows the number of bones +1


Start again:

As with the initialization operation, the timing is set.


Scan function:

Suppose the current position is not an egg with bones. And there are 0 eggs with bones around it, then scan the 8 locations around it. and display the corresponding number

void Cboneineggview::scan (void) {for (Int. i=0;i<rownum;i++) for (int j=0;j<colnum;j++) if (egg[i][j].num==0& &egg[i][j].bitmap==1) {for (int n=i-1;n<i+2;n++) for (int m=j-1;m<j+2;m++) if (n>=0&&n<rownum &&m>=0&&m<colnum) if (egg[n][m].num!=-1&&egg[n][m].bitmap==0) {egg[n][m].bitmap=1; CRect Rect;rect.left=n*30+10;rect.right=n*30+40;rect.top=m*30+50;rect.bottom=m*30+80;invalidaterect (&rect);}}


Code address

Nitpick

"VC + + Game development" intelligence game--nitpick (imitation minesweeper)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.