简体   繁体   English

.exe没有显示“按任意键继续...”

[英].exe not showing “Press any key to continue…”

在此处输入图片说明 In Visual Studio whenever I start without debugging, the .exe file that shows up does not contain the phrase "Press any key to continue..." like it usually does. 在Visual Studio中,只要我没有调试就启动,显示的.exe文件通常都不会包含短语“按任意键继续...”。 The screen just has the flashing cursor at the beginning. 屏幕的开头只是闪烁的光标。 Is there any easy fix to this? 有什么简单的解决办法吗? I have commented out some of my code and the phrase shows back up. 我已经注释掉了一些代码,并且该短语显示出来了。

This is the code that I have commented out: I have all of the variables and classes declared correctly. 这是我注释掉的代码:我正确声明了所有变量和类。

void Maze::addPaths()
{
    Coordinate currentLocation;
    Coordinate startLocation;
    Coordinate endLocation; //not used yet
    std::stack<Coordinate> stack;

    currentLocation.row = (((rand() % HEIGHT) / 2) * 2);
    currentLocation.column = (((rand() % WIDTH) / 2) * 2);

    startLocation = currentLocation;
    grid[currentLocation.row][currentLocation.column] = START;
    player = currentLocation;
    do 
    {
        //drawMaze();
        bool canMoveUp = !(currentLocation.row == 0 || grid[currentLocation.row - 2][currentLocation.column] != WALL);
        bool canMoveDown = !(currentLocation.row == HEIGHT - 1 || grid[currentLocation.row + 2][currentLocation.column] != WALL);
        bool canMoveLeft = !(currentLocation.column == 0 || grid[currentLocation.row][currentLocation.column - 2] != WALL);
        bool canMoveRight = !(currentLocation.column == WIDTH - 1 || grid[currentLocation.row][currentLocation.column + 2] != WALL);

        if (canMoveUp || canMoveDown || canMoveLeft || canMoveRight)
        {
            stack.push(currentLocation);

            //choose random location to dig
            bool moveFound = false;
            while (!moveFound)
            {
                int direction = rand() % 4;
                if (direction == 0 && canMoveUp)
                {
                    moveFound = true;
                    grid[currentLocation.row - 2][currentLocation.column] = PATH;
                    grid[currentLocation.row - 1][currentLocation.column] = PATH;
                    currentLocation.row -= 2;
                }
                else if (direction == 1 && canMoveDown)
                {
                    moveFound = true;
                    grid[currentLocation.row + 2][currentLocation.column] = PATH;
                    grid[currentLocation.row + 1][currentLocation.column] = PATH;
                    currentLocation.row += 2;
                }
                else if (direction == 2 && canMoveLeft)
                {
                    moveFound = true;
                    grid[currentLocation.row][currentLocation.column - 2] = PATH;
                    grid[currentLocation.row][currentLocation.column - 1] = PATH;
                    currentLocation.column -= 2;
                }
                else if (direction == 3 && canMoveRight)
                {
                    moveFound = true;
                    grid[currentLocation.row][currentLocation.column + 2] = PATH;
                    grid[currentLocation.row][currentLocation.column - 2] = PATH;
                    currentLocation.column += 2;
                cout << "yay";
                }
            }
        }
        else if (!stack.empty())
        {
            currentLocation = stack.top();
            stack.pop();
        }
    } while (!stack.empty());
    //addDestinationToGrid();
    cout << "no";
}

On Windows, system("PAUSE"); 在Windows上, system("PAUSE"); will prompt a user with the text: 将提示用户输入文本:

Press any key to continue...

It seems your main do-while loops in endless cycle. 看来您的主要do-while循环是无休止的。 How do you initialize grid? 您如何初始化网格?

问题最终是我走出了名为grid的数组的边界,而且我还在for循环中混合了行和列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM