#include<stdio.h>
#include<Windows.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
int page;
int con;
int line;
int g_level;
int g_nextlevels;
int g_score;
int g_beforescore;
int g_combo = 0;
int g_speed = 150;
int g_speed_r[7] = { 150,70,120, 50, 100, 90, 80 };
int g_rsp[3][5][5] = { { { 1, 95, 95, 95, 4 },
{ 124, 64, 32, 64, 124 },
{ 124, 64, 32, 64, 124 },
{ 124, 32, 64, 32, 124 },
{ 2, 95, 95, 95, 3 } },
{ { 1, 95, 95, 95, 4 },
{ 124, 32, 32, 32, 124 },
{ 124, 64, 64, 64, 124 },
{ 124, 64, 64, 64, 124 },
{ 2, 95, 95, 95, 3 } },
{ { 1, 95, 95, 95, 4 },
{ 124, 64, 64, 64, 124 },
{ 124, 64, 64, 64, 124 },
{ 124, 64, 64, 64, 124 },
{ 2, 95, 95, 95, 3 } } };
int g_rspcon;
int g_rspline;
int g_nextblock[7];
int g_life = 5;
int gm_put;
int g_y;
int gm_y;
int rspshape = -1;
int main_i;
int lastscore=0;
int rule();
int startpage();
int game();
int score(g_level);
int sideboard();
int makeblock();
int drop();
int rhythmbox();
int scankey();
int combo();
int gameover();
int win();
int reset();
int levelup();
int levelscore();
int levelscore() {
if (g_level == 1 && gm_put - 1 == rspshape && gm_y >= 20) {
g_score += 10;
g_speed -= 5;
}
else if (g_level == 2 && gm_y > 20) {
if (rspshape == 0 && gm_put == 2) {
g_score += 10;
g_speed -= 4;
}
else if (rspshape == 1 && gm_put == 3) {
g_score += 10;
g_speed -= 4;
}
else if (rspshape == 2 && gm_put == 1) {
g_score += 10;
g_speed -= 4;
}
}
else if (g_level == 3 && gm_y > 20) {
if (rspshape == 0 && gm_put == 3) {
g_score += 10;
g_speed -= 4;
}
else if (rspshape == 1 && gm_put == 1) {
g_score += 10;
g_speed -= 4;
}
else if (rspshape == 2 && gm_put == 2) {
g_score += 10;
g_speed -= 4;
}
}
else if (g_level == 4 && gm_y > 20) {
if (rspshape == 0 && gm_put == 2) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
else if (rspshape == 1 && gm_put == 3) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
else if (rspshape == 2 && gm_put == 1) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
}
else if (g_level == 5 && gm_y > 20) {
if (rspshape == 0 && gm_put == 3) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
else if (rspshape == 1 && gm_put == 1) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
else if (rspshape == 2 && gm_put == 2) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
}
}
int levelup() {
if (g_score >= 50 && g_score <= 60) {
g_level = 2;
score();
g_speed = 120;
}
else if (g_score >= 100 && g_score <= 110) {
g_level = 3;
score();
g_speed = 100;
}
else if (g_score >= 170 && g_score <= 180) {
g_level = 4;
score();
g_speed = 100;
}
else if (g_score >= 230 && g_score <= 240) {
g_level = 5;
score();
g_speed = 100;
}
}
int reset() {
g_level = 1;
g_score = 0;
g_combo = 0;
g_life = 5;
}
int gameover() {
int x = 7, y = 13;
system("cls");
gotoxy(x, y); printf(" ┌─────────┐");
gotoxy(x, y + 1); printf(" │ G A M E O V E R !│");
gotoxy(x, y + 2); printf(" └─────────┘");
gotoxy(x, y + 3); printf(" 재시작_a ");
gotoxy(x, y + 4); printf("종료하려면 d를 2번 누르세요");
gotoxy(x, y + 10);
reset();
return 0;
}
int win() {
int x = 7, y = 13;
system("cls");
gotoxy(x, y); printf(" ┌─────────┐");
gotoxy(x, y + 1); printf(" │ Y O U W I N ! │");
gotoxy(x, y + 2); printf(" └─────────┘");
gotoxy(x, y + 3); printf(" 재시작_a ");
gotoxy(x, y + 4); printf("종료하려면 d를 2번 누르세요");
reset();
return 0;
}
int combo() {
if (g_beforescore + 10 == g_score) {
++g_combo;
g_score = g_score + 2;
}
else if (g_beforescore == g_score && g_score == 0) {
g_combo = 0;
g_score = 0;
--g_life;
}
else if (g_beforescore == g_score) {
g_combo = 0;
g_speed += 10;
g_score = g_score - 10;
--g_life;
}
}
int scankey() {
gm_put = getch();
if (gm_put == 'a') {
gm_put = 1;
}
else if (gm_put == 's') {
gm_put = 2;
}
else if (gm_put == 'd') {
gm_put = 3;
}
gm_y = g_y;
}
int rhythmbox() {
for (int i = 0; i < 20; ++i) {
gotoxy(i, 21); printf("=");
gotoxy(i, 27); printf("=");
}
}
int startpage() {
system("cls");
printf("\n\n\n\n\n");
printf(" ▦▦▦ ▦ ▦ ▦ \n");
printf(" ▦ ▦ ▦ ▦ ▦ ▦▦▦ ▦ ▦▦ ▦▦\n");
printf(" ▦▦ ▦▦▦ ▦▦▦ ▦ ▦▦▦ ▦ ▦ ▦\n");
printf(" ▦ ▦ ▦ ▦ ▦ ▦▦ ▦ ▦ ▦ ▦ ▦\n");
printf(" ▦▦\n\n\n");
printf(" ▦▦ ▦▦ ▦▦▦▦▦\n");
printf(" ▦▦ ▦▦ ▦ | | ▦\n");
printf(" ▦▦ ▦▦ ▦▦▦▦▦ ▦ | | ▦\n");
printf(" ▦▦▦▦▦▦ ▦ ▦ ▦ ▦ | | ▦\n");
printf(" ▦ ▦ ▦▦▦ ▦ ▦ ▦ ▦\n");
printf(" ▦▦▦ ▦ ▦ ▦ ▦▦ ▦\n");
printf(" ▦ ▦ ▦▦▦▦▦▦ ▦ ▦\n");
printf(" ▦▦▦▦▦▦ ▦▦▦▦▦\n\n\n\n");
printf(" 게임방법 : a 게임시작 : s\n");
reset();
char start = getch();
system("cls");
if (start == 'a') {
return 97;
}
}
int rule() {
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n");
printf(" ┌────────────────────────┐\n");
printf(" │ <게임방법> │\n");
printf(" │ │\n");
printf(" │ ≫조작법 : 가위 _ a │\n");
printf(" │ 바위 _ s │\n");
printf(" │ 보 _ d 로 조작합니다. │\n");
printf(" │ ≫내려오는 가위, 바위, 보를 밑에 칸에 내려오는 │\n");
printf(" │ 타이밍에 맞추어 알맞은 키를 누릅니다. │\n");
printf(" │ │\n");
printf(" │ 돌아가기 _ d 게임시작 _ s │\n");
printf(" └────────────────────────┘\n");
char d = getch();
if (d == 'd') {
return startpage();
}
}
int score() {
int x = 7, y = 12;
switch (g_level)
{
case 1: {
gotoxy(x, y); printf("┌──────────────┐");
gotoxy(x, y + 1); printf("│ ROUND1 │\n");
gotoxy(x, y + 2); printf("│ 비 겨 라 │\n");
gotoxy(x, y + 3); printf("└──────────────┘\n");
Sleep(2000);
system("cls");
rhythmbox();
sideboard();
break;
}
case 2: {
gotoxy(x, y); printf("┌──────────────┐\n");
gotoxy(x, y + 1); printf("│ ROUND2 │\n");
gotoxy(x, y + 2); printf("│ 이 겨 라 │\n");
gotoxy(x, y + 3); printf("└──────────────┘\n");
Sleep(2000);
system("cls");
rhythmbox();
sideboard();
break;
}
case 3: {
gotoxy(x, y); printf("┌──────────────┐\n");
gotoxy(x, y + 1); printf("│ ROUND3 │\n");
gotoxy(x, y + 2); printf("│ 져 라 │\n");
gotoxy(x, y + 3); printf("└──────────────┘\n");
Sleep(2000);
system("cls");
rhythmbox();
sideboard();
break;
}case 4: {
gotoxy(x, y); printf("┌──────────────┐\n");
gotoxy(x, y + 1); printf("│ ROUND4 │\n");
gotoxy(x, y + 2); printf("│ 이 겨 라 │\n");
gotoxy(x, y + 3); printf("└──────────────┘\n");
Sleep(2000);
system("cls");
rhythmbox();
sideboard();
break;
}case 5: {
gotoxy(x, y); printf("┌──────────────┐\n");
gotoxy(x, y + 1); printf("│ ROUND5 │\n");
gotoxy(x, y + 2); printf("│ 져 라 │\n");
gotoxy(x, y + 3); printf("└──────────────┘\n");
Sleep(2000);
system("cls");
rhythmbox();
sideboard();
break;
}
}
}
int gotoxy(int x, int y) {
COORD pos = { 2 * x,y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void CursorView(char show)
{
HANDLE hConsole;
CONSOLE_CURSOR_INFO ConsoleCursor;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
ConsoleCursor.bVisible = show;
ConsoleCursor.dwSize = 1;
SetConsoleCursorInfo(hConsole, &ConsoleCursor);
}
int sideboard() {
int x = 9;
int y = 3;
con = 30;
line = 28;
system("cls");
gotoxy(con - x + 1, line - y - 4);
for (int i = 0; i < g_life; ++i) {
printf("♥ ");
}
gotoxy(con - x, line - y - 3); printf("┌───────┐");
gotoxy(con - x, line - y - 2); printf("│LEVEL : %6d│", g_level);
gotoxy(con - x, line - y - 1); printf("│SCORE : %6d│", g_score);
gotoxy(con - x, line - y); printf("│COMBO : %6d│", g_combo);
gotoxy(con - x, line - y + 1); printf("└───────┘");
gotoxy(con - x, line - y+2); printf("best score : %4d", lastscore);
}
int makeblock(g_rspcon, g_rspline) {
switch (g_rsp[rspshape][g_rspline][g_rspcon]) {
case 1:
printf("┌"); break;
case 2:
printf("└"); break;
case 3:
printf("┘"); break;
case 4:
printf("┐"); break;
case 95:
printf("─"); break;
case 124:
printf("│"); break;
case 32:
printf(" "); break;
case 64:
printf("▦"); break;
}
}
int drop()
{
int x = 15;
rspshape = rand() % 3;
gm_put = 0;
sideboard();
for (g_y = 0; g_y < 22; ++g_y) {
for (int i = -1; i < 5; ++i) {
for (x = 8; x < 13; ++x) {
gotoxy(x, g_y + i);
if (i == -1) {
printf(" ");
}
else {
makeblock(x - 8, i);
}
}
}
rhythmbox();
if (kbhit()) scankey();
Sleep(g_speed);
}
levelscore();
combo();
g_beforescore = g_score;
}
int main() {
int startpage(void);
int rule(void);
reset();
CursorView(0);
system("mode con cols=60 lines=28");
srand((unsigned)time(NULL));
page = startpage();
while (1) {
if (page == 97) {
page = rule();
}
else if (page == 115) {
main_i = 0;
g_level = 1;
score();
while (main_i<100000) {
levelup();
drop();
sideboard();
if (g_speed <= 70) {
g_speed = 70;
}
if (g_score < 0 || g_life == 0) {
if (lastscore < g_score) {
lastscore = g_score;
}
reset();
gameover();
if (getch() == 'a') continue;
else if (getch() == 'd') return 0;
}
if (g_score > 800) {
lastscore = g_score;
reset();
win();
if (getch() == 'a') continue;
else if (getch() == 'd') return 0;
}
}
}
else {
break;
}
}
}