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:
- 39:e128071a95b0
- Parent:
- 36:c854f1f51f43
--- a/Game/Game.cpp Sat Apr 27 16:06:33 2019 +0000
+++ b/Game/Game.cpp Mon Apr 29 16:30:47 2019 +0000
@@ -9,15 +9,13 @@
#include "Math.h"
Game::Game(Difficulty difficulty) :
- score(0),
- next_tetromino_type(Tetromino::getRandomTetrominoType()),
+ score(0), next_tetromino_type(Tetromino::getRandomTetrominoType()),
current_tetromino(
Tetromino::getTetrominoOfType(Tetromino::getRandomTetrominoType())),
- frames(0),
- last_move_frame(0),
- start_x(Grid::GRID_WIDTH / 2 - 1),
+ frames(0), last_move_frame(0), start_x(Grid::GRID_WIDTH / 2 - 1),
player_number(Prefs::getInstance()->getKey(Prefs::LAST_PLAYER)) {
current_tetromino = current_tetromino.teleportedTo(start_x);
+
switch (difficulty) {
case EASY:
move_frames = Engine::FPS / 6; // ~ 160ms
@@ -32,12 +30,8 @@
score_for_row = 10;
break;
}
-
- if (player_number == Prefs::EMPTY) {
- player_number = 1;
- } else {
- player_number += 1;
- }
+
+ player_number = player_number == Prefs::EMPTY ? 1 : player_number + 1;
}
Game::~Game() {}
@@ -52,21 +46,17 @@
if (grid.isSpaceForTetromino(current_tetromino.movedLeft())) {
current_tetromino = current_tetromino.movedLeft();
}
- }
- if (Input::buttonHit(Input::RIGHT)) {
+ } else if (Input::buttonHit(Input::RIGHT)) {
if (grid.isSpaceForTetromino(current_tetromino.movedRight())) {
current_tetromino = current_tetromino.movedRight();
}
- }
- if (Input::buttonHit(Input::UP)) {
+ } else if (Input::buttonHit(Input::UP)) {
if (grid.isSpaceForTetromino(current_tetromino.rotatedClockwise())) {
current_tetromino = current_tetromino.rotatedClockwise();
}
- }
- if (Input::buttonHit(Input::DOWN)) {
+ } else if (Input::buttonHit(Input::DOWN)) {
dropCurrentTetromino();
- }
- if (Input::buttonHit(Input::START)) {
+ } else if (Input::buttonHit(Input::START)) {
Menus::MenuManager::add(new Menus::PausedMenu());
}
}
