【问题标题】:Use of undeclared identifier error in simple snake game在简单的蛇游戏中使用未声明的标识符错误
【发布时间】: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++


【解决方案1】:

为了测试一个理论,我在一个古老的文本编辑器中提取了文件,然后我看到了

**}?**

十六进制编辑器说

20 20 20 20 2A 2A 7D 3F 2A 2A

3F 不应该在那里。

【讨论】:

  • 在 } 后面有一个隐形字符。感谢修复
猜你喜欢
  • 2020-08-10
  • 1970-01-01
  • 1970-01-01
  • 2017-02-06
  • 1970-01-01
  • 1970-01-01
  • 2013-03-12
  • 2023-04-09
相关资源
最近更新 更多