-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
365 lines (338 loc) · 6.32 KB
/
main.cpp
File metadata and controls
365 lines (338 loc) · 6.32 KB
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#include<iostream>
#include<Windows.h>
#include<conio.h>
#include<vector>
#include<string>
#include<ctime>
#pragma comment(lib, "winmm.lib")
using namespace std;
//리듬게임 By. BlockDMask.
//[PART1] make screen, change screen, input.
//[PART2] input&output, question, life.
//[PART3] setting level, play music, play time
#define MAGIC_KEY 224
#define SPACE 32
#define KEY_NUM 4
#define LIFE 3
#define MAX_LEVEL 11
enum MENU
{
GAMESTART = 0,
INFO,
QUIT
};
enum KEYBOARD
{
UP = 72,
LEFT = 75,
RIGHT = 77,
DOWN = 80
};
//Cursor move
void gotoxy(int x, int y)
{
COORD Pos;
Pos.X = 2 * x;
Pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
//title, console size
void SetConsoleView()
{
system("mode con:cols=50 lines=20");
system("title DanceDance");
}
//-----------Draw-----------------
void DrawReadyGame()
{
system("cls");
gotoxy(5, 2);
cout << "******************************";
gotoxy(5, 3);
cout << "* Dance Dance *";
gotoxy(5, 4);
cout << "******************************";
gotoxy(10, 8);
cout << "GameStart";
gotoxy(10, 9);
cout << "GameInfo";
gotoxy(10, 10);
cout << "Quit" << endl;
}
void DrawInfoGame()
{
system("cls");
gotoxy(1, 3);
cout << "*******************************************";
gotoxy(1, 4);
cout << "|Developer - BlockDMask";
gotoxy(1, 5);
cout << "|Blog - https://blockdmask.tistory.com/";
gotoxy(1, 8);
cout << "|Thank you.";
gotoxy(1, 9);
cout << "*******************************************";
gotoxy(1, 10);
cout << "|Music - https://www.youtube.com/HYPMUSIC";
}
void DrawStartGame(const int life, const int score, const string questionStr, const string answerStr)
{
system("cls");
gotoxy(2, 1);
cout << "*******************************************";
gotoxy(4, 3);
cout << "Life : " << life << " / " << LIFE;
gotoxy(4, 4);
cout << "Score : " << score;
gotoxy(4, 8);
cout << "Q : " << questionStr;
gotoxy(4, 10);
cout << "A : " << answerStr;
gotoxy(4, 12);
cout << "press SPACE! after input done.";
gotoxy(2, 18);
cout << "*******************************************" << endl;
}
//게임 오버 그리기
void DrawGameOver(const int playTime)
{
gotoxy(8, 8);
cout << "-------------------";
gotoxy(8, 9);
cout << "| G A M E O V E R |";
gotoxy(8, 10);
cout << " " << playTime << " sec";
gotoxy(8, 11);
cout << "-------------------";
system("pause>null");
}
//커서 움직이는것 출력
void DrawUserCursor(int& y)
{
if (y <= 0)
{
y = 0;
}
else if (y >= 2)
{
y = 2;
}
gotoxy(9, 8 + y);
cout << ">";
}
//-----------Func-----------------
MENU ReadyGame()
{
int y = 0;
int input = 0;
while (true)
{
DrawReadyGame();
DrawUserCursor(y);
input = _getch();
//→←↑↓
if (input == MAGIC_KEY)
{
switch (_getch())
{
case UP:
--y;
break;
case DOWN:
++y;
break;
}
}
else if (input == SPACE)
{
switch (y)
{
case 0:
return GAMESTART;
case 1:
return INFO;
case 2:
return QUIT;
}
}
}
}
void InfoGame()
{
DrawInfoGame();
system("pause>null");
}
void SetQuestion(vector<int>& questionVec, int level)
{
if (level > MAX_LEVEL)
{
level = MAX_LEVEL;
}
int num = 0;
srand((unsigned int)time(NULL));
for (int i = 0; i < level; ++i) //화살표의 개수 (문제 난이도)
{
num = rand() % KEY_NUM; //화살표 종류.
switch (num)
{
case 0:
questionVec.push_back(UP);
break;
case 1:
questionVec.push_back(RIGHT);
break;
case 2:
questionVec.push_back(LEFT);
break;
case 3:
questionVec.push_back(DOWN);
break;
}
}
}
void VectorToString(const vector<int> v, string& str)
{
for (int i = 0; i < static_cast<int>(v.size()); ++i)
{
switch (v[i])
{
case UP:
str += "↑ ";
break;
case DOWN:
str += "↓ ";
break;
case LEFT:
str += "← ";
break;
case RIGHT:
str += "→ ";
break;
}
}
}
bool CheckAnswer(const vector<int> questionVec, const vector<int> answerVec)
{
//숫자의 배열이 같다.
//길이 체크
if (questionVec.size() != answerVec.size())
{
//길이 다르네
return false;
}
//내용물 체크
for (int i = 0; i < static_cast<int>(questionVec.size()); ++i)
{
if (questionVec[i] != answerVec[i])
{
//다른게 있네.
return false;
}
}
return true;
}
void StartGame()
{
PlaySound("HYP-Hit.wav", NULL, SND_NODEFAULT | SND_ASYNC | SND_LOOP);
int life = LIFE;
int score = 0;
//재생했을때 현재시간.
clock_t startTime, endTime;
startTime = clock();
//→←↑↓, d a w s
//문제
vector<int> questionVec;
string questionStr = "";
//답안지
vector<int> answerVec;
string answerStr = "";
int firstInput = 0;
int secondInput = 0;
while (true)
{
int level = (score / 30) + 1;
//문제를 세팅
SetQuestion(questionVec, level);
//문제를 보여주기.
VectorToString(questionVec, questionStr);
while (true)
{
//1문제를 가지고 문제를 푼다.
DrawStartGame(life, score, questionStr, answerStr);
if (life == 0)
{
//게임 오버일때 현재시간
endTime = clock();
int playTime = static_cast<int>((endTime - startTime) / CLOCKS_PER_SEC);
DrawGameOver(playTime);
PlaySound(NULL, NULL, 0);
return;
}
//정답 하나씩 입력.
firstInput = _getch();
if (firstInput == MAGIC_KEY)
{
secondInput = _getch();
answerVec.push_back(secondInput);
switch (secondInput)
{
case UP:
answerStr += "↑ ";
break;
case DOWN:
answerStr += "↓ ";
break;
case LEFT:
answerStr += "← ";
break;
case RIGHT:
answerStr += "→ ";
break;
}
}
else if (firstInput == SPACE)
{
//답안 제출
//답안 확인
if (CheckAnswer(questionVec, answerVec))
{
score += 10;
}
else
{
//틀렸다.
--life;
score -= 5;
if (score < 0)
{
score = 0;
}
}
questionVec.clear();
questionStr = "";
answerVec.clear();
answerStr = "";
break;
}
}
}
}
int main(void)
{
SetConsoleView();
while (true)
{
switch (ReadyGame())
{
case GAMESTART:
StartGame();
break;
case INFO:
InfoGame();
break;
case QUIT:
return 0;
}
}
return 0;
}