#include
#include
#include
#include
# pragma comment (lib, "winmm. Lib")//
Int flag=0;//chess number
Int board [20] [20]={0};
Int panduan (int a, int b);
Void initGame ()//initialize the game
{
Initgraph (600400);
Loadimage (NULL, "hpic728. JPG");
//the background music
McISendString (" open city flower has been open. Mp3 ", 0, 0).
McISendString (" north flowers open. Play mp3, 0, 0).
//drawing board
Setlinecolor (BLACK);
For (int I=25; i<500; I +=25)
{
The line (I, 0, I, 500);
The line (0, I, 500, I);
}
The line (501,0,501,500);
Outtextxy (510100, player 1: "black");
Outtextxy (510150, "the player 2: white");
Outtextxy (510200, "ps: please do not in");
Outtextxy (510220, "edge move later");
}
//chess
Void playChess ()
{
MOUSEMSG m;//mouse structure
Int x=0, y=0;
Int a=0, b=0;
HWND HWND=GetHWnd ();
While (1)
{
M=GetMouseMsg ();
for(int i=1; i<20; I++)
{
for(int j=1; J<20; J++)
{
If (abs (m.x - I * 25) & lt; 12 & amp; & Abs (m.y - j * 25) & lt; 12)
{
X=I * 25;
Y=j * 25;
A=I;
B=j;
}
}
}
If (m.u Msg==WM_LBUTTONDOWN)
{
If (board [a] [b]!=0)
{
MessageBox (HWND, "there are pieces, please choose again!" ", "prompt", MB_OK);
continue;
}
If (flag % 2==0)
{setfillcolor (BLACK);
Solidcircle (x, y, 10);
Board [a] [b]=1;
}
The else {
Setfillcolor (WHITE);
Solidcircle (x, y, 10);
Board [a] [b]=2;
}
flag++;
If (panduan (a, b))
{
If (flag % 2==0)
{
MessageBox (HWND "player 2: white victory", "game over", MB_OK);
return;
}
The else
{MessageBox (HWND, player 1: black "victory", "game over", MB_OK);
return;
}
}
}
}
}
//determine win
Int panduan (int a, int b)
{
int i,j;
int t;
T=2 - flag % 2;
For (I=a - 4, j=b; i<=a; I++)
{
If (i>=0 & amp; & i<16 & amp; & T==board [I] [j] & amp; & T==board [j] [I + 1] & amp; & T==board [I + 2] [j] & amp; & T==board + 3 [I] [j] & amp; & T==board [I + 4] [j])
return 1;
}
For (I=a, j=b - 4; J<=b; J++)
{
If (j>=0 & amp; & J<16 & amp; & T==board [I] [j] & amp; & T==board [I] [m + 1] & amp; & T==board [I] [m + 2] & amp; & T==board + 3 [j] [I] & amp; & T==board [I] [j + 4])
return 1;
}
For (I=a - 4, j=b - 4; i<=a, j<=b; I++ j++)
{
If (i>=0 & amp; & i<16 & amp; & j>=0 & amp; & J<16 & amp; & T==board [I] [j] & amp; & T==board [I + 1] [m + 1] & amp; & T==board [I + 2] [m + 2] & amp; & T==board/I + 3, + 3 [j] & amp; & T==board [I + 4] [j + 4])
return 1;
}
For (I=a - 4, j=b + 4; i<=a, j>=1; I++, j -)
{
If (i>=0 & amp; & i<16 & amp; & j>=0 & amp; & J<16 & amp; & T==board [I] [j] & amp; & T==board + 1] [I] [j - 1 & amp; & T==board [I + 2] [j - 2] & amp; & T==board + 3 [I] [j - 3] & amp; & T==board [I + 4] [4])
return 1;
}
return 0;
}
Int menu ()
{
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" * * you are welcome to use the software \ n ");
Printf (" * * \ n ");
Gobang printf (" * * * * \ n ");
Printf (" * * \ n ");
Printf (" * * \ n ");
Printf (" * * * (1) enter the game \ n ");
Printf (" * * \ n ");
Printf (" * * (2) quit the game * \ n ");
Printf (" * * \ n ");
Printf (" * * (3) game shows * \ n ");
Printf (" * * \ n ");
Printf (" * * \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" please enter the corresponding digital manipulation \ n ");
return 0;
}
Int main ()
{
The switch (menu ())
{
Case 1:
InitGame (); break;
}
PlayChess ();
return 0;
}
CodePudding user response:
Use cycle! Will open gobang operating in a cycle, and then give a trigger condition such as press Enter or set a button, when conditions are back into circulationCodePudding user response: