-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcringe.cpp
234 lines (217 loc) · 6.91 KB
/
cringe.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include<iostream>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<string.h>
#include <windows.h>
#include <time.h>
// рандомные импорты
#define SCREEN_WIDTH 90
#define SCREEN_HEIGHT 26
#define WIN_WIDTH 70
#define MENU_WIDTH 20
#define GAP_SIZE 7
#define PIPE_DIF 45
// всякие константы
using namespace std;
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // буду менять цвета
COORD CursorPosition; // Буду обрабатывать откуда cout
boolean goesUp = false; // Буду рисовать птичку вверх и птичку вниз
int pipePos[3];
int gapPos[3];
int pipeFlag[3];
char bird[3][6] = { ' ','_','_','_',' ',' ',
'/',' ','v','o','\\','>',
'|', '_', '_', '_', '/' ,' ' };
char birdd[3][6] = { ' ','_','_','_',' ',' ',
'/',' ','^','o','\\','>',
'|', '_', '_', '_', '/' ,' ' };
int birdPos = 6;
int score = 0;
void gotoxy(int x, int y) {
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console, CursorPosition);
}
void setcursor(bool visible, DWORD size) {
if (size == 0) size = 20;
CONSOLE_CURSOR_INFO lpCursor;
lpCursor.bVisible = visible;
lpCursor.dwSize = size;
SetConsoleCursorInfo(console, &lpCursor);
}
void drawBorder() {
SetConsoleTextAttribute(console, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
for (int i = 0; i <= SCREEN_WIDTH; i++) {
gotoxy(i, 0); cout << "#";
gotoxy(i, SCREEN_HEIGHT); cout << "#";
}
for (int i = 0; i < SCREEN_HEIGHT; i++) {
gotoxy(0, i); cout << "#";
gotoxy(SCREEN_WIDTH, i); cout << "#";
}
for (int i = 0; i < SCREEN_HEIGHT; i++) {
gotoxy(WIN_WIDTH, i); cout << "#";
}
} // заливка по краям
void generatePipe(int ind) {
gapPos[ind] = 3 + rand() % 14;
} // трубу рандомим для того чтобы вставить
void drawPipe(int ind) {
SetConsoleTextAttribute(console, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
if (pipeFlag[ind] == true) {
for (int i = 0; i < gapPos[ind]; i++) {
gotoxy(WIN_WIDTH - pipePos[ind], i + 1); cout << "|*|";
}
for (int i = gapPos[ind] + GAP_SIZE; i < SCREEN_HEIGHT - 1; i++) {
gotoxy(WIN_WIDTH - pipePos[ind], i + 1); cout << "|*|";
}
}
} // рисуем сгенерированные трубы из списка
void erasePipe(int ind) {
if (pipeFlag[ind] == true) {
for (int i = 0; i < gapPos[ind]; i++) {
gotoxy(WIN_WIDTH - pipePos[ind], i + 1); cout << " ";
}
for (int i = gapPos[ind] + GAP_SIZE; i < SCREEN_HEIGHT - 1; i++) {
gotoxy(WIN_WIDTH - pipePos[ind], i + 1); cout << " ";
}
}
} // стираем старую чтобы ткнуть новую по кд
void drawBird() {
SetConsoleTextAttribute(console, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 6; j++) {
if (goesUp) {
gotoxy(j + 2, i + birdPos); cout << bird[i][j];
} else {
gotoxy(j + 2, i + birdPos); cout << birdd[i][j];
}
}
}
} // Самый лучший рисовальщик птиц
void eraseBird() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 6; j++) {
gotoxy(j + 2, i + birdPos); cout << " ";
}
}
} // Какая досадная потеря
int collision() {
if (pipePos[0] >= 61) {
if (birdPos < gapPos[0] - 1 || birdPos > gapPos[0] - 2 + GAP_SIZE) {
return 1;
}
}
return 0;
} // Проверка на столкновение(true/false но интами)
void death() {
system("cls");
cout << endl;
SetConsoleTextAttribute(console, FOREGROUND_RED | FOREGROUND_INTENSITY);
cout << "\t\t--------------------------" << endl;
cout << "\t\t--- Напился и разбился ---" << endl;
cout << "\t\t--------------------------" << endl << endl;
SetConsoleTextAttribute(console, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout << "\t\tНажми любую кнопку чтобы вернуться в меню.";
_getch();
} // Очистить всё и вывести текст с цветом
void updateScore() {
gotoxy(WIN_WIDTH + 7, 5); cout << "Очков: " << score << endl;
} // Выводить очки
void help() {
system("cls");
SetConsoleTextAttribute(console, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout << "Как играть:" << endl;
SetConsoleTextAttribute(console, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout << "Кликай на пробел чтобы птичка подлетала.";
SetConsoleTextAttribute(console, FOREGROUND_RED | FOREGROUND_INTENSITY);
cout << "\n\nНажми любую кнопку чтобы вернуться в меню.";
_getch();
} // Окошко с помощью
void play() {
birdPos = 6;
score = 0;
pipeFlag[0] = 1;
pipeFlag[1] = 0;
pipePos[0] = pipePos[1] = 4;
system("cls");
drawBorder();
generatePipe(0);
updateScore();
SetConsoleTextAttribute(console, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
gotoxy(WIN_WIDTH + 5, 2); cout << "ПИВНАЯ ПТИЧКА";
SetConsoleTextAttribute(console, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
gotoxy(10, 5); cout << "Нажми любую кнопку чтобы начать.";
_getch();
gotoxy(10, 5); cout << " ";
while (1) {
goesUp = false;
if (_kbhit()) {
char ch = _getch();
if (ch == 32) {
if (birdPos > 3) {
birdPos -= 3;
goesUp = true;
}
}
if (ch == 27) {
break;
}
}
drawBird();
drawPipe(0);
drawPipe(1);
if (collision() == 1) {
death();
return;
}
Sleep(100);
eraseBird();
erasePipe(0);
erasePipe(1);
birdPos += 1;
if (birdPos > SCREEN_HEIGHT - 3) {
death();
return;
}
if (pipeFlag[0] == 1) pipePos[0] += 2;
if (pipeFlag[1] == 1) pipePos[1] += 2;
if (pipePos[0] >= 40 && pipePos[0] < 42) {
pipeFlag[1] = 1;
pipePos[1] = 4;
generatePipe(1);
}
if (pipePos[0] > 68) {
score++;
updateScore();
pipeFlag[1] = 0;
pipePos[0] = pipePos[1];
gapPos[0] = gapPos[1];
}
}
} // Навалил кринжа
int main() {
setlocale(LC_ALL, "Russian");
setcursor(0, 0);
srand((unsigned)time(NULL));
while(1) {
system("cls");
SetConsoleTextAttribute(console, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
gotoxy(10, 5); cout << " -------------------------- ";
gotoxy(10, 6); cout << " | Пивная птичка | ";
gotoxy(10, 7); cout << " --------------------------";
SetConsoleTextAttribute(console, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
gotoxy(10, 9); cout << "1. Словить тильт";
gotoxy(10, 10); cout << "2. Как играть?";
gotoxy(10, 11); cout << "3. Выйти из консольки";
SetConsoleTextAttribute(console, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
gotoxy(10, 13); cout << "Введи цифру от 1 до 3: ";
char op = _getche();
if (op == '1') play();
else if (op == '2') help();
else if (op == '3') exit(0);
}
return 0;
}
// https://docs.google.com/document/d/1PYNhX2t4IA-J5ro29eiEnireeZgK-gml/edit?usp=sharing&ouid=108777646462001550507&rtpof=true&sd=true