style(game): redesign game board UI

This commit is contained in:
2025-09-23 03:25:48 +03:30
parent 1ea3f01414
commit 1a14c7ff11
+10 -8
View File
@@ -7,7 +7,7 @@ using namespace std;
bool gameOver; bool gameOver;
const int width = 40; const int width = 40;
const int height = 20; const int height = 40;
int x, y, fruitX, fruitY, score; int x, y, fruitX, fruitY, score;
int tailX[100], tailY[100]; int tailX[100], tailY[100];
int ntail; int ntail;
@@ -28,29 +28,31 @@ void setup() {
void draw() { void draw() {
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), {0,0}); SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), {0,0});
for(int i = 0; i < width + 2; i++) cout << "#"; cout << "";
cout << "\n"; for(int i = 1; i < width + 1; i++) cout << "";
cout << "\n";
for(int i = 0; i < height; i++) { for(int i = 0; i < height; i++) {
for(int j = 0; j < width; j++ ) { for(int j = 0; j < width; j++ ) {
if(j == 0) cout << "#"; if(j == 0) cout << "";
if(i == y && j == x) cout << "O"; if(i == y && j == x) cout << "O";
else if(i == fruitY && j == fruitX) cout << "F"; else if(i == fruitY && j == fruitX) cout << "F";
else { else {
bool print = false; bool print = false;
for (int k = 0; k < ntail; k++) { for (int k = 0; k < ntail; k++) {
if (tailX[k] == j && tailY[k] == i) { if (tailX[k] == j && tailY[k] == i) {
cout << "o"; cout << "@";
print = true; print = true;
} }
} }
if(!print) cout << " "; if(!print) cout << " ";
} }
if(j == width - 1) cout << "#"; if(j == width - 1) cout << "";
} }
cout << "\n"; cout << "\n";
} }
for(int i = 0; i < width + 2; i++) cout << "#"; cout << "";
cout << "\n"; for(int i = 1; i < width + 1; i++) cout << "";
cout << "\n";
cout << "score:" << score << "\n"; cout << "score:" << score << "\n";
cout << "Time: " << timer << "s\n"; // Display timer cout << "Time: " << timer << "s\n"; // Display timer