This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
137 lines (125 loc) · 4.09 KB
/
main.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
#include "tetris.h"
int main (void){
std::string tetromino[7];
tetromino[0] += "..X.";
tetromino[0] += "..X.";//I
tetromino[0] += "..X.";
tetromino[0] += "..X.";
tetromino[1] += "..X.";
tetromino[1] += ".XX.";//T
tetromino[1] += "..X.";
tetromino[1] += "....";
tetromino[2] += "....";
tetromino[2] += ".XX.";//C
tetromino[2] += ".XX.";
tetromino[2] += "....";
tetromino[3] += "..X.";
tetromino[3] += ".XX.";//Z
tetromino[3] += ".X..";
tetromino[3] += "....";
tetromino[4] += ".X..";
tetromino[4] += ".XX.";//S
tetromino[4] += "..X.";
tetromino[4] += "....";
tetromino[5] += ".X..";
tetromino[5] += ".X..";//L
tetromino[5] += ".XX.";
tetromino[5] += "....";
tetromino[6] += "..X.";
tetromino[6] += "..X.";//J
tetromino[6] += ".XX.";
tetromino[6] += "....";
initscr ();
noecho();
cbreak();
start_color();
nodelay(stdscr,TRUE);
screen screen;
class clock clock;
while(1){//program loop
fflush(stdin);
bool gameOver = FALSE;
char keyPressed = 0;
while(1){//menu loop
screen.drawClearConsole();
screen.drawRandomStuff();
screen.drawLogo();
refresh();
usleep(750000);
keyPressed = getch();
if (keyPressed == 27){
endwin();
exit(1);
}
if (keyPressed == '\n')
break;
}
screen.drawClearConsole();
screen.drawLocalBorders();
char consoleBuffer[20][10];
for(int i = 0; i<20;i++)
for(int j = 0; j<10;j++)
consoleBuffer[i][j] = ' ';
static int tet_rot_curr = 0;
static int t_x = 3;
static int t_y = 0;
static int tet_type_curr = 0;
new_tetromino(tetromino, tet_type_curr, tet_rot_curr);
while(1){//game loop
clock.tick();
eraseTetromino(consoleBuffer, tetromino[tet_type_curr], tet_rot_curr, t_x, t_y);
screen.drawPlayArea(consoleBuffer);
keyPressed = getch();
if (clock.value == 9)
keyPressed = 's';
switch (keyPressed){
case 27:
endwin();
exit(1);
case 'a':
if(checkLegality(consoleBuffer, tetromino[tet_type_curr], tet_rot_curr, t_x, t_y, 1) == TRUE)
t_x--;
break;
case 'd':
if(checkLegality(consoleBuffer, tetromino[tet_type_curr], tet_rot_curr, t_x, t_y, 2) == TRUE)
t_x++;
break;
case 'w':
if(checkLegality(consoleBuffer, tetromino[tet_type_curr], tet_rot_curr, t_x, t_y, 3) == TRUE)
tet_rot_curr++;
break;
case 's':
if(checkLegality(consoleBuffer, tetromino[tet_type_curr], tet_rot_curr, t_x, t_y, 4) == TRUE)
t_y++;
else{
drawTetromino(consoleBuffer, tetromino[tet_type_curr], tet_rot_curr, t_x, t_y);
checkForLine(consoleBuffer);
gameOver = checkForGameOver(consoleBuffer);
new_tetromino(tetromino, tet_type_curr, tet_rot_curr);
t_x = 3, t_y = 0;
}
break;
}
drawTetromino(consoleBuffer, tetromino[tet_type_curr], tet_rot_curr, t_x, t_y);
screen.drawPlayArea(consoleBuffer);
refresh();
if (gameOver == TRUE)
break;
}
while(1){//game over loop
usleep(750000);
mvprintw(10,14,"GAME OVER");
mvprintw(12,13,"Press ENTER");
refresh();
keyPressed = getch();
if (keyPressed == 27){
endwin();
exit(1);
}
if (keyPressed == '\n')
break;
}
}
endwin();
return 0;
}