我的编程环境是vs2019
#include "stdafx.h"是自带的,其他版本可能需要添加#include “stdafx.h”
除了下面代码外,无其他改动
#include
#include
#include
#include
#include
#include
#pragma comment(lib, "winmm.lib")
void hello(); //欢迎界面
void load(); //等待界面
void start(); //游戏初始化
void writer(); //作者界面
void board(); //绘画棋盘
void behind(); //玩家对战
int success(int[15][15]); //胜利条件判断
void regret(int[15][15], int[15][15]); //悔棋
void machine(); //人机对战
int robot(int[15][15], int[15][15], int[15][15]); //电脑执棋
void win(int); //胜利界面
void over(); //游戏结束
HWND gc;
void hello() {
initgraph(800, 600);
setbkcolor(WHITE);
cleardevice();
mciSendString(TEXT(" open 音乐.mp3 alias mysong"), NULL, 0, NULL);
mciSendString(TEXT("play mysong"), NULL, 0, NULL);
load();
}
void load() {
IMAGE mg;
loadimage(&mg, "image\\loading01.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading02.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading03.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading04.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading05.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading06.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading07.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading08.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading09.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading10.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading11.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading12.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading13.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading14.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading15.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading16.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading17.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading18.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading19.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading20.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading21.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading22.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading23.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading24.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading25.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading26.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading27.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading28.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading29.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading30.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading31.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading32.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading33.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading34.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading35.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading36.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading37.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading38.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading39.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading40.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading41.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading42.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading43.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading44.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading45.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading46.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading47.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading48.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading49.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading50.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading51.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading52.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading53.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading54.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading55.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading56.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading57.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading58.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading59.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading60.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading61.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading62.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading63.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading64.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading65.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading66.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading67.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading68.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading69.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading70.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading71.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading72.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading73.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading74.jpg");
putimage(0, 0, &mg);
Sleep(80);
loadimage(&mg, "image\\loading75.jpg");
putimage(0, 0, &mg);
}
void start()
{
int cont = 0;
initgraph(600, 800);
cleardevice();
settextcolor(RED); //设置文字颜色
setbkmode(TRANSPARENT); //设置窗口透明
settextstyle(128, 0, "宋体"); //设置字体大小、宽度、字体
outtextxy(100, 100, "五子棋");
setlinecolor(RED);
rectangle(150, 300, 450, 650);
rectangle(160, 310, 440, 640);
line(160, 420, 440, 420);
line(160, 530, 440, 530);
settextstyle(65, 0, "华文琥珀");
outtextxy(170, 340, "人机大战");
outtextxy(170, 450, "双人对战");
outtextxy(170, 560, "联系作者");
setlinecolor(WHITE);
settextcolor(WHITE);
settextstyle(23, 0, "华文琥珀");
outtextxy(527, 37, "音乐");
circle(550, 50, 25);
IMAGE gc;
loadimage(&gc, "image//jjkk.png");
putimage(220, 660, &gc);
while (true)
{
MOUSEMSG m;
m = GetMouseMsg();
if (m.uMsg == WM_LBUTTONDOWN)
{
if (m.x <= 440 && m.x >= 160 && m.y < 640 && m.y > 530)
writer();
if (m.x <= 440 && m.x >= 160 && m.y < 530 && m.y > 420)
behind();
if (m.x <= 440 && m.x >= 160 && m.y < 420 && m.y > 310)
machine();
if (m.x <= 575 && m.x >= 528 && m.y < 75 && m.y > 25)
{
if (cont % 2 == 0)
{
mciSendString(TEXT("pause mysong"), NULL, 0, NULL);
cont++;
}
else
{
mciSendString(TEXT("resume mysong"), NULL, 0, NULL);
cont++;
}
}
}
}
}
void writer()
{
initgraph(600, 600);
setbkcolor(WHITE);
cleardevice();
IMAGE img;
loadimage(&img, "image\\writer.png");
putimage(100, 100, &img);
settextcolor(RED);
settextstyle(40, 0, "华文琥珀");
outtextxy(100, 50, "小伙子不错,联系作者");
outtextxy(50, 500, "教你一招半式,走向棋坛巅峰");
settextstyle(20, 0, "宋体");
outtextxy(50, 550, "(加VX后点击头像返回)");
while (true)
{
MOUSEMSG m;
m = GetMouseMsg();
if(m.uMsg== WM_LBUTTONDOWN)
if (m.x <= 350 && m.x >= 250 && m.y <= 350 && m.y >= 250)
start();
}
}
void board()
{
initgraph(1200, 800);
setbkcolor(BLACK);
cleardevice();
setlinecolor(WHITE);
circle(1060, 130, 31);
for (int i = 50; i <= 750; i += 50)
{
line(i, 50, i, 750);
line(50, i, 750, i);
}
for (int i = 200; i < 800; i += 400)
{
for (int j = 200; j < 800; j += 400)
fillcircle(i, j, 5);
}
setlinecolor(RED);
rectangle(860, 400, 1140, 690);
rectangle(870, 410, 1130, 680);
line(870, 500, 1130, 500);
line(870, 590, 1130, 590);
settextstyle(50, 0, "宋体");
outtextxy(940, 435, "悔 棋");
outtextxy(940, 525, "重 来");
outtextxy(940, 615, "投 降");
outtextxy(800, 100, "玩家一:");
outtextxy(800, 250, "玩家二:");
setfillcolor(RED);
fillcircle(1060, 130, 30);
setfillcolor(WHITE);
fillcircle(1060, 270, 30);
}
void behind()
{
board();
setlinecolor(WHITE);
MOUSEMSG m; // 定义鼠标消息
int i = 0, x, y, q=0, p=0;
int red[15][15],white[15][15],stick[15][15];
while (true)
{
m = GetMouseMsg();
x = m.x % 50;
y = m.y % 50;
setrop2(R2_COPYPEN); //二元光栅操作码:R2_COPYPEN当前颜色
if (m.uMsg == WM_LBUTTONDOWN) // 使用鼠标左键进行操作
{
if (i % 2 == 0 && m.x <= 1130 && m.y < 680 && m.x >= 860 && m.y > 590) //投降
win(1);
if (i % 2 == 1 && m.x <= 1130 && m.y < 680 && m.x >= 860 && m.y > 590)
win(2);
if (m.x <= 1130 && m.y < 590 && m.x >= 860 && m.y > 500) //重开
behind();
if (m.x <= 1130 && m.y < 500 && m.x >= 860 && m.y > 410)
{
if (i % 2 == 1)
{
red[p][q] = 0;
stick[p][q] = 0;
i++;
}
else {
white[p][q] = 0;
stick[p][q] = 0;
i++;
}
regret(red, white);
}
if (x >= 25)
m.x = m.x - x + 50;
else
m.x = m.x - x;
if (y >= 25)
m.y = m.y - y + 50;
else
m.y = m.y - y;
p = m.x / 50 - 1;
q = m.y / 50 - 1;
if (p < 15 && q < 15)
{
if (stick[p][q] == 1)
continue;
if (i % 2 == 0 && m.x <= 750 && m.y <= 750 && m.x >= 50 && m.y >= 50)
{
setfillcolor(RED);
fillcircle(m.x, m.y, 20);
red[p][q] = 1;
if (success(red) == 1)win(2);
stick[p][q] = 1;
i++;
}
else if (i % 2 == 1 && m.x <= 750 && m.y <= 750 && m.x >= 50 && m.y >= 50)
{
setfillcolor(WHITE);
fillcircle(m.x, m.y, 20);
white[p][q] = 1;
if (success(white) == 1)win(1);
stick[p][q] = 1;
i++;
}
}
}
}
}
int success(int x[15][15])
{
int m, n;
for (m = 0; m < 15; m++)
{
for (n = 0; n < 15; n++)
{
if (x[m][n] == 1 && x[m][n + 1] == 1 && x[m][n + 2] == 1 && x[m][n + 3] == 1 && x[m][n + 4] == 1)return 1;
if (x[m][n] == 1 && x[m + 1][n] == 1 && x[m + 2][n] == 1 && x[m + 3][n] == 1 && x[m + 4][n] == 1)return 1;
if (x[m][n] == 1 && x[m + 1][n + 1] == 1 && x[m + 2][n + 2] == 1 && x[m + 3][n + 3] == 1 && x[m + 4][n + 4] == 1)return 1;
if (n > 3 && x[m][n] == 1 && x[m + 1][n - 1] == 1 && x[m + 2][n - 2] == 1 && x[m + 3][n - 3] == 1 && x[m + 4][n - 4] == 1)return 1;
}
}
return 0;
}
void regret(int x[15][15], int y[15][15])
{
board();
setrop2(R2_COPYPEN);
setcolor(WHITE);
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 15; j++) {
if (x[i][j] == 1) {
setfillcolor(RED);
fillcircle((i + 1) * 50, (j + 1) * 50, 20);
}
if (y[i][j] == 1) {
setfillcolor(WHITE);
fillcircle((i + 1) * 50, (j + 1) * 50, 20);
}
}
}
}
void machine()
{
board();
setlinecolor(WHITE);
MOUSEMSG m; // 定义鼠标消息
int i = 0, x, y, q = 0, p = 0;
int red[15][15],white[15][15],stick[15][15],whtie1[15][15];
while (true)
{
m = GetMouseMsg();
x = m.x % 50;
y = m.y % 50;
setrop2(R2_COPYPEN); //二元光栅操作码:R2_COPYPEN当前颜色
if (m.uMsg == WM_LBUTTONDOWN) // 使用鼠标左键进行操作
{
if (m.x <= 1130 && m.y < 680 && m.x >= 860 && m.y > 590) //投降
win(1);
if (m.x <= 1130 && m.y < 590 && m.x >= 860 && m.y > 500) //重开
machine();
if (m.x <= 1130 && m.y < 500 && m.x >= 860 && m.y > 410)
{
for (int x1 = 0; x1 < 15; x1++) {
for (int y1 = 0; y1 < 15; y1++) {
if (whtie1[x1][y1] != white[x1][y1]) {
white[x1][y1] = 0;
stick[x1][y1] = 0;
}
}
}
red[p][q] = 0;
stick[p][q] = 0;
regret(red, whtie1);
continue;
}
if (x >= 25)
m.x = m.x - x + 50;
else
m.x = m.x - x;
if (y >= 25)
m.y = m.y - y + 50;
else
m.y = m.y - y;
p = m.x / 50 - 1;
q = m.y / 50 - 1;
if (p < 15 && q < 15)
{
if (stick[p][q] == 1)
break;
if (m.x <= 750 && m.y <= 750 && m.x >= 50 && m.y >= 50)
{
setfillcolor(RED);
fillcircle(m.x, m.y, 20);
red[p][q] = 1;
if (success(red) == 1)win(2);
stick[p][q] = 1;
}
for (int x1 = 0; x1 < 15; x1++) {
for (int y1 = 0; y1 < 15; y1++) {
whtie1[x1][y1] = white[x1][y1];
}
}
robot(red, white, stick);
}
}
}
}
int robot(int x[15][15], int y[15][15], int z[15][15])
{
srand((unsigned)time(NULL));
int m, n;
/*-------------------------------------------------------判断四-----------------------------------------------------------*/
for (m = 0; m < 15; m++)
{
for (n = 0; n < 15; n++)
{
if (x[m][n] == 1 && x[m][n + 1] == 1 && x[m][n + 2] == 1 && x[m][n + 3] == 1 && n < 11 && z[m][n + 4] != 1)
{
y[m][n + 4] = 1;
z[m][n + 4] = 1;
setfillcolor(WHITE);
fillcircle((m + 1) * 50, (n + 5) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m][n + 1] == 1 && x[m][n + 2] == 1 && x[m][n + 3] == 1 && n > 0 && z[m][n - 1] != 1)
{
y[m][n - 1] = 1;
z[m][n - 1] = 1;
setfillcolor(WHITE);
fillcircle((m + 1) * 50, n * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n] == 1 && x[m + 2][n] == 1 && x[m + 3][n] == 1 && m < 11 && z[m + 4][n] != 1)
{
y[m + 4][n] = 1;
z[m + 4][n] = 1;
setfillcolor(WHITE);
fillcircle((m + 5) * 50, (n + 1) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n] == 1 && x[m + 2][n] == 1 && x[m + 3][n] == 1 && m > 0 && z[m - 1][n] != 1)
{
y[m - 1][n] = 1;
z[m - 1][n] = 1;
setfillcolor(WHITE);
fillcircle(m * 50, (n + 1) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n + 1] == 1 && x[m + 2][n + 2] == 1 && x[m + 3][n + 3] == 1 && n < 11 && m < 11 && z[m + 4][n + 4] != 1)
{
y[m + 4][n + 4] = 1;
z[m + 4][n + 4] = 1;
setfillcolor(WHITE);
fillcircle((m + 5) * 50, (n + 5) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n + 1] == 1 && x[m + 2][n + 2] == 1 && x[m + 3][n + 3] == 1 && n > 0 && m > 0 && z[m - 1][n - 1] != 1)
{
y[m - 1][n - 1] = 1;
z[m - 1][n - 1] = 1;
setfillcolor(WHITE);
fillcircle(m * 50, n * 50, 20);
return 0;
}
if (n > 3 && m < 11 && x[m][n] == 1 && x[m + 1][n - 1] == 1 && x[m + 2][n - 2] == 1 && x[m + 3][n - 3] == 1 && z[m + 4][n - 4] != 1)
{
y[m + 4][n - 4] = 1;
z[m + 4][n - 4] = 1;
setfillcolor(WHITE);
fillcircle((m + 5) * 50, (n - 3) * 50, 20);
return 0;
}
if (n < 14 && m > 0 && x[m][n] == 1 && x[m + 1][n - 1] == 1 && x[m + 2][n - 2] == 1 && x[m + 3][n - 3] == 1 && z[m - 1][n + 1] != 1)
{
y[m - 1][n + 1] = 1;
z[m - 1][n + 1] = 1;
setfillcolor(WHITE);
fillcircle(m * 50, (n + 2) * 50, 20);
return 0;
}
}
}
/*-------------------------------------------------------判断三-----------------------------------------------------------*/
for (m = 0; m < 15; m++)
{
for (n = 0; n < 15; n++)
{
if (x[m][n] == 1 && x[m][n + 1] == 1 && x[m][n + 2] == 1 && n < 12 && z[m][n + 3] != 1)
{
y[m][n + 3] = 1;
z[m][n + 3] = 1;
setfillcolor(WHITE);
fillcircle((m + 1) * 50, (n + 4) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m][n + 1] == 1 && x[m][n + 2] == 1 && n > 0 && z[m][n - 1] != 1)
{
y[m][n - 1] = 1;
z[m][n - 1] = 1;
setfillcolor(WHITE);
fillcircle((m + 1) * 50, n * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n] == 1 && x[m + 2][n] == 1 && m < 12 && z[m + 3][n] != 1)
{
y[m + 3][n] = 1;
z[m + 3][n] = 1;
setfillcolor(WHITE);
fillcircle((m + 4) * 50, (n + 1) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n] == 1 && x[m + 2][n] == 1 && m > 0 && z[m - 1][n] != 1)
{
y[m - 1][n] = 1;
z[m - 1][n] = 1;
setfillcolor(WHITE);
fillcircle(m * 50, (n + 1) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n + 1] == 1 && x[m + 2][n + 2] == 1 && n < 12 && m < 12 && z[m + 3][n + 3] != 1)
{
y[m + 3][n + 3] = 1;
z[m + 3][n + 3] = 1;
setfillcolor(WHITE);
fillcircle((m + 4) * 50, (n + 4) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n + 1] == 1 && x[m + 2][n + 2] == 1 && n > 0 && m > 0 && z[m - 1][n - 1] != 1)
{
y[m - 1][n - 1] = 1;
z[m - 1][n - 1] = 1;
setfillcolor(WHITE);
fillcircle(m * 50, n * 50, 20);
return 0;
}
if (n > 2 && m < 12 && x[m][n] == 1 && x[m + 1][n - 1] == 1 && x[m + 2][n - 2] == 1 && z[m + 3][n - 3] != 1)
{
y[m + 3][n - 3] = 1;
z[m + 3][n - 3] = 1;
setfillcolor(WHITE);
fillcircle((m + 4) * 50, (n - 2) * 50, 20);
return 0;
}
if (n < 14 && m > 0 && x[m][n] == 1 && x[m + 1][n - 1] == 1 && x[m + 2][n - 2] == 1 && z[m - 1][n + 1] != 1)
{
y[m - 1][n + 1] = 1;
z[m - 1][n + 1] = 1;
setfillcolor(WHITE);
fillcircle(m * 50, (n + 2) * 50, 20);
return 0;
}
}
}
/*-------------------------------------------------------判断二-----------------------------------------------------------*/
for (m = 0; m < 15; m++)
{
for (n = 0; n < 15; n++) {
if (x[m][n] == 1 && x[m][n + 1] == 1 && n < 13 && z[m][n + 2] != 1)
{
y[m][n + 2] = 1;
z[m][n + 2] = 1;
setfillcolor(WHITE);
fillcircle((m + 1) * 50, (n + 3) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m][n + 1] == 1 && n > 0 && z[m][n - 1] != 1)
{
y[m][n - 1] = 1;
z[m][n - 1] = 1;
setfillcolor(WHITE);
fillcircle((m + 1) * 50, n * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n] == 1 && m < 13 && z[m + 2][n] != 1)
{
y[m + 2][n] = 1;
z[m + 2][n] = 1;
setfillcolor(WHITE);
fillcircle((m + 3) * 50, (n + 1) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n] == 1 && m > 0 && z[m - 1][n] != 1)
{
y[m - 1][n] = 1;
z[m - 1][n] = 1;
setfillcolor(WHITE);
fillcircle(m * 50, (n + 1) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n + 1] == 1 && n < 13 && m < 13 && z[m + 2][n + 2] != 1)
{
y[m + 2][n + 2] = 1;
z[m + 2][n + 2] = 1;
setfillcolor(WHITE);
fillcircle((m + 3) * 50, (n + 3) * 50, 20);
return 0;
}
if (x[m][n] == 1 && x[m + 1][n + 1] == 1 && n > 0 && m > 0 && z[m - 1][n - 1] != 1)
{
y[m - 1][n - 1] = 1;
z[m - 1][n - 1] = 1;
setfillcolor(WHITE);
fillcircle(m * 50, n * 50, 20);
return 0;
}
if (n > 1 && m < 13 && x[m][n] == 1 && x[m + 1][n - 1] == 1 && z[m + 2][n - 2] != 1)
{
y[m + 2][n - 2] = 1;
z[m + 2][n - 2] = 1;
setfillcolor(WHITE);
fillcircle((m + 3) * 50, (n - 1) * 50, 20);
return 0;
}
if (n < 14 && m > 0 && x[m][n] == 1 && x[m + 1][n - 1] == 1 && z[m - 1][n - 1] != 1)
{
y[m - 1][n - 1] = 1;
z[m - 1][n - 1] = 1;
setfillcolor(WHITE);
fillcircle(m * 50, (n + 2) * 50, 20);
return 0;
}
}
}
while (1)
{
for (m = 0; m < 15; m++)
{
for (n = 0; n < 15; n++)
{
if (x[m][n] == 1)
{
setfillcolor(WHITE);
int p = rand() % 8;
switch (p)
{
case 0:
if (m == 0)break;
y[m - 1][n] = 1;
z[m - 1][n] = 1;
fillcircle(m * 50, (n + 1) * 50, 20);
return 0;
case 1:
if (m == 0 || n == 14)break;
y[m - 1][n + 1] = 1;
z[m - 1][n + 1] = 1;
fillcircle(m * 50, (n + 2) * 50, 20);
return 0;
case 2:
if (n == 14)break;
y[m][n + 1] = 1;
z[m][n + 1] = 1;
fillcircle((m + 1) * 50, (n + 2) * 50, 20);
return 0;
case 3:
if (m == 14 || n == 14)break;
y[m + 1][n + 1] = 1;
z[m + 1][n + 1] = 1;
fillcircle((m + 2) * 50, (n + 2) * 50, 20);
return 0;
case 4:
if (m == 14)break;
y[m + 1][n] = 1;
z[m + 1][n] = 1;
fillcircle((m + 2) * 50, (n + 1) * 50, 20);
return 0;
case 5:
if (m == 14 || n == 0)break;
y[m + 1][n - 1] = 1;
z[m + 1][n - 1] = 1;
fillcircle((m + 2) * 50, n * 50, 20);
return 0;
case 6:
if (n == 0)break;
y[m][n - 1] = 1;
z[m][n - 1] = 1;
fillcircle((m + 1) * 50, n * 50, 20);
return 0;
case 7:
if (m == 0 || n == 0)break;
y[m - 1][n - 1] = 1;
z[m - 1][n - 1] = 1;
fillcircle(m * 50, n * 50, 20);
return 0;
}
}
}
}
}
}
void win(int x)
{
initgraph(1200, 800);
cleardevice();
IMAGE mg; // 定义 IMAGE 对象
loadimage(&mg, "image\\wyt.png"); // 读取图片
putimage(800, 33, &mg); // 显示 IMAGE 对象
IMAGE img; // 定义 IMAGE 对象
loadimage(&img, "image\\timg.jpg"); // 读取图片
putimage(0, 0, &img); // 显示 IMAGE 对象
settextstyle(50, 0, "宋体");
outtextxy(100, 500, "牛逼啊小伙子");
if (x == 1)
{
outtextxy(100, 600, "白方获胜");
}
else
{
outtextxy(100, 600, "红方获胜");
}
settextcolor(WHITE);
settextstyle(100, 0, "宋体");
outtextxy(500, 600, "-->");
settextstyle(88, 0, "华文琥珀");
outtextxy(670, 520, "返回游戏界面");
outtextxy(720, 690, " 结束游戏");
while (true)
{
int ID;
MOUSEMSG n;
n = GetMouseMsg();
switch (n.uMsg) {
case WM_LBUTTONDOWN:
if (n.x <= 1200 && n.x >= 650 && n.y <= 650 && n.y >= 500)
start();
if (n.x <= 1200 && n.x >= 650 && n.y <= 800 && n.y >= 650) {
gc = GetHWnd(); //弹窗前置
ID = MessageBox(gc, "是否关闭游戏?", "", MB_YESNO);
if(ID==IDYES)
over();
}
}
}
}
void over()
{
initgraph(500, 500);
settextcolor(RED);
settextstyle(100, 0, "华文琥珀");
outtextxy(120, 200, "再见!");
Sleep(1800);
closegraph(); // 关闭绘图窗口
}
int main()
{
hello();
start();
return 0;
}