-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoard.h
167 lines (143 loc) · 2.53 KB
/
Board.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
/*****************************************************************//**
* \file Board.h
* \brief Board representation
*
* \author Chau Le
* \date July 2021
*********************************************************************/
#pragma once
#ifndef BOARD_H
#define BOARD_H
#include <iostream>
#include <array>
#include <SFML/Graphics.hpp>
#define boardWidth 6
#define boardHeight 6
#define boardSquareSize 135 // px
//#define matrixWidth boardWidth + 2
//#define matrixHeight boardHeight + 2
enum class ClearType {
NONE,
SINGLE,
DOUBLE,
TRIPLE,
TETRIS, // standard
TSPIN_MINI_NO,
TSPIN_NO,
TSPIN_MINI_SINGLE,
TSPIN_SINGLE,
TSPIN_MINI_DOUBLE,
TSPIN_DOUBLE,
TSPIN_TRIPLE, // t-spin
COMBO,
SOFTDROP,
HARDDROP, // others
SINGLE_LINE_PC,
DOUBLE_LINE_PC,
TRIPLE_LINE_PC,
TETRIS_PC,
B2B_TETRIS_PC, // pc
B2B_TETRIS, // standard
B2B_TSPIN_MINI_SINGLE,
B2B_TSPIN_SINGLE,
B2B_TSPIN_MINI_DOUBLE,
B2B_TSPIN_DOUBLE,
B2B_TSPIN_TRIPLE, // t-spin
B2B_PENTRIS_PC,
B2B_PENTRIS,
PENTRIS_PC,
PENTRIS
};
// Scoring array mapping with the ClearType enums
static int clearTypeScore[] = { 0,
100,
300,
500,
800,
0,
0,
200,
800,
400,
1200,
1600,
0,
0,
0,
800,
1200,
1800,
2000,
3200,
1200,
300,
1200,
600,
1800,
2400,
5000,
3000,
3000,
2400
};
struct ClearingInfo
{
int linesCleared;
bool isPC;
};
/**
* Controls the board.
*/
class Board
{
private:
sf::Sprite image;
sf::Sprite cellImage;
std::array<std::array<short, boardWidth>, boardHeight> board = { 0 };
int xPos = 0;
int yPos = 0;
public:
Board();
Board(int xPos, int yPos);
~Board();
/**
* Draw board.
*/
void render(sf::RenderWindow& window);
/**
* Clear all lines that werre filled.
*
* \return Clearing info of how many lines was cleared and if it results a pc
*/
ClearingInfo clearLines();
bool createGarbageLine(int holePos);
/**
* Get an array representation of the board.
*/
std::array<std::array<short, boardWidth>, boardHeight> getBoard();
/**
* Set cell with a specific value.
* \param x Row index
* \param y Column index
* \param value Value to be assigned at x and y position
*/
void setCell(int x, int y, int value);
/**
* Get cell's value.
*
* \param x Row index
* \param y Column index
* \return cell's valuea at x any y position in array
*/
int getCell(int x, int y);
/**
* Print out array representation of board in the console.
*/
void print();
void setBoard(std::array<std::array<short, boardHeight>, boardWidth> board);
void clearBoard();
void enforceGravity();
int getXPos();
int getYPos();
};
#endif