ELEC2645 (2018/19) / Mbed 2 deprecated el17ajf

Dependencies:   mbed

Fork of el17ajf by Angus Findlay

Committer:
el17ajf
Date:
Thu Apr 04 08:08:01 2019 +0000
Revision:
24:555cb65502a3
Parent:
18:24ce897024d0
Child:
25:bf47fe41883a
Documented the Tetromino class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17ajf 18:24ce897024d0 1 #ifndef TETROMINO_H
el17ajf 18:24ce897024d0 2 #define TETROMINO_H
el17ajf 18:24ce897024d0 3
el17ajf 4:aa433f9865a6 4 #include "Block.h"
el17ajf 4:aa433f9865a6 5
el17ajf 24:555cb65502a3 6 /** Tetromino class
el17ajf 24:555cb65502a3 7 * @brief Class containing the information about a Tetrimono
el17ajf 24:555cb65502a3 8 * This class is immutable by design - a Tetromino's state should not be
el17ajf 24:555cb65502a3 9 * changed after it is created, rather replaced with a changed version,
el17ajf 24:555cb65502a3 10 * much like Strings in many OOP languages. This helps with collion detection.
el17ajf 24:555cb65502a3 11 */
el17ajf 4:aa433f9865a6 12 class Tetromino {
el17ajf 4:aa433f9865a6 13 public:
el17ajf 24:555cb65502a3 14 /**
el17ajf 24:555cb65502a3 15 * Type enum
el17ajf 24:555cb65502a3 16 * Contains the 7 possible tetrominos, represented by letters as on
el17ajf 24:555cb65502a3 17 * the wikipedia page https://en.wikipedia.org/wiki/Tetromino
el17ajf 24:555cb65502a3 18 */
el17ajf 4:aa433f9865a6 19 enum Type {
el17ajf 4:aa433f9865a6 20 I, O, T, J, L, S, Z
el17ajf 4:aa433f9865a6 21 };
el17ajf 24:555cb65502a3 22
el17ajf 24:555cb65502a3 23 /**
el17ajf 24:555cb65502a3 24 * @brief Gets a new Tetromino object from a given type
el17ajf 24:555cb65502a3 25 * @param type The type of the tetromino
el17ajf 24:555cb65502a3 26 * @returns A new Tetromino object
el17ajf 24:555cb65502a3 27 */
el17ajf 8:5066ce13a430 28 static Tetromino getTetrominoOfType(Tetromino::Type type);
el17ajf 24:555cb65502a3 29
el17ajf 24:555cb65502a3 30 /**
el17ajf 24:555cb65502a3 31 * @brief This Tetromino, but moved to the left
el17ajf 24:555cb65502a3 32 * @returns A tetromino with the same blocks as this, but translated [-1, 0]
el17ajf 24:555cb65502a3 33 */
el17ajf 4:aa433f9865a6 34 Tetromino movedLeft();
el17ajf 24:555cb65502a3 35
el17ajf 24:555cb65502a3 36 /**
el17ajf 24:555cb65502a3 37 * @brief This Tetromino, but moved to the right
el17ajf 24:555cb65502a3 38 * @returns A tetromino with the same blocks as this, but translated [+1, 0]
el17ajf 24:555cb65502a3 39 */
el17ajf 4:aa433f9865a6 40 Tetromino movedRight();
el17ajf 24:555cb65502a3 41
el17ajf 24:555cb65502a3 42 /**
el17ajf 24:555cb65502a3 43 * @brief This Tetromino, but moved down
el17ajf 24:555cb65502a3 44 * @returns A tetromino with the same blocks as this, but translated [0, 1]
el17ajf 24:555cb65502a3 45 */
el17ajf 6:a54df561f442 46 Tetromino movedDown();
el17ajf 24:555cb65502a3 47
el17ajf 24:555cb65502a3 48 /**
el17ajf 24:555cb65502a3 49 * @brief This Tetromino, but rotated clockwise
el17ajf 24:555cb65502a3 50 * @returns A tetromino with the same blocks as this, but rotated
el17ajf 24:555cb65502a3 51 * 90 degrees clockwise about the 'origin' (rounded down)
el17ajf 24:555cb65502a3 52 */
el17ajf 7:2e37bad816cb 53 Tetromino rotatedClockwise();
el17ajf 24:555cb65502a3 54
el17ajf 24:555cb65502a3 55 /**
el17ajf 24:555cb65502a3 56 * @brief This Tetromino, but rotated anticlockwise
el17ajf 24:555cb65502a3 57 * @returns A tetromino with the same blocks as this, but rotated
el17ajf 24:555cb65502a3 58 * 90 degrees anticlockwise about the 'origin' (rounded down)
el17ajf 24:555cb65502a3 59 */
el17ajf 7:2e37bad816cb 60 Tetromino rotatedAnticlockwise();
el17ajf 24:555cb65502a3 61
el17ajf 24:555cb65502a3 62 /**
el17ajf 24:555cb65502a3 63 * @brief Draw this Tetramino with the
el17ajf 24:555cb65502a3 64 * @returns A tetromino with the same blocks as this, but rotated
el17ajf 24:555cb65502a3 65 * 90 degrees about the 'origin' (rounded down)
el17ajf 24:555cb65502a3 66 */
el17ajf 6:a54df561f442 67 void draw();
el17ajf 24:555cb65502a3 68
el17ajf 24:555cb65502a3 69 /**
el17ajf 24:555cb65502a3 70 * @brief Gets a random tetromino type
el17ajf 24:555cb65502a3 71 * @returns A psudo-randomly selected Tetromino with rand()
el17ajf 24:555cb65502a3 72 */
el17ajf 6:a54df561f442 73 static Type getRandomTetrominoType();
el17ajf 24:555cb65502a3 74
el17ajf 7:2e37bad816cb 75 Tetromino(); // TODO is this needed
el17ajf 7:2e37bad816cb 76 ~Tetromino();
el17ajf 7:2e37bad816cb 77 Block blocks[4];
el17ajf 24:555cb65502a3 78
el17ajf 24:555cb65502a3 79 /**
el17ajf 24:555cb65502a3 80 * @brief This Tetromino, but translated by [x, 0]
el17ajf 24:555cb65502a3 81 * @returns A tetromino with the same blocks as this, translated by [x, 0]
el17ajf 24:555cb65502a3 82 */
el17ajf 15:afeefa3ceb61 83 Tetromino teleportedTo(int x);
el17ajf 8:5066ce13a430 84
el17ajf 6:a54df561f442 85 private:
el17ajf 6:a54df561f442 86 Tetromino translated(int dx, int dy);
el17ajf 8:5066ce13a430 87 static Tetromino getTetrominoFromString(const char * str);
el17ajf 6:a54df561f442 88 Tetromino(Block a, Block b, Block c, Block d);
el17ajf 18:24ce897024d0 89 };
el17ajf 18:24ce897024d0 90 #endif