ELEC2645 (2018/19) / Mbed 2 deprecated el17ajf

Dependencies:   mbed

Fork of el17ajf by Angus Findlay

Committer:
el17ajf
Date:
Tue Apr 23 16:38:32 2019 +0000
Revision:
34:0bb0d010e755
Parent:
25:bf47fe41883a
Child:
41:91b0c73b9e02
Documented Block 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 25:bf47fe41883a 63 * @brief Draw this Tetramino to the screen
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 34:0bb0d010e755 75 /**
el17ajf 34:0bb0d010e755 76 * Destructor
el17ajf 34:0bb0d010e755 77 */
el17ajf 7:2e37bad816cb 78 ~Tetromino();
el17ajf 34:0bb0d010e755 79
el17ajf 34:0bb0d010e755 80 /**
el17ajf 34:0bb0d010e755 81 * The 4 blocks that make up the tetromino
el17ajf 34:0bb0d010e755 82 */
el17ajf 7:2e37bad816cb 83 Block blocks[4];
el17ajf 24:555cb65502a3 84
el17ajf 24:555cb65502a3 85 /**
el17ajf 24:555cb65502a3 86 * @brief This Tetromino, but translated by [x, 0]
el17ajf 34:0bb0d010e755 87 * @param x The x coordinate to move the Tetromino to
el17ajf 24:555cb65502a3 88 * @returns A tetromino with the same blocks as this, translated by [x, 0]
el17ajf 24:555cb65502a3 89 */
el17ajf 15:afeefa3ceb61 90 Tetromino teleportedTo(int x);
el17ajf 8:5066ce13a430 91
el17ajf 6:a54df561f442 92 private:
el17ajf 6:a54df561f442 93 Tetromino translated(int dx, int dy);
el17ajf 8:5066ce13a430 94 static Tetromino getTetrominoFromString(const char * str);
el17ajf 6:a54df561f442 95 Tetromino(Block a, Block b, Block c, Block d);
el17ajf 18:24ce897024d0 96 };
el17ajf 18:24ce897024d0 97 #endif