티스토리 뷰
메이플스토리의 구애의 춤을 만들어 보았습니다.
모양에 맞는 방향키를 누르시면 됩니다.
클리어 화면입니다.
소스코드입니다.
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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | #include<stdio.h> #include<windows.h> #include<time.h> #include<conio.h> #include<stdlib.h> #define _CRT_SECURE_NO_WARNINGS #define LEFT 75 #define RIGHT 77 #define UP 72 #define DOWN 80 // 8~11번째 줄 키보드 방향키 아스키코드값 #define DanceBoard_X 39 // Dance 가로크기 #define DanceBoard_Y 4 // Dance 세로크기 #define Void 0 // 빈 부분 #define True 1 #define False 0 #define Fail 200 // 실패 플래그 값 int DanceBlocks[4][4][4] = { //위방향 화살표 { 0,UP,0,0, UP,DOWN,UP,0, 0,1,0,0, 0,1,0,0 }, //아래방향 화살표 { 0,1,0,0, 0,1,0,0, DOWN,UP,DOWN,0, 0,DOWN,0,0 }, //왼쪽방향 화살표 { 0,LEFT,0,0, LEFT,RIGHT,1,1, 0,LEFT,0,0, 0,0,0,0 }, //오른쪽방향 화살표 { 0,0,RIGHT,0, 1,1,LEFT,RIGHT, 0,0,RIGHT,0, 0,0,0,0 } }; //리듬게임 블럭 모양 저장 int DanceBoard[DanceBoard_Y + 1][DanceBoard_X + 1] = { 0, }; // 리듬게임 보드 저장 int DanceBoardCpy[DanceBoard_Y + 1][DanceBoard_X + 1]; // 리듬게임 보드 저장 카피 int DanceSave[8] = { 0, }; // 리듬게임 블럭 저장 int DanceType; // 화살표 저장 int keyinput; // 키 입력 받기 int Dance_X, Dance_Y; // 리듬게임 위치 저장 int DanceSuccess = 0; // 리듬게임 라운드 int DanceSuccessFlag = True; // 리듬게임 성공 플래그 int DanceFail; // 리듬게임 실패 int DanceGet = 0; // 리듬게임 성고 double DanceTime = 60; // 리듬게임 시간 int ColorOption = 15; // 컬러 저장 void Consolecolor( int color); // 콘솔 색깔 변경 void removeCursor( void ); // 커서 지우기 void Reset_DanceBoardCpy( void ); // DanceBoardCpy 초기화 void gotoxy( int x, int y); // 좌표 설정 void DanceOutput( void ); // 리듬게임 출력 int DanceTimer( void ); // 리듬게임 시간 계산 void DanceMap( void ); // 리듬게임 맵 생성 void DanceDrow( void ); // 리듬게임 블럭 그리기 int DanceRound( void ); // 리듬게임 라운드 void DanceBreak( int Keyinput, int num); // 리듬게임 블럭 파괴 void DanceKeyinput( void ); // 리듬게임 키 입력 받기 void DanceEnd( void ); // 리듬게임 종료 int main( void ) { keyinput = 0; srand ( time (NULL)); removeCursor(); system ( "cls" ); Reset_DanceBoardCpy(); DanceMap(); while (1) { DanceTimer(); if (DanceTimer() == Fail) break ; if (DanceSuccessFlag == True) { Reset_DanceBoardCpy(); DanceOutput(); } DanceKeyinput(); DanceDrow(); if (DanceSuccess == 20) break ; } DanceEnd(); } // 메인 함수 void Consolecolor( int color) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); } void removeCursor( void ) { CONSOLE_CURSOR_INFO curInfo; GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curInfo); curInfo.bVisible = 0; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curInfo); } void gotoxy( int x, int y) { COORD pos = { 2 * x,y }; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } void DanceOutput( void ) { int i, j, k; Dance_X = 1; Dance_Y = 4; for (k = 0; k < DanceRound(); k++) { DanceType = rand () % 4; switch (DanceType) { case 0: DanceSave[k] = UP; break ; case 1: DanceSave[k] = DOWN; break ; case 2: DanceSave[k] = LEFT; break ; case 3: DanceSave[k] = RIGHT; break ; } for (i = 0; i <= 3; i++) { for (j = 0; j <= 3; j++) { if (DanceBlocks[DanceType][i][j] >= 1) { DanceBoard[i][j + (5 * k)] = DanceBlocks[DanceType][i][j]; } } } } DanceSuccessFlag = False; } int DanceTimer( void ) { DanceTime = DanceTime - 0.01; Sleep(10); if (DanceTime > 0) { gotoxy(19, 0); printf ( "%.2lf초" , DanceTime); } else if (DanceTime <= 0) { gotoxy(19, 0); printf ( "0.00초" ); } if (DanceTime <= 0) return Fail; } void DanceMap( void ) { gotoxy(15, 0); puts ( "시간 : " ); gotoxy(33, 0); puts ( "성공횟수 :" ); Consolecolor(15); gotoxy(0, 13); printf ( " ■■■■■■" ); gotoxy(0, 14); printf ( " ■■■■■■■" ); gotoxy(0, 15); printf ( " ● ■■■■■■■■" ); Consolecolor(4); gotoxy(0, 16); printf ( " ■ ■■■■■■■" ); gotoxy(0, 17); printf ( " ■ ■ ■■■" ); gotoxy(0, 18); printf ( " ■ ■ ■■■" ); gotoxy(0, 19); printf ( " ■" ); Consolecolor(15); gotoxy(18, 19); printf ( "●" ); Consolecolor(4); gotoxy(33, 19); printf ( "■ ■■■" ); gotoxy(0, 20); printf ( " ■" ); Consolecolor(15); gotoxy(2, 20); printf ( "┼──┼─┼─┼──┼──┼─┼▲─┼─┼─┼─┼──┼─┼┤" ); Consolecolor(4); gotoxy(33, 20); printf ( "■ ■■■" ); Consolecolor(10); gotoxy(0, 21); printf ( "■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■" ); Consolecolor(6); gotoxy(0, 22); printf ( "■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■" ); gotoxy(0, 23); printf ( "■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■" ); gotoxy(0, 24); printf ( "■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■" ); Consolecolor(ColorOption); } void DanceDrow( void ) { int i, j; for (i = 0; i <= DanceBoard_X; i++) { for (j = 0; j <= DanceBoard_Y; j++) { if (DanceBoard[j][i] != DanceBoardCpy[j][i]) { gotoxy(Dance_X + i, Dance_Y + j); switch (DanceBoard[j][i]) { case UP: printf ( "▲" ); break ; case DOWN: printf ( "▼" ); break ; case LEFT: printf ( "◀" ); break ; case RIGHT: printf ( "▶" ); break ; case 1: printf ( "■" ); break ; case Void: printf ( " " ); break ; } } } } gotoxy(38, 0); printf ( "%2d" , DanceSuccess); for (i = 0; i <= DanceBoard_X; i++) { for (j = 0; j <= DanceBoard_Y; j++) { DanceBoardCpy[j][i] = DanceBoard[j][i]; } } } void Reset_DanceBoardCpy( void ) { int i, j; for (i = 0; i <= DanceBoard_Y; i++) { for (j = 0; j <= DanceBoard_X; j++) { DanceBoardCpy[i][j] = 100; } } } int DanceRound( void ) { if (0 <= DanceSuccess&&DanceSuccess < 5) { return 4; } else if (5 <= DanceSuccess&&DanceSuccess < 10) { return 6; } else if (10 <= DanceSuccess&&DanceSuccess < 15) { return 7; } else if (15 <= DanceSuccess&&DanceSuccess < 20) { return 8; } } void DanceBreak( int Keyinput, int num) { int i, j, k; if (Keyinput == True) { for (i = 0; i <= 3; i++) { for (j = 0; j <= 3; j++) { if (DanceBoard[i][j + (5 * num)] >= 1) DanceBoard[i][j + (5 * num)] = Void; } } DanceGet += 1; } if (Keyinput == False) { for (k = 0; k < DanceRound(); k++) { switch (DanceSave[k]) { case UP: for (i = 0; i <= 3; i++) { for (j = 0; j <= 3; j++) { DanceBoard[i][j + (5 * k)] = DanceBlocks[0][i][j]; } } for (i = 0; i <= 3; i++) { for (j = 0; j <= 3; j++) { if (DanceBlocks[0][i][j] >= 1) DanceBoard[i][j + (5 * k)] = DanceBlocks[0][i][j]; } } break ; case DOWN: for (i = 0; i <= 3; i++) { for (j = 0; j <= 3; j++) { if (DanceBlocks[1][i][j] >= 1) DanceBoard[i][j + (5 * k)] = DanceBlocks[1][i][j]; } } break ; case LEFT: for (i = 0; i <= 3; i++) { for (j = 0; j <= 3; j++) { if (DanceBlocks[2][i][j] >= 1) DanceBoard[i][j + (5 * k)] = DanceBlocks[2][i][j]; } } break ; case RIGHT: for (i = 0; i <= 3; i++) { for (j = 0; j <= 3; j++) { if (DanceBlocks[3][i][j] >= 1) DanceBoard[i][j + (5 * k)] = DanceBlocks[3][i][j]; } } break ; } } DanceGet = 0; } } void DanceKeyinput( void ) { keyinput = 0; if (kbhit()) { keyinput = getch(); switch (keyinput) { case UP: if (DanceSave[DanceGet] == UP) { DanceBreak(True, DanceGet); } else if (DanceSave[DanceGet] != UP) { DanceBreak(False, DanceGet); } break ; case DOWN: if (DanceSave[DanceGet] == DOWN) { DanceBreak(True, DanceGet); } else if (DanceSave[DanceGet] != DOWN) { DanceBreak(False, DanceGet); } break ; case LEFT: if (DanceSave[DanceGet] == LEFT) { DanceBreak(True, DanceGet); } else if (DanceSave[DanceGet] != LEFT) { DanceBreak(False, DanceGet); } break ; case RIGHT: if (DanceSave[DanceGet] == RIGHT) { DanceBreak(True, DanceGet); } else if (DanceSave[DanceGet] != RIGHT) { DanceBreak(False, DanceGet); } break ; } } if (DanceGet == DanceRound()) { ++DanceSuccess; DanceGet = 0; DanceSuccessFlag = True; } } void DanceEnd( void ) { if (DanceTime <= 0) { for ( int a = 3; a < 10; a++) { gotoxy(0, a); puts ( " " ); } gotoxy(4, 3); puts ( "■■■■■ ■ ■■■■■ ■" ); gotoxy(4, 4); puts ( "■ ■■ ■ ■" ); gotoxy(4, 5); puts ( "■ ■ ■ ■ ■" ); gotoxy(4, 6); puts ( "■■■■■ ■■■■ ■ ■" ); gotoxy(4, 7); puts ( "■ ■ ■ ■ ■" ); gotoxy(4, 8); puts ( "■ ■ ■ ■ ■" ); gotoxy(4, 9); puts ( "■ ■ ■ ■■■■■ ■■■■■" ); for ( int b = 0; b < 3; b++) { Sleep(1000); gotoxy(28 + (2 * b), 9); printf ( "●" ); } } if (DanceTime > 0) { for ( int a = 3; a < 10; a++) { gotoxy(0, a); puts ( " " ); } gotoxy(4, 3); puts ( " ■■■ ■ ■■■■■ ■ ■■■■ ■ ■" ); gotoxy(4, 4); puts ( "■ ■ ■ ■ ■■ ■ ■ ■ ■" ); gotoxy(4, 5); puts ( "■ ■ ■ ■ ■ ■ ■ ■ ■" ); gotoxy(4, 6); puts ( "■ ■ ■■■■■ ■■■■ ■■■■ ■ ■" ); gotoxy(4, 7); puts ( "■ ■ ■ ■ ■ ■ ■ ■ ■" ); gotoxy(4, 8); puts ( "■ ■ ■ ■ ■ ■ ■ ■ " ); gotoxy(4, 9); puts ( " ■■■ ■■■■■ ■■■■■ ■ ■ ■ ■ ● ●" ); } Sleep(3000); } |
수정사항,오류지적 감사합니다.
'프로그래밍 > C' 카테고리의 다른 글
[C][알고리즘] 선택 정렬(Selection Sort) (0) | 2019.04.12 |
---|