C Language New handwriting minesweeper Strategy 3

Source: Internet
Author: User

After the interface is drawn, the number of thunder is also arranged, the next is the game running process, today, not to say the specific process, then to see the need to use the auxiliary function

First, a simple red flag, the right mouse button function is to draw a red flag, so far we are in the use of the function of their own drawing, efficiency is low, but helps to understand

void Drawredflag (int i, int j) {Setfillstyle (bs_solid); Setfillcolor (RED); Bar (8 + J *, + I *, 8 + J * 20 + 5, 35 + I * + 5); SetColor (BLACK), line (8 + J *, + I *, 8 + J *, + I * 20 + 10);}

The coordinates are good offsets, and you can calculate the offset coordinates according to the position of your game.

Next is the important count of thunder, which counts the number of eight squares around a lattice.

int minestatistics (int i, int j)/* Count the number of mines around each lattice */{int nnum = 0;if (i = = 0 && j = 0)//////statistics */{if of upper left grid (Mine[0][1].num = = 1) nnum++;if (mine[1][0].num = = 1) nnum++;if (mine[1][1].num = = 1) nnum++;} ElseIf (i = = 0 && j = 9)///*/{if (Mine[0][8].num = = 1) nnum++;if (mine[1][9].num = 1) nnum++;if (mine[1][8)///upper right grid . num = = 1) nnum++;} ElseIf (i = = 9 && j = 0)///*/{if (Mine[8][0].num = = 1) nnum++;if (mine[9][1].num = 1) nnum++;if (mine[8][1] . num = = 1) nnum++;} ElseIf (i = = 9 && j = 9)///*/{if (Mine[9][8].num = = 1) nnum++;if (mine[8][9].num = 1) nnum++;if (Mine[8][8] . num = = 1) nnum++;} else if (j = = 0)/* Statistics */{if (mine[i][j + 1].num = 1) nnum++;if (mine[i + 1][j].num = 1) on the left of the first column and nnum++;if (mine[i-1][j].nu m = = 1) nnum++;if (mine[i-1][j + 1].num = = 1) nnum++;if (mine[i + 1][j + 1].num = = 1) nnum++;} else if (j = = 9)/* Statistics */{if (mine[i][j-1].num = = 1) nnum++;if (mine[i + 1][j].num = 1) on the right of the first row of squares (nnum++;if m = = 1) nnum++;if (mine[i-1][j-1].num = = 1)Nnum++;if (mine[i + 1][j-1].num = = 1) nnum++;} else if (i = = 0)///First row lattice statistics */{if (mine[i + 1][j].num = 1) nnum++;if (mine[i][j-1].num = 1) nnum++;if (mine[i][j + 1].num = = 1) nnum++;if (mine[i + 1][j-1].num = = 1) nnum++;if (mine[i + 1][j + 1].num = = 1) nnum++;}  else if (i = = 9)///Last row of grid statistics */{if (mine[i-1][j].num = = 1) nnum++;if (mine[i][j-1].num = = 1) nnum++;if (mine[i][j + 1].num = = 1) nnum++;if (mine[i-1][j-1].num = = 1) nnum++;if (mine[i-1][j + 1].num = 1) nnum++;} else/* General lattice Statistics */{if (mine[i-1][j].num = = 1) nnum++;if (mine[i-1][j + 1].num = 1) nnum++;if (mine[i][j + 1].num = 1) NNUM ++;if (mine[i + 1][j + 1].num = = 1) nnum++;if (mine[i + 1][j].num = 1) nnum++;if (mine[i + 1][j-1].num = 1) nnum++;if (Mi Ne[i][j-1].num = = 1) nnum++;if (mine[i-1][j-1].num = = 1) nnum++;} Return nnum;/* The statistical results of the number of thunder numbers around the lattice returned */}

The return value of this function is the number of mines around this individual, that is, the number displayed after the clearance point is opened.

Not every lattice has thunder, there are continuous areas are no thunder, so to the reality of blank lattice

void Showwhite (int i, int j)/* Displays blank portions of mined-out areas */{if (Mine[i][j].flag = = 1 | | Mine[i][j].num = = 0)/* If there is a red flag or if the lattice has been disposed of, no judgment will be made on the lattice */return;minenum--;/* shows a number or a space in the lattice is to deal with a lattice, when all the lattice has been processed to indicate Victory */if (Mine I [J].roundnum = = 0 && mine[i][j].num! = 1)/* Show Spaces */{drawempty (i, J, 1, White); Mine[i][j].num = 0;} ElseIf (Mine[i][j].roundnum! = 0)/* Output Thunder number */{drawempty (i, J, 1, White); _stprintf_s (Randminenum, _t ("%d"), Mine[i][j]. Roundnum); SetColor (RED); Outtextxy (6 + J *, + + i *, randminenum); Mine[i][j].num = 0;/* has output the number of the grid with 0 indicates that the lattice has been used */return;} /*8 display all blank lattices recursively */if (i! = 0 && Mine[i-1][j].num! = 1) showwhite (I-1, j); if (i! = 0 && J! = 9 &&am P Mine[i-1][j + 1].num! = 1) showwhite (i-1, J + 1); if (j! = 9 && mine[i][j + 1].num! = 1) Showwhite (i, j + 1); if ( J! = 9 && I! = 9 && mine[i + 1][j + 1].num! = 1) showwhite (i + 1, j + 1); if (i! = 9 && mine[i + 1][) J].num! = 1) showwhite (i + 1, j); if (i! = 9 && J! = 0 && mine[i + 1][j-1].num! = 1) ShOwwhite (i + 1, j-1); if (j! = 0 && Mine[i][j-1].num! = 1) showwhite (i, j-1); if (i! = 0 && J! = 0 & & Mine[i-1][j-1].num! = 1) showwhite (i-1, j-1);}

These are auxiliary functions, basically!

C Language New handwriting minesweeper Strategy 3

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.