验证中...
源.cpp
Raw Copy
#include<graphics.h>
#include<iostream>
#include<mmstream.h>
#pragma comment(lib,"winmm.lib")
int a[21][21] = { 0 };
int pan1 = 1;
void ye();
void xia();
int pan();
int main()
{
ye();
getchar();
return 0;
}
void ye()
{
initgraph(600, 500);
loadimage(NULL, L"背景.jpg", 600, 500);
mciSendString(L"open 背景音乐.mp3", 0, 0, 0);
mciSendString(L"play 背景音乐.mp3", 0, 0, 0);
setlinecolor(BLACK);
for (int i = 1; i < 20; i++)
{
line(25 * i, 0, 25 * i, 500);
line(0, 25 * i, 500, 25 * i);
}
line(500, 0, 500, 500);
line(501, 0, 501, 500);
setfillcolor(BLACK);
solidcircle(250, 250, 5);
solidcircle(75, 75, 5);
solidcircle(425, 75, 5);
solidcircle(425, 425, 5);
solidcircle(75, 425, 5);
setbkmode(0);
settextcolor(BLACK);
outtextxy(512, 60, L"玩家1:黑棋");
outtextxy(512, 120, L"玩家2:白棋");
settextcolor(BLUE);
xia();
}
void xia()
{
MOUSEMSG m;
int x, y;
int i = 1;
HWND hwnd;
hwnd = GetHWnd();
while (1)
{
m = GetMouseMsg();
if (m.uMsg == WM_LBUTTONDOWN)
{
x = (m.x + 13) / 25;
y = (m.y + 13) / 25;
if (a[y][x] != 0)
{
MessageBox(hwnd, L"这里已经有棋子了!!!", L"注意", MB_OK);
continue;
}
if (x>20)
{
MessageBox(hwnd, L"不能在棋盘外下棋", L"注意", MB_OK);
continue;
}
if (i % 2 == 1)
{
setfillcolor(BLACK);
solidcircle((m.x + 13) / 25 * 25, (m.y + 13) / 25 * 25, 10);
i++;
a[y][x] = 1;
for (int i = 0; i < 21; i++)
{
for (int j = 0; j < 17; j++)
{
if (a[i][j] == 1 && a[i][j + 1] == 1 && a[i][j + 2] == 1 && a[i][j + 3] == 1 && a[i][j + 4] == 1)
{
MessageBox(hwnd, L"玩家1:黑棋,胜利!!!!", L"胜利", MB_OK);
mciSendString(L"close 背景音乐.mp3", 0, 0, 0);
return;
}
}
}
for (int j = 0; j < 21; j++)
{
for (int i = 0; i < 17;i++)
{
if (a[i][j] == 1 && a[i+1][j] == 1 && a[i+2][j] == 1 && a[i+3][j] == 1 && a[i+4][j] == 1)
{
MessageBox(hwnd, L"玩家1:黑棋,胜利!!!!", L"胜利", MB_OK);
mciSendString(L"close 背景音乐.mp3", 0, 0, 0);
return;
}
}
}
for (int i = 0; i < 17; i++)
{
for (int j = 0; j < 17; j++)
{
if (a[i][j] == 1 && a[i+1][j + 1] == 1 && a[i+2][j + 2] == 1 && a[i+3][j + 3] == 1 && a[i+4][j + 4] == 1)
{
MessageBox(hwnd, L"玩家1:黑棋,胜利!!!!", L"胜利", MB_OK);
mciSendString(L"close 背景音乐.mp3", 0, 0, 0);
return;
}
}
}
for (int i = 0; i < 17; i++)
{
for (int j = 21; j > 3; j--)
{
if (a[i][j] == 1 && a[i + 1][j -1] == 1 && a[i + 2][j -2] == 1 && a[i + 3][j -3] == 1 && a[i + 4][j - 4] == 1)
{
MessageBox(hwnd, L"玩家1:黑棋,胜利!!!!", L"胜利", MB_OK);
mciSendString(L"close 背景音乐.mp3", 0, 0, 0);
return;
}
}
}
}
else
{
setfillcolor(WHITE);
solidcircle((m.x + 13) / 25 * 25, (m.y + 13) / 25 * 25, 10);
i++;
a[y][x] = 2;
for (int i = 0; i < 21; i++)
{
for (int j = 0; j < 17; j++)
{
if (a[i][j] == 2 && a[i][j + 1] == 2 && a[i][j + 2] == 2 && a[i][j + 3] == 2 && a[i][j + 4] == 2)
{
MessageBox(hwnd, L"玩家2:白棋,胜利!!!!", L"胜利", MB_OK);
mciSendString(L"close 背景音乐.mp3", 0, 0, 0);
return;
}
}
}
for (int j = 0; j < 21; j++)
{
for (int i = 0; i < 17; i++)
{
if (a[i][j] == 2 && a[i + 1][j] == 2 && a[i + 2][j] == 2 && a[i + 3][j] == 2 && a[i + 4][j] == 2)
{
MessageBox(hwnd, L"玩家2:白棋,胜利!!!!", L"胜利", MB_OK);
mciSendString(L"close 背景音乐.mp3", 0, 0, 0);
return;
}
}
}
for (int i = 0; i < 17; i++)
{
for (int j = 0; j < 17; j++)
{
if (a[i][j] == 2 && a[i + 1][j + 1] == 2 && a[i + 2][j + 2] == 2 && a[i + 3][j + 3] == 2 && a[i + 4][j + 4] == 2)
{
MessageBox(hwnd, L"玩家2:黑棋,胜利!!!!", L"胜利", MB_OK);
mciSendString(L"close 背景音乐.mp3", 0, 0, 0);
return;
}
}
}
for (int i = 0; i < 17; i++)
{
for (int j = 21; j > 3; j--)
{
if (a[i][j] == 2 && a[i + 1][j - 1] == 2 && a[i + 2][j - 2] == 2 && a[i + 3][j - 3] == 2 && a[i + 4][j - 4] == 2)
{
MessageBox(hwnd, L"玩家2:黑棋,胜利!!!!", L"胜利", MB_OK);
mciSendString(L"close 背景音乐.mp3", 0, 0, 0);
return;
}
}
}
}
}
}
}
程序截图.png

Comment list( 0 )

Sign in for post a comment

Help Search