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: Tetromino/Tetromino.h
- Revision:
- 24:555cb65502a3
- Parent:
- 18:24ce897024d0
- Child:
- 25:bf47fe41883a
--- a/Tetromino/Tetromino.h Thu Apr 04 07:42:54 2019 +0000 +++ b/Tetromino/Tetromino.h Thu Apr 04 08:08:01 2019 +0000 @@ -3,22 +3,83 @@ #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: