summaryrefslogtreecommitdiffstats
path: root/labb3/tiles/TileList.h
blob: 10cfdfbdc1bc0f9f42d09adc9d42c9caa73ea918 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * 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 <QGraphicsScene>
#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