forked from notcamelcase01/Tetris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeader.cpp
192 lines (167 loc) · 4.02 KB
/
Header.cpp
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
#include "Header.h"
ScreenC::ScreenC()
{
GetConsoleScreenBufferInfo(this->hStdOut, &(this->csbi));
this->colsOfConsole = csbi.srWindow.Right+1;
this->rowsOfConsole = csbi.srWindow.Bottom;
this->PLayArea_RightLimit = this->colsOfConsole / 4;
isScreenBuilt = true;
}
void ScreenC::ClearScreen()
{
DWORD countt;
DWORD cellCount;
COORD homeCoords = { 0, 0 }; //FOR NOW SET TO (0,0)
if(this->hStdOut == INVALID_HANDLE_VALUE) return;
/* Get the number of cells in the current buffer */
if(!GetConsoleScreenBufferInfo(this->hStdOut, &csbi)) return;
cellCount = (this->csbi).dwSize.X *(this->csbi).dwSize.Y;
/* Fill the entire buffer with spaces */
if(!FillConsoleOutputCharacter(
this->hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&countt
)) return;
/* Fill the entire buffer with the current colors and attributes */
/*if (!FillConsoleOutputAttribute(
this->hStdOut,
(this->csbi).wAttributes,
cellCount,
homeCoords,
&countt
)) return;*/
/* Move the cursor home */
SetConsoleCursorPosition(this->hStdOut, homeCoords);
}
void Item::redef(int Shape)
{
orientation_type = 0;
m_X = PLayArea_RightLimit / 2;
m_Y = 0;
isDown = false;
current_Shape = Shape;
if (Shape == SQUARE) {
orientation[0] = "22\n22";
orientation[1] = "22\n22";
orientation[2] = "22\n22";
orientation[3] = "22\n22";
for (int i = 0;i < 4;i++) {
orientationHeight[i] = 2;
orientationBreadth[i] = 2;
}
}
if (Shape == LSHAPE) {
orientation[0] = "2\n2\n22";
orientation[1] = " 2\n222";
orientation[2] = "22\n 2\n 2";
orientation[3] = "222\n2 ";
for (int i = 0;i < 4;i++) {
orientationHeight[i] = count(orientation[i].begin(), orientation[i].end(), '\n') + 1;
orientationBreadth[i] = 4 - count(orientation[i].begin(), orientation[i].end(), '\n');
}
}
this->getMap();
}
void Item::getMap()
{
int cX = 0, cY = 0;
int c = 0;
int ty = orientation_type;
for (int k = 0; k < orientation[ty].length(); k++) {
if ((orientation[ty])[k] == '\n') {
cX = 0;
cY++;
continue;
}
else if ((orientation[ty])[k] == '2') {
X[c] = cX;
Y[c] = cY;
cX++;
c++;
continue;
}
else {
cX++;
continue;
}
}
}
Item::Item()
{
}
Item::Item(int Shape)
{
orientation_type = 0;
m_X = PLayArea_RightLimit/2;
m_Y = 0;
isDown = false;
current_Shape = Shape;
if (Shape == SQUARE) {
orientation[0] = "22\n22";
orientation[1] = "22\n22";
orientation[2] = "22\n22";
orientation[3] = "22\n22";
for (int i = 0;i < 4;i++) {
orientationHeight[i] =2;
orientationBreadth[i] = 2;
}
}
if (Shape == ISHAPE) {
orientation[0] = "2222";
orientation[1] = "2\n2\n2\n2";
orientation[2] = "2222";
orientation[3] = "2\n2\n2\n2";
for (int i = 0;i < 4;i++) {
orientationHeight[i] = count(orientation[i].begin(), orientation[i].end(), '\n') + 1;
orientationBreadth[i] = 4 - count(orientation[i].begin(), orientation[i].end(), '\n');
}
}
if (Shape == LSHAPE) {
orientation[0] = "2\n2\n22";
orientation[1] = " 2\n222";
orientation[2] = "22\n 2\n 2";
orientation[3] = "222\n2 ";
for (int i = 0;i < 4;i++) {
orientationHeight[i] = count(orientation[i].begin(), orientation[i].end(), '\n') + 1;
orientationBreadth[i] = 4 - count(orientation[i].begin(), orientation[i].end(), '\n');
}
}
this->getMap();
}
PlayArena::PlayArena()
{
//Build Game
for (int i = 0;i < rowsOfConsole;i++) {
play_arena.push_back("");
for (int j = 0;j < colsOfConsole;j++) {
if (PLayArea_RightLimit == j) {
play_arena[i] += "|";
continue;
}
play_arena[i] += " ";
}
}
for (int i = 0;i < rowsOfConsole;i++) {
dump.push_back("");
for (int j = 0;j < colsOfConsole;j++) {
if (PLayArea_RightLimit == j) {
dump[i] += "|";
continue;
}
dump[i] += " ";
}
}
score = 0;
maxStackHeight = 0;
insert_Blank_Row = play_arena[0];
for (int j = 0; j < PLayArea_RightLimit;j++) {
play_arena[rowsOfConsole - 1][j] = '=';
}
for (int j = 0;j < colsOfConsole;j++) {
stackHeight.push_back(rowsOfConsole - 2);
}
GameInfoPosX = rowsOfConsole / 2;
GameInfoPosY = (3*PLayArea_RightLimit)/4;
}