c++ - 标识符未定义 C++
问题描述
我正在尝试创建一个霸气游戏,我收到 2 个错误,这些错误与标识符“playAt”未定义和标识符“hasLegalMoveFor”未定义相同,我不确定问题是什么,如果你知道问题可能请您向我解释一下,以便我在编码时可以理解更多,我已经为此工作了大约 2 周。
#include<Windows.h>
#include<iostream>
#include<vector>
using namespace std;
int main()
{
// specify default value to fill the vector elements
int mapSize = 0;
int row = 0;
int column = 0;
int x = row = 0;
int y = column = 0;
int horizontal = 0;
int vertical = 0;
char player = 'H' && 'V';
player = horizontal && vertical;
cout << "Enter the size of board. It should accept any size between 2 and 15. => ";
cin >> mapSize;
vector< vector<char> > board(mapSize, vector<char>(mapSize, '0'));
for (int i = 0; i < mapSize; i++) {
for (int j = 0; j < mapSize; j++) {
cout << board[i][j] << " ";
}
cout << endl;
}
int CheckValid(int i, int j, int player); {
if (board[x][y] != 0)
return 0;
if (player == 1) {
if (board[x][y + 1] != 0 || y == 12)
return 0;
}
else {
if (board[x + 1][y] != 0 || x == 12)
return 0;
}
return 1;
}
void play(); {
bool player = horizontal;
while (true) {
cout << ("\n");
if (player == horizontal) {
cout << ("Horizontal to play");
}else {
cout << ("Vertical to play");
}
if (!(hasLegalMoveFor(player))) {
cout << ("No legal moves -- you lose! ");
return;
}
cout << ("Row: ");
int row;
cin >> row;
cout << ("Column: ");
int column;
cin >> column;
playAt(row, column, player);
player = !player;
}
}
void playAt(int x, int y, bool player); {
if (!board[x][y] && !board[x][y + 1] && player == horizontal) {
board[x][y] = true;
board[x][y + 1] = true;
}
else if (!board[x][y] && !board[x + 1][y] && player == vertical) {
board[x][y] = true;
board[x][y] = true;
}
else {
cout << ("Not a legal move!");
}
bool hasLegalMoveFor(bool player); {
int rowOffset = 0;
int columnOffset = 0;
if (player == horizontal) {
columnOffset = 1;
}
else {
rowOffset = 1;
}
for (int x = 0; row < (8 - rowOffset); x++) {
for (int y = 0; y < (8 - columnOffset); y++) {
if (!(board[x][y] = board[x + rowOffset][y + columnOffset])) {
return true;
}
};
}
return false;
}
//board[x][y] = true;
//if (player == horizontal) {
//board[x][y + 1] = true;
//board[x][y + 2] = true;
//} else (player == vertical); {
//board[x + 1][y] = true;
//board[x + 2][y] = true;
//}
//}
//char ch = 0;
//do {
//cout << "Press Q to quit\n";
//cin >> ch;
//system("cls");
//} while (ch != 'Q' && ch != 'q');
//return 0;
}
}
解决方案
推荐阅读
- django - AttributeError:模块“blog.views”没有属性“post_detail”
- c# - 构建 c# MVC asp.net api 网页 - 我想使用 index.cshtml 页面但收到失败消息:CS1980(代码说明见文本)
- bash - Shell 脚本:-ne 的意外运算符
- cordova - 如何调试 Ionic 中使用的 SqlLite 数据库?
- c++ - Qt 5.6.2(msvc2015-32bit) 模型/视图只读示例意外行为
- javascript - 将时间转换为浮点数
- c# - 如何在统一C#中使对象可序列化
- c# - .Net Core 2.0 的 AppVeyor CI。nuget包的自动发布不起作用
- javascript - React:只切换一个类而不影响现有类
- python - python django中的名称未定义错误