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
Tetromino/Tetromino.h
- Committer:
- el17ajf
- Date:
- 2019-04-04
- Revision:
- 24:555cb65502a3
- Parent:
- 18:24ce897024d0
- Child:
- 25:bf47fe41883a
File content as of revision 24:555cb65502a3:
#ifndef TETROMINO_H #define TETROMINO_H #include "Block.h" /** Tetromino class * @brief Class containing the information about a Tetrimono * This class is immutable by design - a Tetromino's state should not be * changed after it is created, rather replaced with a changed version, * much like Strings in many OOP languages. This helps with collion detection. */ class Tetromino { public: /** * Type enum * Contains the 7 possible tetrominos, represented by letters as on * the wikipedia page https://en.wikipedia.org/wiki/Tetromino */ enum Type { I, O, T, J, L, S, Z }; /** * @brief Gets a new Tetromino object from a given type * @param type The type of the tetromino * @returns A new Tetromino object */ static Tetromino getTetrominoOfType(Tetromino::Type type); /** * @brief This Tetromino, but moved to the left * @returns A tetromino with the same blocks as this, but translated [-1, 0] */ Tetromino movedLeft(); /** * @brief This Tetromino, but moved to the right * @returns A tetromino with the same blocks as this, but translated [+1, 0] */ Tetromino movedRight(); /** * @brief This Tetromino, but moved down * @returns A tetromino with the same blocks as this, but translated [0, 1] */ Tetromino movedDown(); /** * @brief This Tetromino, but rotated clockwise * @returns A tetromino with the same blocks as this, but rotated * 90 degrees clockwise about the 'origin' (rounded down) */ Tetromino rotatedClockwise(); /** * @brief This Tetromino, but rotated anticlockwise * @returns A tetromino with the same blocks as this, but rotated * 90 degrees anticlockwise about the 'origin' (rounded down) */ Tetromino rotatedAnticlockwise(); /** * @brief Draw this Tetramino with the * @returns A tetromino with the same blocks as this, but rotated * 90 degrees about the 'origin' (rounded down) */ void draw(); /** * @brief Gets a random tetromino type * @returns A psudo-randomly selected Tetromino with rand() */ static Type getRandomTetrominoType(); Tetromino(); // TODO is this needed ~Tetromino(); Block blocks[4]; /** * @brief This Tetromino, but translated by [x, 0] * @returns A tetromino with the same blocks as this, translated by [x, 0] */ Tetromino teleportedTo(int x); private: Tetromino translated(int dx, int dy); static Tetromino getTetrominoFromString(const char * str); Tetromino(Block a, Block b, Block c, Block d); }; #endif