From 7fd468078a7fb379c424f2b8fb8130b627f89c2f Mon Sep 17 00:00:00 2001 From: MerajDerafshi Date: Tue, 23 Sep 2025 00:42:24 +0330 Subject: [PATCH] feat(game): implement base functions and board rendering --- snake.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 snake.cpp diff --git a/snake.cpp b/snake.cpp new file mode 100644 index 0000000..d8f9f0e --- /dev/null +++ b/snake.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +using namespace std; + +bool gameOver; +const int width = 40; +const int height = 40; +int x, y, fruitX, fruitY, score; +enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN }; +eDirection dir; + +void setup() { + gameOver = false; + dir = STOP; + x = width / 2; + y = height / 2; + fruitX = rand() % width; + fruitY = rand() % height; + score = 0; +} + +void draw() { + system("cls"); + for(int i = 0; i < width + 2; i++) cout << "#"; + cout << "\n"; + for(int i = 0; i < height; i++) { + for(int j = 0; j < width; j++ ) { + if(j == 0) cout << "#"; + cout << " "; + if(j == width - 1) cout << "#"; + } + cout << "\n"; + } + for(int i = 0; i < width + 2; i++) cout << "#"; + cout << "\n"; + +} + +void input() { + +} + +void logic() { + +} + +int main() { + setup(); + while(!gameOver){ + draw(); + input(); + logic(); + } +} \ No newline at end of file