【发布时间】:2017-07-11 20:26:35
【问题描述】:
我正在尝试设计一个简单的蛇游戏。这是我的代码:
using namespace std;
bool gameOver;
//Map Dimentions
const int width = 20;
const int height = 20;
//Positions
int x, y, fruitX, fruitY, score;
//Directions
enum eDirection { STOP = 0, Left, Right, Up, Down};
eDirection dir;
void Setup() {
gameOver = false;
dir = STOP;
//Center Snake Head
x = width / 2;
y = height / 2;
//Randomly places fruit within constraints of map
fruitX = rand() % width;
fruitY = rand() % height;
score = 0;
}
void Draw() {
//Clears Terminal Window
system("clear");
//Walls of Map
for(int j = 0 ; j < height ; ++j)
{
for(int i = 0; i < width ;++i)
{
if( i == 0 || i == (width - 1) || j == 0 || j == (height - 1) )
{
cout << "* ";
}
else
{
cout << " ";
}
}
cout << endl;
**}**
}
void Input() {
}
void Logic() {
}
int main () {
Setup();
while (!gameOver) {
Draw();
Input();
Logic();
}
return 0;
}
在我的代码文档的开头,我包含了所有 c++ 库。在我的地图墙的最后一个 } 中,被 **** 包围,我收到错误“使用未声明的标识符”。我不知道是什么原因造成的。有什么想法吗?
【问题讨论】:
-
你认为
**}**应该做什么? -
您没有包含任何标题,但您正在使用例如
cout. -
**** 只是围绕问题,它们实际上并没有出现在我的代码中,我在 sn-p 之前的顶部都有每个 #include
-
看起来你有一些非法的、不可打印的字符。删除
**}**周围的空白行以杀死它们。 Wipe them out. All of them. -
发布完整的minimal reproducible example,以便将其复制粘贴到 cpp 文件时生成错误。使用注释标记该行。包括构建命令行。
标签: c++