#include #include 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(){ gameover = false; dir = STOP; x = width / 2 - 1; y = height / 2 - 1; fruitx = rand() % width; fruity = rand() % height; score = 0; } void draw(){ system("cls");// system ("clear"); for (int i = 0; i < width + 1; i++) cout << "#"; cout << endl; for (int i = 0; i= width - 1) x = 0; else if (x < 0) x = width - 2; if (y >= height) y = 0; else if (y < 0) y = height - 1; for (int i = 0; i < nTail; i++){ if (tailx[i] == x&&taily[i] == y) gameover = true; } if (x == fruitx&&y == fruity){ score += 10; fruitx = rand() % width; fruity = rand() % height; nTail++; } } int main(){ setup(); while (!gameover){ draw(); input(); Logic(); } return 0; }