7
7
#include < SFML/Graphics/RectangleShape.hpp>
8
8
#include < SFML/Graphics/Rect.hpp>
9
9
10
- #include < array>
11
-
12
10
Table::completetion::completetion (mark theType, unsigned a, unsigned b) {
13
11
type = theType;
14
12
@@ -28,7 +26,42 @@ Table::completetion::completetion(mark theType, unsigned a, unsigned b) {
28
26
29
27
Table::Table (Score& theScore) : theScore(theScore)
30
28
{
29
+ sf::Vector2f startPosition = { TABLE_POSITION_X, TABLE_POSITION_Y };
30
+ float lineLength = CELL_SPACING * TABLE_SIZE;
31
+
32
+ for (unsigned i = 0 ; i < TABLE_SIZE - 1 ; i++) {
33
+ float rowY = CELL_SPACING * (i + 1 .f );
34
+ minorGrid[i * 2 ].position = { startPosition.y , rowY + startPosition.y };
35
+ minorGrid[i * 2 ].color = COLOR_LIGHT_BLUE;
36
+ minorGrid[i * 2 + 1 ].position = { lineLength + startPosition.y , rowY + startPosition.y };
37
+ minorGrid[i * 2 + 1 ].color = COLOR_LIGHT_BLUE;
38
+ }
39
+
40
+ unsigned gridPositionOffset = (TABLE_SIZE - 1 ) * 2 ;
41
+ for (unsigned i = 0 ; i < TABLE_SIZE - 1 ; i++) {
42
+ float rowX = CELL_SPACING * (i + 1 .f );
43
+ minorGrid[gridPositionOffset + i * 2 ].position = { rowX + startPosition.x , startPosition.x };
44
+ minorGrid[gridPositionOffset + i * 2 ].color = COLOR_LIGHT_BLUE;
45
+ minorGrid[gridPositionOffset + i * 2 + 1 ].position = { rowX + startPosition.x , lineLength + startPosition.x };
46
+ minorGrid[gridPositionOffset + i * 2 + 1 ].color = COLOR_LIGHT_BLUE;
47
+ }
31
48
49
+ for (unsigned i = 0 ; i < 4 ; i++) {
50
+ float rowY = (CELL_SPACING * 3 .f ) * i;
51
+ majorGrid[i * 2 ].position = { startPosition.y , rowY + startPosition.y };
52
+ majorGrid[i * 2 ].color = COLOR_BLACK;
53
+ majorGrid[i * 2 + 1 ].position = { lineLength + startPosition.y , rowY + startPosition.y };
54
+ majorGrid[i * 2 + 1 ].color = COLOR_BLACK;
55
+ }
56
+
57
+ gridPositionOffset = 4 * 2 ;
58
+ for (unsigned i = 0 ; i < 4 ; i++) {
59
+ float rowX = (CELL_SPACING * 3 .f ) * i;
60
+ majorGrid[gridPositionOffset + i * 2 ].position = { rowX + startPosition.x , startPosition.x };
61
+ majorGrid[gridPositionOffset + i * 2 ].color = COLOR_BLACK;
62
+ majorGrid[gridPositionOffset + i * 2 + 1 ].position = { rowX + startPosition.x , lineLength + startPosition.x };
63
+ majorGrid[gridPositionOffset + i * 2 + 1 ].color = COLOR_BLACK;
64
+ }
32
65
}
33
66
34
67
sf::Vector2i Table::mousePositionToCellPosition (const sf::Vector2f& mousePosition)
@@ -159,6 +192,13 @@ void Table::applyBlock(Block& theBlock, const sf::Vector2i& tableCellCoords) {
159
192
if (completedMarks->size () > 1 ) // give one point for getting more marks at one time
160
193
theScore.addToCombo (1 );
161
194
195
+ for (const auto & mark : *completedMarks) {
196
+ if (mark.type == mark::square)
197
+ theScore.addCompletionSquare ();
198
+ else
199
+ theScore.addCompletionLine ();
200
+ }
201
+
162
202
executeCompletetionsWith (completedMarks, cell::empty);
163
203
}
164
204
}
@@ -239,14 +279,12 @@ bool Table::canBlockBePlaced(Block& theBlock)
239
279
240
280
void Table::draw (sf::RenderWindow& window)
241
281
{
242
- sf::Vector2f startPosition = { TABLE_POSITION_X, TABLE_POSITION_Y } ;
243
- float lineLength = CELL_SPACING * TABLE_SIZE ;
282
+ sf::RectangleShape cell ;
283
+ cell. setSize ({ CELL_SPACING - 2 , CELL_SPACING - 2 }) ;
244
284
245
285
for (unsigned l = 0 ; l < 9 ; l++) {
246
286
for (unsigned c = 0 ; c < 9 ; c++) {
247
- sf::RectangleShape cell;
248
- cell.setPosition ({ startPosition.x + CELL_SPACING * l + 1 , startPosition.y + CELL_SPACING * c + 1 });
249
- cell.setSize ({ CELL_SPACING - 2 , CELL_SPACING - 2 });
287
+ cell.setPosition ({ TABLE_POSITION_X + CELL_SPACING * l + 1 .f , TABLE_POSITION_Y + CELL_SPACING * c + 1 .f });
250
288
251
289
switch (cellTable[l][c]) {
252
290
case cell::empty:
@@ -270,45 +308,6 @@ void Table::draw(sf::RenderWindow& window)
270
308
}
271
309
} // DRAW CELLS END
272
310
273
- sf::VertexArray minorGrid (sf::Lines, 2 * (TABLE_SIZE * 2 - 2 ));
274
-
275
- for (unsigned i = 0 ; i < TABLE_SIZE - 1 ; i++) {
276
- float rowY = CELL_SPACING * (i + 1 .f );
277
- minorGrid[i * 2 ].position = { startPosition.y , rowY + startPosition.y };
278
- minorGrid[i * 2 ].color = COLOR_LIGHT_BLUE;
279
- minorGrid[i * 2 + 1 ].position = { lineLength + startPosition.y , rowY + startPosition.y };
280
- minorGrid[i * 2 + 1 ].color = COLOR_LIGHT_BLUE;
281
- }
282
-
283
- unsigned gridPositionOffset = (TABLE_SIZE - 1 ) * 2 ;
284
- for (unsigned i = 0 ; i < TABLE_SIZE - 1 ; i++) {
285
- float rowX = CELL_SPACING * (i + 1 .f );
286
- minorGrid[gridPositionOffset + i * 2 ].position = { rowX + startPosition.x , startPosition.x };
287
- minorGrid[gridPositionOffset + i * 2 ].color = COLOR_LIGHT_BLUE;
288
- minorGrid[gridPositionOffset + i * 2 + 1 ].position = { rowX + startPosition.x , lineLength + startPosition.x };
289
- minorGrid[gridPositionOffset + i * 2 + 1 ].color = COLOR_LIGHT_BLUE;
290
- }
291
-
292
311
window.draw (minorGrid);
293
-
294
- sf::VertexArray majorGrid (sf::Lines, 4 * 2 * 2 );
295
-
296
- for (unsigned i = 0 ; i < 4 ; i++) {
297
- float rowY = (CELL_SPACING * 3 .f ) * i;
298
- majorGrid[i * 2 ].position = { startPosition.y , rowY + startPosition.y };
299
- majorGrid[i * 2 ].color = COLOR_BLACK;
300
- majorGrid[i * 2 + 1 ].position = { lineLength + startPosition.y , rowY + startPosition.y };
301
- majorGrid[i * 2 + 1 ].color = COLOR_BLACK;
302
- }
303
-
304
- gridPositionOffset = 4 * 2 ;
305
- for (unsigned i = 0 ; i < 4 ; i++) {
306
- float rowX = (CELL_SPACING * 3 .f ) * i;
307
- majorGrid[gridPositionOffset + i * 2 ].position = { rowX + startPosition.x , startPosition.x };
308
- majorGrid[gridPositionOffset + i * 2 ].color = COLOR_BLACK;
309
- majorGrid[gridPositionOffset + i * 2 + 1 ].position = { rowX + startPosition.x , lineLength + startPosition.x };
310
- majorGrid[gridPositionOffset + i * 2 + 1 ].color = COLOR_BLACK;
311
- }
312
-
313
312
window.draw (majorGrid); // DRAW GRID END
314
313
}
0 commit comments