Use bigger icons, 45x45
[vexed] / playfield.h
1 #ifndef PLAYFIELD_H
2 #define PLAYFIELD_H
3 #include <QtCore>
4
5 namespace PF
6 {
7     const int FIELD_WIDTH=10;
8     const int FIELD_HEIGHT=8;
9
10     const int CELL_EMPTY=0;
11     const int CELL_WALL=1;
12
13     const int MAX_UNDO=10;
14 };
15
16 typedef int Field[PF::FIELD_WIDTH][PF::FIELD_HEIGHT];
17
18 class PlayField : public QObject
19 {
20     Q_OBJECT
21 private:
22     Field field;
23     Field undos[PF::MAX_UNDO];
24     int undoMade[PF::MAX_UNDO];
25
26     int currentUndo;
27     bool moveBlock(int w, int h, int dw, int dh);
28     bool checkFall(int w, int h);
29     bool checkGlobalFall();
30     bool checkTouch();
31 private:
32     void copy(const Field field_src, Field field_dst)
33     {
34         for(int w=0; w<PF::FIELD_WIDTH; w++)
35             for(int h=0; h<PF::FIELD_HEIGHT; h++)
36                 field_dst[w][h]=field_src[w][h];
37     }
38     void setup(const Field field_src)
39     {
40         copy(field_src, field);
41         moves=0;
42     }
43 public:
44     QString title;
45     QString solution;
46     int moves;
47     int totalUndo;
48
49     PlayField(const QString &_title, const QString &_board, const QString &_solution);
50     PlayField(PlayField *pf):title(pf->title),solution(pf->solution)
51     {
52         setup(pf->field);
53         moves=0;
54         currentUndo=0;
55         totalUndo=0;
56     }
57
58     void set(int w, int h, int cell){field[w][h]=cell;}
59     int get(int w, int h){return field[w][h];}
60     bool checkSolved();
61     const QString& getSolution()
62         {
63                 return solution;
64         }
65     void move(int w, int h, int w_new);
66     void undo();
67
68 signals:
69     void cellMoved(int w, int h, int wnew, int hnew);
70     void cellGone(int w, int h);
71 };
72
73 #endif // PLAYFIELD_H