//创建对话框,绘制五子棋,并实现五子棋的输赢判断
#include<windows.h>
#include <tchar.h>
//棋盘和棋手,黑子先手
LPCWSTR lps[11] = { L" 1",L" 2",L" 3",L" 4",L" 5",L" 6",L" 7",L" 8",L" 9",L"10",L"11" };
int chessboard[11][11] = {
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0
}, chequer = -1;
//重新开始
void reset()
{
for (int i = 0; i <= 10; i++)
for (int j = 0; j <= 10; j++)
chessboard[i][j] = 0;
chequer = -1;
}
//判断输赢
int judgeWinner()
{
//横向
for (int i = 0; i <= 10; i++)
for (int j = 0; j <= 6; j++)
{
if (chessboard[i][j] == 1 && chessboard[i][j + 1] == 1 && chessboard[i][j + 2] == 1 && chessboard[i][j + 3] == 1 && chessboard[i][j + 4] == 1)
return 1;
if (chessboard[i][j] == -1 && chessboard[i][j + 1] == -1 && chessboard[i][j + 2] == -1 && chessboard[i][j + 3] == -1 && chessboard[i][j + 4] == -1)
return -1;
}
//纵向
for (int j = 0; j <= 10; j++)
for (int i = 0; i <= 6; i++)
{
if (chessboard[i][j] == 1 && chessboard[i + 1][j] == 1 && chessboard[i + 2][j] == 1 && chessboard[i + 3][j] == 1 && chessboard[i + 4][j] == 1)
return 1;
if (chessboard[i][j] == -1 && chessboard[i + 1][j] == -1 && chessboard[i + 2][j] == -1 &&
C++ 五子棋
最新推荐文章于 2023-10-15 20:54:39 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)