(尝试五子棋,使用的VS)报错E0065 应输入“;”,改了好久都没有成功,求助大佬帮忙改一下
#include <iostream>
#include <vector>
using namespace std;
const int SIZE = 19;
int map[SIZE][SIZE];
int flag = 0;
void init()
{
for (int i = 0; i < SIZE; i++)
{
for (int j = 0; j < SIZE; j++)
{
map[i][j] = 0; // 初始化棋盘,所有位置置空
}
}
}
int isWin(int x, int y)
{
int color = map[x][y]; // 获取当前位置的棋子颜色
int count = 1; // 统计连续相同颜色的棋子数
int dx[] = { -1, 0, 1, 1 }; // x 方向的增量
int dy[] = { 1, 1, 1, 0 }; // y 方向的增量
// 检查四个方向
for (int i = 0; i < 4; i++)
{
int tx = x, ty = y;
while (count < 5)
{
tx += dx[i];
ty += dy[i];
// 判断是否越界或者是否是相同颜色的棋子
if (tx < 0 || tx >= SIZE || ty < 0 || ty >= SIZE || map[tx][ty] != color) {
break;
}
count++;
}
if (count >= 5)
{
return color;
}
count = 1; // 重置计数器
}
return 0; // 返回 0 表示游戏未结束
}
bool isValid(int x, int y)
{
if (x < 0 || x >= SIZE || y < 0 || y >= SIZE)
{
return false;
}
if (map[x][y] != 0)
{
return false;
}
return true;
}
int playerMove(int x, int y)
{
if (!isValid(x, y))
{
return -1; // 无效的落子位置
}
flag++;
int color = (flag % 2 == 0) ? 1 : 2; // 黑子为偶数次落子,白子为奇数次落子
map[x][y] = color;
return isWin(x, y);
}
void menuView()
{
cout << "=============" << endl;
cout << " 棋盘游戏 " << endl;
cout << "=============" << endl;
cout << " 1. 开始游戏" << endl;
cout << " 2. 退出游戏" << endl;
cout << "请输入选项: ";
}
void gameView_ShowMap()
{
cout << " ";
for (int i = 0; i < SIZE; i++)
{
cout << i << " ";
}
cout << endl;
for (int i = 0; i < SIZE; i++)
{
cout << i << " ";
for (int j = 0; j < SIZE; j++)
{
if (map[i][j] == 0) {
cout << ". ";
}
else if (map[i][j] == 1)
{
cout << "X ";
}
else if (map[i][j] == 2)
{
cout << "O ";
}
}
cout << endl;
}
}
void winView(int winner)
{
if (winner == 1) {
cout << "黑方获胜!" << endl;
}
else if (winner == 2)
{
cout << "白方获胜!" << endl;
}
else
{
cout << "平局!" << endl;
}
}
void gameView()
{
int winner = 0;
init();
while (true)
{
system("clear"); // 清屏
gameView_ShowMap();
if (flag == SIZE * SIZE)
{
winner = -1; // 平局
if (winner != 0)
{
break;
}
int x, y;
cout << "请输入落子坐标(x, y),以空格分隔: ";
cin >> x >> y;
winner = playerMove(x, y);
if (winner != 0)
{
break;
}
}
system("clear");
gameView_ShowMap();
winView(winner);
}
int main()
{
while (true)
{
menuView();
int choice;
cin >> choice;
if (choice == 1)
{
gameView();
}
else if (choice == 2)
{
break;
}
else
{
cout << "无效选项,请重新选择!" << endl;
}
}
return 0;
}
报错E0065 应输入“;”,改了好久都没有成功,可以帮我改一下嘛?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- threenewbee 2023-08-16 18:06关注
void gameView()函数缺少后花括号。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1
悬赏问题
- ¥15 无源定位系统的时差估计误差标准差
- ¥15 请问这个代码哪里有问题啊
- ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
- ¥15 通过GaussianView进行结构微调消除虚频
- ¥15 调用transformers库
- ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?
- ¥15 新硬盘安装的程序总是崩溃,提示遇到错误
- ¥15 openpcdet自制数据集评估bev精度和3d精度相同
- ¥15 excel 上下按钮 显示行
- ¥20 云卓h12pro 数传问题