-
Notifications
You must be signed in to change notification settings - Fork 0
/
draughtboard.h
209 lines (138 loc) · 3.7 KB
/
draughtboard.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* draughtBoard.h
* Represent a checkers gameboard.
*
* @author Yoan DUMAS
* @versionn 1.0
* @date 18/12/2013
*/
#ifndef DRAUGHTBOARD_H
#define DRAUGHTBOARD_H
#include <string>
#include <sstream>
#include <QtGui>
#include <stdexcept>
#include "rules.h"
#include "piece.h"
#include "clickablelabel.h"
class SquareNotEmpty : public std::exception {
public:
/**
* Constructor of square not empty exception.
* @param msg, the log of the error.
*/
SquareNotEmpty(const char * msg) {
std::ostringstream oss;
oss << msg;
this->msg_ = oss.str();
}
/**
* Destructor of the exception.
*/
virtual ~SquareNotEmpty() throw(){}
/**
* Permits to describe the error.
* @return The log of the error.
*/
virtual const char * what() const throw() {
return this->msg_.c_str();
}
private:
/** The log of the error. */
std::string msg_;
};
class SquareEmpty : public std::exception {
public:
/**
* Constructor of square is empty exception.
* @param msg, the log of the error.
*/
SquareEmpty(const char * msg) {
std::ostringstream oss;
oss << msg;
this->msg_ = oss.str();
}
/**
* Destructor of the exception.
*/
virtual ~SquareEmpty() throw(){}
/**
* Permits to describe the error.
* @return The log of the error.
*/
virtual const char * what() const throw() {
return this->msg_.c_str();
}
private:
/** The log of the error. */
std::string msg_;
};
class DraughtBoard {
public:
/**
* Constructor of draughtboard.
*/
DraughtBoard(/*QObject * parent = 0*/);
/**
* Retunrs the color of the selected square.
* @return The color of the selected square.
*/
color_t getColor(const position_t & inPos) const;
/**
* Draws the draughtpiece.
*/
QWidget * draw() const;
/**
* Destructor of draughtboard.
*/
~DraughtBoard();
/**
* Permits to know if the position passed in parameter is filled by a Piece.
* @return true if the square is free.
* @throw std::out_of_range
*/
bool isFree(const position_t & inPos) const throw(std::out_of_range);
/**
* Permits to add a new Piece to the draughtboard.
* @param inPiece, the Piece to add.
* @throw SquareNotEmpty exception if the square is not empty.
*/
void addPiece(Piece & inPiece) throw(SquareNotEmpty);
/**
* Permits to delete a Piece from the draughtboard.
* @param inPos, the position of the Piece to delete.
* @throw SquareEmpty exception if the square is empty.
*/
void deletePiece(const position_t & inPos) throw(SquareEmpty);
/**
* Permits to move a Piece from a given position to another.
* @param inSrc, the source position of the Piece.
* @param inDst, the destination position of the Piece.
*/
void move(const position_t & inSrc, const position_t & inDst) throw(SquareNotEmpty, SquareEmpty);
/**
* Returns the Piece contained in the square to the given position.
* @param inPosition, the position of the Piece on the draughtboard.
* @return The piece wished.
*/
const Piece * getPiece(const position_t & inPosition) const;
/**
* Return the table of clickable labels.
* @return The table of clickable labels.
*/
ClickableLabel ** getLabelTable();
private:
/**
* The gameboard.
*/
Piece *** gameboard_;
/**
* Initialyzes all sqares of the draughtboard to NULL.
*/
void init();
/**
* ClickableLabel table.
*/
ClickableLabel ** labelTable_;
};
#endif // DRAUGHTBOARD_H