Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions GameSample/Fruits.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@ class Fruits
}

void eat() {
updateFruit(*this, grid);
grid.setSymbol(this->crd, this->symbol);
}

const COORD getCoords() const {
return this->crd;
}

friend void updateFruit(Fruits& fruit, BaseGrid& grid);
};

void updateFruit(Fruits& fruit, BaseGrid& grid) {
fruit.crd.X = rand() % grid.getWidth();
fruit.crd.Y = rand() % grid.getHeight();
fruit.symbol = (rand() % 2 == 0) ? 42 : 43;
}



6 changes: 3 additions & 3 deletions GameSample/SnakeTheGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class SnakeTheGame : public GameBase
{}

bool snakeOnFruit(Snake& snk, Fruits& fruit) {
return snk.getCoords() == fruit.getCoords();
return snk.getCoords().X == fruit.getCoords().X &&
snk.getCoords().Y == fruit.getCoords().Y;
}

void runGame() override {
view.printMessage();
Fruits fruit{ COORD{}, 0, view.getViewGrid() };
updateFruit(fruit, view.getViewGrid());
Fruits fruit{ {WIDTH / 4, HEIGHT / 4}, '%', view.getViewGrid()};
while (true) {
view.drawLines();
controls.checkInput();
Expand Down