/* * TDDD86 Lab 3a - gusso230 (group 11) * This file contains the tile list structure. * You can add, draw, lower, raise and remove tiles. */ #ifndef TILELIST_H #define TILELIST_H #include #include "Tile.h" class TileList { public: TileList(); // allocate an empty tile list ~TileList(); // deallocate the tile list void addTile(Tile tile); // add a tile to the tile list, possibly reallocating void drawAll(QGraphicsScene *scene) const; // draw all tiles to `scene` int indexOfTopTile(int x, int y) const; // return index of top tile at (x, y) void lower(int x, int y); // move the top tile at (x, y) to the bottom void raise(int x, int y); // move the bottom tile at (x, y) to the top void remove(int x, int y); // remove the top tile at (x, y) void removeAll(int x, int y); // remove all tiles at (x, y) private: static const int INITIAL_SIZE = 10; // the initial size int cur_size = 0; // current size of array int amount_tiles; // number of active tiles in array Tile *tiles; // the array /* * shiftRight and shiftLeft move a group of tiles either right or left * in the internal array. * shiftRight(1, 4): * 0 1 2 3 4 5 * 0 1 1 2 3 5 * shiftLeft(4, 1): * 0 1 2 3 4 5 * 0 2 3 4 4 5 * Effectively, `start` is duplicated either to the right for shiftRight * or to the left for shiftLeft, and `end` is lost. */ void shiftRight(int start, int end); void shiftLeft(int start, int end); }; #endif // TILELIST_H