Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of el17ajf by
Diff: Game/Game.cpp
- Revision:
- 21:62d2b5b73160
- Parent:
- 19:370d83a8dc33
- Child:
- 22:0a474f074553
--- a/Game/Game.cpp Wed Apr 03 17:25:15 2019 +0000 +++ b/Game/Game.cpp Wed Apr 03 20:33:27 2019 +0000 @@ -1,7 +1,8 @@ #include "Game.h" #include "Input.h" #include "Engine.h" -#include "Menus.h" +#include "MenuManager.h" +#include "GameOverMenu.h" #include "Prefs.h" Game::Game(Difficulty difficulty) { @@ -28,10 +29,7 @@ start_x = Grid::GRID_WIDTH / 2 - 1; currentTetromino = currentTetromino.teleportedTo(start_x); score = 0; - Prefs prefs; - playerNumber = prefs.getKey(Prefs::LAST_PLAYER) + 1; - - printf(">>>>>>> made game ...\n"); + playerNumber = Prefs::getInstance()->getKey(Prefs::LAST_PLAYER) + 1; } Game::~Game() { @@ -52,8 +50,6 @@ if (Input::buttonHit(Input::RIGHT)) { if (grid.isSpaceForTetromino(currentTetromino.movedRight())) { currentTetromino = currentTetromino.movedRight(); - } else { - printf("NO SPACE TO THE RIGHT"); } } if (Input::buttonHit(Input::UP)) { @@ -106,18 +102,16 @@ } void Game::addScoreToLeaderboard() { - Prefs prefs; for (int i = 0; i < Prefs::HIGHSCORE3; i++) { - if (score > prefs.getKey((Prefs::Key)i)) { - prefs.setKey((Prefs::Key)i, score); - prefs.setKey((Prefs::Key)(i + 3), playerNumber); + if (score > Prefs::getInstance()->getKey((Prefs::Key)i)) { + Prefs::getInstance()->setKey((Prefs::Key)i, score); + Prefs::getInstance()->setKey((Prefs::Key)(i + 3), playerNumber); } } } void Game::gameOver() { addScoreToLeaderboard(); - Prefs prefs; - prefs.setKey(Prefs::LAST_PLAYER, playerNumber); - Menus::add(Menus::GAME_OVER); + Prefs::getInstance()->setKey(Prefs::LAST_PLAYER, playerNumber); + Menus::MenuManager::add(new Menus::GameOverMenu()); }