1 #include <Game/Game.hpp>
2 #include <Config/Globals.hpp>
3 #include <Misc/Utils.hpp>
4 #include <Interface/LayoutGame.hpp>
5 #include <Flow/InputManager.hpp>
6 #include <Game/BoardParser.hpp>
11 enum NamesToEasilyIdentifyTheMenuItemsInsteadOfRawNumbers
13 RESUME, RESTART, QUIT_MENU, QUIT_GAME
31 SAFE_DELETE(this->layout);
35 SAFE_DELETE(this->player);
36 SAFE_DELETE(this->board);
37 SAFE_DELETE(this->fruits);
42 SAFE_DELETE(this->layout);
46 SAFE_DELETE(this->player);
47 SAFE_DELETE(this->board);
48 SAFE_DELETE(this->fruits);
50 this->userAskedToQuit =
false;
51 this->userAskedToGoToMenu =
false;
65 this->
currentScore->board_scroll_delay = Globals::Game::board_scroll_delay;
66 this->
currentScore->board_scroll_left = Globals::Game::board_scroll_left;
67 this->
currentScore->board_scroll_right = Globals::Game::board_scroll_right;
68 this->
currentScore->board_scroll_up = Globals::Game::board_scroll_up;
69 this->
currentScore->board_scroll_down = Globals::Game::board_scroll_down;
72 int boardw = Board::large_width;
73 int boardh = Board::large_height;
75 if (Globals::Game::board_size == Globals::Game::SMALL)
77 boardw = Board::small_width;
78 boardh = Board::small_height;
80 else if (Globals::Game::board_size == Globals::Game::MEDIUM)
82 boardw = Board::medium_width;
83 boardh = Board::medium_height;
86 if (! levelName.empty())
94 this->board =
new Board(boardw,
96 ((Globals::Game::teleport) ?
102 this->player =
new Player(this->board->getStartX(),
103 this->board->getStartY());
105 if (Globals::Game::random_walls)
107 this->player->getY());
110 this->fruits =
new FruitManager(Globals::Game::fruits_at_once);
111 this->fruits->
update(this->player, this->board);
122 this->layout->
pause->getW() - 2,
123 this->layout->pause->getH() - 2);
127 item =
new MenuItem(
"Resume", RESUME);
130 item =
new MenuItem(
"Restart", RESTART);
135 item =
new MenuItem(
"Quit to Main Menu", QUIT_MENU);
138 item =
new MenuItem(
"Quit Game", QUIT_GAME);
146 void Game::handleInput()
148 if (InputManager::noKeyPressed())
153 if (InputManager::isPressed(
"quit"))
155 this->userAskedToQuit =
true;
157 else if (InputManager::isPressed(
"pause"))
165 else if (InputManager::isPressed(
'\n') ||
166 InputManager::isPressed(KEY_ENTER))
177 else if (InputManager::isPressed(
"help"))
203 if (InputManager::isPressed(
"left"))
205 this->player->move(Player::LEFT);
207 else if (InputManager::isPressed(
"right"))
209 this->player->move(Player::RIGHT);
211 else if (InputManager::isPressed(
"up"))
213 this->player->move(Player::UP);
215 else if (InputManager::isPressed(
"down"))
217 this->player->move(Player::DOWN);
239 this->
start(Globals::Game::current_level);
243 this->userAskedToGoToMenu =
true;
247 this->userAskedToQuit =
true;
264 if (! this->player->isAlive())
275 this->player->update(this->board);
277 while (this->fruits->
eatenFruit(this->player))
279 this->player->increase();
287 this->fruits->
update(this->player, this->board);
297 delta = Globals::Game::board_scroll_delay;
301 if (Globals::Game::board_scroll_up) this->board->scrollUp();
302 if (Globals::Game::board_scroll_down) this->board->scrollDown();
303 if (Globals::Game::board_scroll_left) this->board->scrollLeft();
304 if (Globals::Game::board_scroll_right) this->board->scrollRight();
321 return this->userAskedToQuit;
325 return this->userAskedToGoToMenu;
330 if (speed < 1)
return 800;
347 void Game::pause(
bool option)