#include <iostream>
#include <conio.h> // For _kbhit() and getch()
#include <windows.h> // For Sleep()
using namespace std;
bool gameOver;
const int width = 20;
const int height = 20;
int x, y, fruitX, fruitY, score;
int tailX[100], tailY[100];
int nTail;
enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN };
eDirection dir;
void Setup();
void Draw();
void Input();
void Logic();
int main() {
Setup();
while (!gameOver) {
Draw();
Input();
Logic();
Sleep(10); // 控制游戏速度
}
return 0;
}
void Setup() {
gameOver = false;
dir = STOP;
x = width / 2;
y = height / 2;
fruitX = rand() % width;
fruitY = rand() % height;
score = 0;
}
void Draw()