/* * 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: /* * Create and allocate an empty tile list. */ TileList(); /* * Deallocate the tile list. */ ~TileList(); /* * Add `tile` to the tile list, possibly reallocating. O(1) amortized. */ void addTile(Tile tile); /* * Draw all tiles to `scene`. O(n). */ void drawAll(QGraphicsScene *scene) const; /* * Return the index of the top tile at (x, y). O(n). */ int indexOfTopTile(int x, int y) const; /* * Move the top tile at (x, y) to the bottom. O(n). */ void lower(int x, int y); /* * Move the bottom tile at (x, y) to the top. O(n). */ void raise(int x, int y); /* * Remove the top tile at (x, y). O(n). */ void remove(int x, int y); /* * Remove all tiles at (x, y). O(n^2). */ void removeAll(int x, int 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