自己编写的一个小游戏,不知道问题所在.

问题遇到的现象和发生背景

一点开就没任何输出,请大家指教一下。

用代码块功能插入代码,请勿粘贴截图

#include
#include
#include
#include
#include
#include
#define LENGTH 60
#define WIDTH 20

void ShowUI();
void InitApple();
void InitPlayer();
void PlayGame();

short apple[2];
short player[2];
short lyA = 0;
short lxP = 0;
short dx;
short score;

void InitApple()
{
    apple[0] = rand() % LENGTH;
    apple[1] = 0;
}

void InitPlayer()
{
    player[0] = LENGTH / 2;
    player[1] = WIDTH;
}

void ShowUI()
{
    COORD coord;

    coord.X = apple[0];  //APPLE
    coord.Y = lyA;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
    putchar(' ');

    coord.X = apple[0];
    coord.Y = apple[1];
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
    putchar('$');

    coord.X = lxP; //PLAYER
    coord.Y = player[1];
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
    putchar(' ');

    coord.X = player[0];
    coord.Y = player[1];
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
    putchar('@');

    /*coord.X = 30;
    coord.Y = 70;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
    printf("score: %d", score); */
}

void PlayGame()
{
    char input = 'd';
    short temp;
    while(apple[1] > WIDTH)
    {
        ShowUI();
        while(_kbhit())
        {
            input = _getch();
        }

        switch(input)
        {
            case 'A': case 'a': dx = -1; break;
            case 'D': case 'd': dx = 1; break;
        }

        lxP = player[0];
        player[0] += dx;

        lyA = apple[1];
        apple[1] += 1;

        if(player[0] == apple[0] && apple[0] == WIDTH)
            score += 10;

        Sleep(500);
    }
}

int main()
{
    srand((size_t)time(NULL));
    InitApple();
    InitPlayer();
    PlayGame();
    system("PAUSE");
    return 0;
}



运行结果及报错内容

img


#define WIDTH 20    
apple[1] = 0;
 while (apple[1] > WIDTH)   //恒为假
    system("PAUSE");

明白点了吗