-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheatHandler.cpp
More file actions
40 lines (34 loc) · 1.29 KB
/
Copy pathCheatHandler.cpp
File metadata and controls
40 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "CheatHandler.h"
#include "Game.h"
void CheatHandler::checkForCheats(Game &game, std::list<std::pair<int, int>> &snake1, std::list<std::pair<int, int>> &snake2) {
if (game.keys['a'] && game.keys['d']) {
growSnake(snake1, 3);
game.keys['a'] = false;
game.keys['d'] = false;
}
if (game.keys[75] && game.keys[77]) {
growSnake(snake2, 3);
game.keys[75] = false;
game.keys[77] = false;
}
if (game.keys['1'] && game.keys['2'] && game.keys['3']) {
activateParadiseMode(game);
game.keys['1'] = false;
game.keys['2'] = false;
game.keys['3'] = false;
}
}
// Grow the snake by a certain number of segments
void CheatHandler::growSnake(std::list<std::pair<int, int>>& snake, const int growth) {
auto tail = snake.back(); // Capture the tail before growing
for (int i = 0; i < growth; ++i) {
snake.push_back(tail); // Add new segments at the tail position
}
}
// Activate paradise mode (lots of apples everywhere, limited to 1/8 of the grid)
void CheatHandler::activateParadiseMode(Game &game) {
game.paradiseModeActive = true;
// Limit apples to 1/8 of the grid size
const int maxApples = (game.grid.getWidth() * game.grid.getHeight()) / 8;
game.generateFoodPositions(maxApples);
}