From 7dacf98af1251d141cf2098622f3a421b28dbe2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=A1=D0=B0=D0=BD=D0=B4=D0=B0=D0=BB=D0=BE=D0=B2?= Date: Sun, 21 May 2023 14:13:38 +0300 Subject: [PATCH 1/3] Best renaming --- GameSample/Fruits.h | 6 +++--- GameSample/SnakeTheGame.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/GameSample/Fruits.h b/GameSample/Fruits.h index dcf7971..0cc2142 100644 --- a/GameSample/Fruits.h +++ b/GameSample/Fruits.h @@ -17,7 +17,7 @@ class Fruits } void eat() { - updateFruit(*this, grid); + updateFruit_1(*this, grid); grid.setSymbol(this->crd, this->symbol); } @@ -25,10 +25,10 @@ class Fruits return this->crd; } - friend void updateFruit(Fruits& fruit, BaseGrid& grid); + friend void updateFruit_1(Fruits& fruit, BaseGrid& grid); }; -void updateFruit(Fruits& fruit, BaseGrid& grid) { +void updateFruit_1(Fruits& fruit, BaseGrid& grid) { fruit.crd.X = rand() % grid.getWidth(); fruit.crd.Y = rand() % grid.getHeight(); fruit.symbol = (rand() % 2 == 0) ? 42 : 43; diff --git a/GameSample/SnakeTheGame.h b/GameSample/SnakeTheGame.h index c049629..318c346 100644 --- a/GameSample/SnakeTheGame.h +++ b/GameSample/SnakeTheGame.h @@ -21,13 +21,13 @@ class SnakeTheGame : public GameBase {} bool snakeOnFruit(Snake& snk, Fruits& fruit) { - return snk.getCoords() == fruit.getCoords(); + return 1; } void runGame() override { view.printMessage(); Fruits fruit{ COORD{}, 0, view.getViewGrid() }; - updateFruit(fruit, view.getViewGrid()); + updateFruit_1(fruit, view.getViewGrid()); while (true) { view.drawLines(); controls.checkInput(); From bae5c04f3ecd23f682eda2f7f23bfd4fb84e8cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=A1=D0=B0=D0=BD=D0=B4=D0=B0=D0=BB=D0=BE=D0=B2?= Date: Sun, 21 May 2023 13:46:17 +0300 Subject: [PATCH 2/3] Fix fatal errors --- GameSample/Fruits.h | 36 ---------------------------- GameSample/SnakeTheGame.h | 50 --------------------------------------- 2 files changed, 86 deletions(-) delete mode 100644 GameSample/Fruits.h delete mode 100644 GameSample/SnakeTheGame.h diff --git a/GameSample/Fruits.h b/GameSample/Fruits.h deleted file mode 100644 index 0cc2142..0000000 --- a/GameSample/Fruits.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include -#include "BaseGrid.h" - -class Fruits -{ - char symbol; - COORD crd; - BaseGrid& grid; -public: - Fruits(COORD crd, char symbol, BaseGrid& grid) : - crd(crd), - symbol(symbol), - grid(grid) - { - grid.setSymbol(this->crd, this->symbol); - } - - void eat() { - updateFruit_1(*this, grid); - grid.setSymbol(this->crd, this->symbol); - } - - const COORD getCoords() const { - return this->crd; - } - - friend void updateFruit_1(Fruits& fruit, BaseGrid& grid); -}; - -void updateFruit_1(Fruits& fruit, BaseGrid& grid) { - fruit.crd.X = rand() % grid.getWidth(); - fruit.crd.Y = rand() % grid.getHeight(); - fruit.symbol = (rand() % 2 == 0) ? 42 : 43; -} - diff --git a/GameSample/SnakeTheGame.h b/GameSample/SnakeTheGame.h deleted file mode 100644 index 318c346..0000000 --- a/GameSample/SnakeTheGame.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once -#include "SnakeView.h" -#include "Snake.h" -#include "Controls.h" -#include "GameBase.h" -#include "Fruits.h" - -const int WIDTH = 25, HEIGHT = 25; - - -class SnakeTheGame : public GameBase -{ - SnakeView view; - Snake snk; - SnakeControls controls; -public: - SnakeTheGame() : - view(WIDTH, HEIGHT), - snk( WIDTH / 2, HEIGHT / 2, view.getViewGrid(), '*', 1 ), - controls(snk) - {} - - bool snakeOnFruit(Snake& snk, Fruits& fruit) { - return 1; - } - - void runGame() override { - view.printMessage(); - Fruits fruit{ COORD{}, 0, view.getViewGrid() }; - updateFruit_1(fruit, view.getViewGrid()); - while (true) { - view.drawLines(); - controls.checkInput(); - snk.move(); - /*if (fruit.isEaten()) { - generateOtherFruit - }*/ - } - /*while (true) { - view.drawLines(); - controls.checkInput(); - snk.move(); - }*/ - } - - void initGame() override { - std::cout << "Game initialized\n"; - } -}; - From e59b24e25a85671c0593b464d65d8aab0dfc2610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=A1=D0=B0=D0=BD=D0=B4=D0=B0=D0=BB=D0=BE=D0=B2?= Date: Sun, 21 May 2023 14:31:15 +0300 Subject: [PATCH 3/3] Returned file --- GameSample/Fruits.h | 30 +++++++++++++++++++++++ GameSample/SnakeTheGame.h | 50 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 GameSample/Fruits.h create mode 100644 GameSample/SnakeTheGame.h diff --git a/GameSample/Fruits.h b/GameSample/Fruits.h new file mode 100644 index 0000000..7caab43 --- /dev/null +++ b/GameSample/Fruits.h @@ -0,0 +1,30 @@ +#pragma once +#include +#include "BaseGrid.h" + +class Fruits +{ + char symbol; + COORD crd; + BaseGrid& grid; +public: + Fruits(COORD crd, char symbol, BaseGrid& grid) : + crd(crd), + symbol(symbol), + grid(grid) + { + grid.setSymbol(this->crd, this->symbol); + } + + void eat() { + grid.setSymbol(this->crd, this->symbol); + } + + const COORD getCoords() const { + return this->crd; + } +}; + + + + diff --git a/GameSample/SnakeTheGame.h b/GameSample/SnakeTheGame.h new file mode 100644 index 0000000..45c27de --- /dev/null +++ b/GameSample/SnakeTheGame.h @@ -0,0 +1,50 @@ +#pragma once +#include "SnakeView.h" +#include "Snake.h" +#include "Controls.h" +#include "GameBase.h" +#include "Fruits.h" + +const int WIDTH = 25, HEIGHT = 25; + + +class SnakeTheGame : public GameBase +{ + SnakeView view; + Snake snk; + SnakeControls controls; +public: + SnakeTheGame() : + view(WIDTH, HEIGHT), + snk( WIDTH / 2, HEIGHT / 2, view.getViewGrid(), '*', 1 ), + controls(snk) + {} + + bool snakeOnFruit(Snake& snk, Fruits& fruit) { + return snk.getCoords().X == fruit.getCoords().X && + snk.getCoords().Y == fruit.getCoords().Y; + } + + void runGame() override { + view.printMessage(); + Fruits fruit{ {WIDTH / 4, HEIGHT / 4}, '%', view.getViewGrid()}; + while (true) { + view.drawLines(); + controls.checkInput(); + snk.move(); + /*if (fruit.isEaten()) { + generateOtherFruit + }*/ + } + /*while (true) { + view.drawLines(); + controls.checkInput(); + snk.move(); + }*/ + } + + void initGame() override { + std::cout << "Game initialized\n"; + } +}; +