利用vs 2019和easyx图形库完成五子棋小游戏
C++源码:
#include<iostream>
#include<graphics.h>
using namespace std;
int map[16][16];
int num = 1; int flag = 256;
void Initgame()
{
IMAGE image;
loadimage(&image, "back.jpg", 750, 750);
putimage(0, 0, &image);
}
void Initmap()
{
for (size_t i = 0; i < 16; i++)
{
for (size_t j = 0; j < 16; j++)
{
map[i][j] = 0;
}
}
}
bool JudgeCOL()
{
for (size_t j = 0; j < 15; j++)
{
for (size_t i = 0; i < 11; i++)
{
if (map[i][j] == 1 &&
map[i + 1][j] == 1 &&
map[i + 2][j] == 1 &&
map[i + 3][j] == 1 &&
map[i + 4][j] == 1)
{
return true;
}
if (map[i][j] == 2 &&
map[i + 1][j] == 2 &&
map[i + 2][j] == 2 &&
map[i + 3][j] == 2 &&
map[i + 4][j] == 2)
{
return true;
}
}
}
return false;
}
bool JudgeROW()
{
for (size_t i = 0; i < 15; i++)
{
for (size_t j = 0; j < 10; j++)
{
if (map[i][j] == 1 &&
map[i][j + 1] == 1 &&
map[i][j + 2] == 1 &&
map[i][j + 3] == 1 &&
map[i][j + 4] == 1)
{
return true;
}
else if (map[i][j] == 2 &&
map[i][j + 1] == 2 &&
map[i][j + 2] == 2 &&
map[i][j + 3] == 2 &&
map[i][j + 4] == 2)
{
return true;
}
}
}
return false;
}
bool MouseEvent()
{
MOUSEMSG msg = GetMouseMsg();
if (msg.uMsg == WM_LBUTTONDOWN) {
if (num % 2 == 0)
{
setfillcolor(WHITE);
if (msg.x % 50 <= 10 && msg.y % 50 <= 10)
{
if (map[msg.y / 50][msg.x / 50] == 1 || map[msg.y / 50][msg.x / 50] == 2)
{
return false;
}
map[msg.y / 50][msg.x / 50] = 1;
num++;
fillcircle(msg.x - msg.x % 50, msg.y - msg.y % 50, 20);
return true;
}
if (msg.x % 50 <= 10 && msg.y % 50 >= 40)
{
if (map[msg.y / 50 + 1][msg.x / 50] == 1 || map[msg.y / 50 + 1][msg.x / 50] == 2)
{
return false;
}
map[msg.y / 50 + 1][msg.x / 50] = 1;
num++;
fillcircle(msg.x - msg.x % 50, (msg.y / 50 + 1) * 50, 20);
return true;
}
if (msg.x % 50 >= 40 && msg.y % 50 <= 10)
{
if (map[msg.y / 50][msg.x / 50 + 1] == 1 || map[msg.y / 50][msg.x / 50 + 1] == 2)
{
return false;
}
map[msg.y / 50][msg.x / 50 + 1] = 1;
num++;
fillcircle(50 * (msg.x / 50 + 1), msg.y - msg.y % 50, 20);
return true;
}
if (msg.x % 50 >= 40 && msg.y % 50 >= 40)
{
if (map[msg.y / 50 + 1][msg.x / 50 + 1] == 1 || map[msg.y / 50 + 1][msg.x / 50 + 1] == 2)
{
return false;
}
map[msg.y / 50 + 1][msg.x / 50 + 1] = 1;
num++;