- 写完之后,发现点击鼠标不能运行,不知道哪里出问题,请求大佬的协助
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include<windows.h>
#include <time.h>
MOUSEMSG m;
int k=0;
void InitGame()
{
initgraph(600, 500);
setlinecolor(RED);
for (int i = 0; i < 20; i++)
{
line(0, i * 25, 500, i * 25);
line(i * 25, 0, i * 25, 500);
}
setlinestyle(PS_SOLID, 2);
line(500, 0, 500, 500);
getchar();
}
int board[20][20] = { 0 };
int flag = 1;
int judge(int a, int b)
{
int i, j;
int t = 2 - flag % 2;
for ((i = a - 4) && (j = b); i <= a; i++)
{
if (i >= 1 && i < 16 && t == board[i][j] && t == board[i + 1][j] && t == board[i + 2][j] && t == board[i + 3][j] && t == board[i + 4][j])
return 1;
}
for ((i = a) && (j = b - 4); j <= a; j++)
{
if (j >= 1 && j < 16 && t == board[i][j] && t == board[i][j + 1] && t == board[i][j + 2] && t == board[i][j + 3] && t == board[i][j + 4])
return 1;
}
for ((i = a - 4) && (j = b - 4); ((i <= a) && (j >= b)); i++, j++)
{
if (i >= 1 && i < 16 && j >= 1 && j < 16 && t == board[i][j] && t == board[i + 1][j + 1] && t == board[i + 2][j + 2] && t == board[i + 3][j + 3] && t == board[i + 4][j + 4])
return 1;
}
for ((i = a - 4) && (j = b + 4); ((i <= a) && (j >= b)); i++, j--)
{
if (i >= 1 && i < 16 && j >= 1 && j < 16 && t == board[i][j] && t == board[i + 1][j - 1] && t == board[i + 2][j - 2] && t == board[i + 3][j - 3] && t == board[i + 4][j - 4])
return 1;
}
}
void Move()
{
int x,y;
m=GetMouseMsg();
if(m.uMsg==WM_LBUTTONDOWN)
{
for(x=12;x<600;x+=25)
for(y=12;y<500;y+=25)
{
if(m.x>=x&&m.x<=(x+25)&&m.y>=y&&y<=(y+25))
{ if(board[(x+13)/25][(y+13)/25]=0)
{
if (flag % 2 == 1) { setfillcolor(WHITE); };
if (flag % 2 == 0) { setfillcolor(BLUE); };
solidcircle(x+13, y+13, 12);
board[(x+13)/25][(y+13)/25]=1;
flag++;
}
}
}
}
FlushMouseMsgBuffer();
if (judge(x / 25, y / 25))
{
if (1 == flag % 2)
{ k=1;
outtextxy(512, 400, _T("玩家2胜利"));
return;
}
else
{ k=1;
outtextxy(512, 60, _T("玩家胜利"));
return;
}
}
}
void main()
{
InitGame();
while (k)
Move();
}