summaryrefslogtreecommitdiffstats
path: root/labb3/tiles/TileList.h
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-09-21 15:44:37 +0200
committerGustav Sörnäs <gustav@sornas.net>2020-09-21 15:44:37 +0200
commit8b6a241faee1e0d9aac9281be7be883ba0332ac1 (patch)
tree9c6d51cafa4603da39d763b1b7509c2c89997517 /labb3/tiles/TileList.h
parente483926bf15d6a560885c9b26d1c51a796583745 (diff)
downloadtddd86-8b6a241faee1e0d9aac9281be7be883ba0332ac1.tar.gz
Initial solution L3
Diffstat (limited to 'labb3/tiles/TileList.h')
-rw-r--r--labb3/tiles/TileList.h50
1 files changed, 36 insertions, 14 deletions
diff --git a/labb3/tiles/TileList.h b/labb3/tiles/TileList.h
index a4b6ce6..865823f 100644
--- a/labb3/tiles/TileList.h
+++ b/labb3/tiles/TileList.h
@@ -1,8 +1,8 @@
-// This is the .h file you will edit and turn in.
-// We have provided a skeleton for you,
-// but you must finish it as described in the spec.
-// Also remove these comments here and add your own, as well as on the members.
-// TODO: remove this comment header
+/*
+ * 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
@@ -12,18 +12,40 @@
class TileList {
public:
- TileList();
- ~TileList();
- void addTile(Tile tile);
- void drawAll(QGraphicsScene* scene);
- int indexOfTopTile(int x, int y);
- void lower(int x, int y);
- void raise(int x, int y);
- void remove(int x, int y);
- void removeAll(int x, int y);
+ 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;
+ 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
+ static const int INCREASE_SIZE = 10; // how much the size is increased when
+ // it's needed
+ int cur_size = 0; // current size of array
+ int amount_tiles; // number of active tiles in array
+ Tile *tiles; // the array
+ int indexOfBottomTile(int x, int y) const;
+
+ /*
+ * 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