Skip to content

gunh0/PlayTetrisByC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 

Repository files navigation

PlayTetrisByC

Environment

  • Windows
  • Microsoft Visual Studio

Screenshot

Best Score by https://github.com/melli0505 (2019.10.28)


Code Detail

#define _CRT_NONSTDC_NO_WARNINGS    // ๋น„ํ‘œ์ค€ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ ์—๋Ÿฌ ๋ฐฉ์ง€
#define _CRT_SECURE_NO_WARNINGS     // scanf ๋ณด์•ˆ ๊ฒฝ๊ณ ๋กœ ์ธํ•œ ์ปดํŒŒ์ผ ์—๋Ÿฌ ๋ฐฉ์ง€
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>

#define LEFT 75 //์ขŒ๋กœ ์ด๋™    //ํ‚ค๋ณด๋“œ๊ฐ’๋“ค 
#define RIGHT 77 //์šฐ๋กœ ์ด๋™ 
#define UP 72 //ํšŒ์ „ 
#define DOWN 80 //soft drop
#define SPACE 32 //hard drop
#define p 112 //์ผ์‹œ์ •์ง€ 
#define P 80 //์ผ์‹œ์ •์ง€
#define ESC 27 //๊ฒŒ์ž„์ข…๋ฃŒ 

#define false 0
#define true 1

#define ACTIVE_BLOCK -2 // ๊ฒŒ์ž„ํŒ๋ฐฐ์—ด์— ์ €์žฅ๋  ๋ธ”๋ก์˜ ์ƒํƒœ๋“ค 
#define CEILLING -1     // ๋ธ”๋ก์ด ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„์€ 0 ๋˜๋Š” ์Œ์˜ ์ •์ˆ˜๋ฃŒ ํ‘œํ˜„ 
#define EMPTY 0         // ๋ธ”๋ก์ด ์ด๋™ํ•  ์ˆ˜ ์—†๋Š” ๊ณต๊ฐ„์€ ์–‘์ˆ˜๋กœ ํ‘œํ˜„ 
#define WALL 1
#define INACTIVE_BLOCK 2 // ์ด๋™์ด ์™„๋ฃŒ๋œ ๋ธ”๋ก๊ฐ’ 

#define MAIN_X 11 //๊ฒŒ์ž„ํŒ ๊ฐ€๋กœํฌ๊ธฐ 
#define MAIN_Y 23 //๊ฒŒ์ž„ํŒ ์„ธ๋กœํฌ๊ธฐ 
#define MAIN_X_ADJ 3 //๊ฒŒ์ž„ํŒ ์œ„์น˜์กฐ์ • 
#define MAIN_Y_ADJ 1 //๊ฒŒ์ž„ํŒ ์œ„์น˜์กฐ์ • 

#define STATUS_X_ADJ MAIN_X_ADJ+MAIN_X+1 //๊ฒŒ์ž„์ •๋ณดํ‘œ์‹œ ์œ„์น˜์กฐ์ • 

int STATUS_Y_GOAL; //GOAL ์ •๋ณดํ‘œ์‹œ์œ„์น˜Y ์ขŒํ‘œ ์ €์žฅ 
int STATUS_Y_LEVEL; //LEVEL ์ •๋ณดํ‘œ์‹œ์œ„์น˜Y ์ขŒํ‘œ ์ €์žฅ
int STATUS_Y_SCORE; //SCORE ์ •๋ณดํ‘œ์‹œ์œ„์น˜Y ์ขŒํ‘œ ์ €์žฅ

int blocks[7][4][4][4] = {
	{ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0 } },
	{ { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 } },
	{ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0 },
	{ 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0 } },
	{ { 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0 },
	{ 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0 } },
	{ { 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0 } },
	{ { 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0 } },
	{ { 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0 } }
}; //๋ธ”๋ก๋ชจ์–‘ ์ €์žฅ 4*4๊ณต๊ฐ„์— ๋ธ”๋ก์„ ํ‘œํ˜„ blcoks[b_type][b_rotation][i][j]๋กœ ์‚ฌ์šฉ 

int b_type; //๋ธ”๋ก ์ข…๋ฅ˜๋ฅผ ์ €์žฅ 
int b_rotation; //๋ธ”๋ก ํšŒ์ „๊ฐ’ ์ €์žฅ 
int b_type_next; //๋‹ค์Œ ๋ธ”๋ก๊ฐ’ ์ €์žฅ 

int main_org[MAIN_Y][MAIN_X]; //๊ฒŒ์ž„ํŒ์˜ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฐ์—ด ๋ชจ๋‹ˆํ„ฐ์— ํ‘œ์‹œํ›„์— main_cpy๋กœ ๋ณต์‚ฌ๋จ 
int main_cpy[MAIN_Y][MAIN_X]; //์ฆ‰ maincpy๋Š” ๊ฒŒ์ž„ํŒ์ด ๋ชจ๋‹ˆํ„ฐ์— ํ‘œ์‹œ๋˜๊ธฐ ์ „์˜ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ 
//main์˜ ์ „์ฒด๋ฅผ ๊ณ„์† ๋ชจ๋‹ˆํ„ฐ์— ํ‘œ์‹œํ•˜์ง€ ์•Š๊ณ (์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋ชจ๋‹ˆํ„ฐ๊ฐ€ ๊นœ๋นก๊ฑฐ๋ฆผ) 
//main_cpy์™€ ๋ฐฐ์—ด์„ ๋น„๊ตํ•ด์„œ ๊ฐ’์ด ๋‹ฌ๋ผ์ง„ ๊ณณ๋งŒ ๋ชจ๋‹ˆํ„ฐ์— ๊ณ ์นจ 
int bx, by; //์ด๋™์ค‘์ธ ๋ธ”๋ก์˜ ๊ฒŒ์ž„ํŒ์ƒ์˜ x,y์ขŒํ‘œ๋ฅผ ์ €์žฅ 

int key; //ํ‚ค๋ณด๋“œ๋กœ ์ž…๋ ฅ๋ฐ›์€ ํ‚ค๊ฐ’์„ ์ €์žฅ 

int speed; //๊ฒŒ์ž„์ง„ํ–‰์†๋„ 
int level; //ํ˜„์žฌ level 
int level_goal; //๋‹ค์Œ๋ ˆ๋ฒจ๋กœ ๋„˜์–ด๊ฐ€๊ธฐ ์œ„ํ•œ ๋ชฉํ‘œ์ ์ˆ˜ 
int cnt; //ํ˜„์žฌ ๋ ˆ๋ฒจ์—์„œ ์ œ๊ฑฐํ•œ ์ค„ ์ˆ˜๋ฅผ ์ €์žฅ 
int score; //ํ˜„์žฌ ์ ์ˆ˜ 
int last_score = 0; //๋งˆ์ง€๋ง‰๊ฒŒ์ž„์ ์ˆ˜ 
int best_score = 0; //์ตœ๊ณ ๊ฒŒ์ž„์ ์ˆ˜ 

int new_block_on = 0; //์ƒˆ๋กœ์šด ๋ธ”๋Ÿญ์ด ํ•„์š”ํ•จ์„ ์•Œ๋ฆฌ๋Š” flag 
int crush_on = 0; //ํ˜„์žฌ ์ด๋™์ค‘์ธ ๋ธ”๋ก์ด ์ถฉ๋Œ์ƒํƒœ์ธ์ง€ ์•Œ๋ ค์ฃผ๋Š” flag 
int level_up_on = 0; //๋‹ค์Œ๋ ˆ๋ฒจ๋กœ ์ง„ํ–‰(ํ˜„์žฌ ๋ ˆ๋ฒจ๋ชฉํ‘œ๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Œ์„) ์•Œ๋ฆฌ๋Š” flag 
int space_key_on = 0; //hard drop์ƒํƒœ์ž„์„ ์•Œ๋ ค์ฃผ๋Š” flag 

void title(void); //๊ฒŒ์ž„์‹œ์ž‘ํ™”๋ฉด 
void reset(void); //๊ฒŒ์ž„ํŒ ์ดˆ๊ธฐํ™” 
void reset_main(void); //๋ฉ”์ธ ๊ฒŒ์ž„ํŒ(main_org[][]๋ฅผ ์ดˆ๊ธฐํ™”)
void reset_main_cpy(void); //copy ๊ฒŒ์ž„ํŒ(main_cpy[][]๋ฅผ ์ดˆ๊ธฐํ™”)
void draw_map(void); //๊ฒŒ์ž„ ์ „์ฒด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ‘œ์‹œ 
void draw_main(void); //๊ฒŒ์ž„ํŒ์„ ๊ทธ๋ฆผ 
void new_block(void); //์ƒˆ๋กœ์šด ๋ธ”๋ก์„ ํ•˜๋‚˜ ๋งŒ๋“ฆ 
void check_key(void); //ํ‚ค๋ณด๋“œ๋กœ ํ‚ค๋ฅผ ์ž…๋ ฅ๋ฐ›์Œ 
void drop_block(void); //๋ธ”๋ก์„ ์•„๋ž˜๋กœ ๋–จ์–ดํŠธ๋ฆผ 
int check_crush(int bx, int by, int rotation); //bx, by์œ„์น˜์— rotationํšŒ์ „๊ฐ’์„ ๊ฐ™๋Š” ๊ฒฝ์šฐ ์ถฉ๋Œ ํŒ๋‹จ 
void move_block(int dir); //dir๋ฐฉํ–ฅ์œผ๋กœ ๋ธ”๋ก์„ ์›€์ง์ž„ 
void check_line(void); //์ค„์ด ๊ฐ€๋“์ฐผ๋Š”์ง€๋ฅผ ํŒ๋‹จํ•˜๊ณ  ์ง€์›€ 
void check_level_up(void); //๋ ˆ๋ฒจ๋ชฉํ‘œ๊ฐ€ ๋‹ฌ์„ฑ๋˜์—ˆ๋Š”์ง€๋ฅผ ํŒ๋‹จํ•˜๊ณ  levelup์‹œํ‚ด 
void check_game_over(void); //๊ฒŒ์ž„์˜ค๋ฒ„์ธ์ง€ ํŒ๋‹จํ•˜๊ณ  ๊ฒŒ์ž„์˜ค๋ฒ„๋ฅผ ์ง„ํ–‰ 
void pause(void);//๊ฒŒ์ž„์„ ์ผ์‹œ์ •์ง€์‹œํ‚ด 

void gotoxy(int x, int y) { //gotoxyํ•จ์ˆ˜ 
	COORD pos = { 2 * x, y };
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

typedef enum { NOCURSOR, SOLIDCURSOR, NORMALCURSOR } CURSOR_TYPE; //์ปค์„œ์ˆจ๊ธฐ๋Š” ํ•จ์ˆ˜์— ์‚ฌ์šฉ๋˜๋Š” ์—ด๊ฑฐํ˜• 
void setcursortype(CURSOR_TYPE c) { //์ปค์„œ์ˆจ๊ธฐ๋Š” ํ•จ์ˆ˜ 
	CONSOLE_CURSOR_INFO CurInfo;

	switch (c) {
	case NOCURSOR:
		CurInfo.dwSize = 1;
		CurInfo.bVisible = FALSE;
		break;
	case SOLIDCURSOR:
		CurInfo.dwSize = 100;
		CurInfo.bVisible = TRUE;
		break;
	case NORMALCURSOR:
		CurInfo.dwSize = 20;
		CurInfo.bVisible = TRUE;
		break;
	}
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &CurInfo);
}

int main() {
	int i;

	srand((unsigned)time(NULL)); //๋‚œ์ˆ˜ํ‘œ์ƒ์„ฑ 
	setcursortype(NOCURSOR); //์ปค์„œ ์—†์•ฐ 
	title(); //๋ฉ”์ธํƒ€์ดํ‹€ ํ˜ธ์ถœ 
	reset(); //๊ฒŒ์ž„ํŒ ๋ฆฌ์…‹ 

	while (1) {
		for (i = 0; i < 5; i++) { //๋ธ”๋ก์ด ํ•œ์นธ๋–จ์–ด์ง€๋Š”๋™์•ˆ 5๋ฒˆ ํ‚ค์ž…๋ ฅ๋ฐ›์„ ์ˆ˜ ์žˆ์Œ 
			check_key(); //ํ‚ค์ž…๋ ฅํ™•์ธ 
			draw_main(); //ํ™”๋ฉด์„ ๊ทธ๋ฆผ 
			Sleep(speed); //๊ฒŒ์ž„์†๋„์กฐ์ ˆ 
			if (crush_on && check_crush(bx, by + 1, b_rotation) == false) Sleep(100);
			//๋ธ”๋ก์ด ์ถฉ๋Œ์ค‘์ธ๊ฒฝ์šฐ ์ถ”๊ฐ€๋กœ ์ด๋™๋ฐ ํšŒ์ „ํ•  ์‹œ๊ฐ„์„ ๊ฐ–์Œ 
			if (space_key_on == 1) { //์ŠคํŽ˜์ด์Šค๋ฐ”๋ฅผ ๋ˆ„๋ฅธ๊ฒฝ์šฐ(hard drop) ์ถ”๊ฐ€๋กœ ์ด๋™๋ฐ ํšŒ์ „ํ• ์ˆ˜ ์—†์Œ break; 
				space_key_on = 0;
				break;
			}
		}
		drop_block(); // ๋ธ”๋ก์„ ํ•œ์นธ ๋‚ด๋ฆผ 
		check_level_up(); // ๋ ˆ๋ฒจ์—…์„ ์ฒดํฌ 
		check_game_over(); //๊ฒŒ์ž„์˜ค๋ฒ„๋ฅผ ์ฒดํฌ 
		if (new_block_on == 1) new_block(); // ๋‰ด ๋ธ”๋Ÿญ flag๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ์ƒˆ๋กœ์šด ๋ธ”๋Ÿญ ์ƒ์„ฑ 
	}
}

void title(void) {
	int x = 5; //ํƒ€์ดํ‹€ํ™”๋ฉด์ด ํ‘œ์‹œ๋˜๋Š” x์ขŒํ‘œ 
	int y = 4; //ํƒ€์ดํ‹€ํ™”๋ฉด์ด ํ‘œ์‹œ๋˜๋Š” y์ขŒํ‘œ 
	int cnt; //ํƒ€์ดํ‹€ ํ”„๋ ˆ์ž„์„ ์„ธ๋Š” ๋ณ€์ˆ˜  

	gotoxy(x, y + 0); printf("โ– โ–กโ–กโ–กโ– โ– โ– โ–กโ–กโ– โ– โ–กโ–กโ– โ– "); Sleep(100);
	gotoxy(x, y + 1); printf("โ– โ– โ– โ–ก  โ– โ–กโ–ก    โ– โ– โ–กโ–กโ– "); Sleep(100);
	gotoxy(x, y + 2); printf("โ–กโ–กโ–กโ–               โ–กโ–   โ– "); Sleep(100);
	gotoxy(x, y + 3); printf("โ– โ– โ–กโ– โ–   โ–ก  โ–   โ–กโ–กโ– โ–กโ–ก"); Sleep(100);
	gotoxy(x, y + 4); printf("โ– โ–   โ– โ–กโ–กโ–กโ– โ– โ– โ–กโ– โ– โ–กโ–ก"); Sleep(100);
	gotoxy(x, y + 5); printf("       Play Tetris By C"); Sleep(100);
	gotoxy(x + 5, y + 2); printf("T E T R I S"); Sleep(100);
	gotoxy(x, y + 7); printf("Please Enter Any Key to Start..");
	gotoxy(x, y + 9); printf("  โ–ณ   : Shift");
	gotoxy(x, y + 10); printf("โ—  โ–ท : Left / Right");
	gotoxy(x, y + 11); printf("  โ–ฝ   : Soft Drop");
	gotoxy(x, y + 12); printf(" SPACE : Hard Drop");
	gotoxy(x, y + 13); printf("   P   : Pause");
	gotoxy(x, y + 14); printf("  ESC  : Quit");
	gotoxy(x, y + 16); printf("BONUS FOR HARD DROPS / COMBOS");

	for (cnt = 0;; cnt++) { //cnt๋ฅผ 1์”ฉ ์ฆ๊ฐ€์‹œํ‚ค๋ฉด์„œ ๊ณ„์† ๋ฐ˜๋ณต    //ํ•˜๋‚˜๋„ ์•ˆ์ค‘์š”ํ•œ ๋ณ„ ๋ฐ˜์ง์ด๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜ํšจ๊ณผ 
		if (kbhit()) break; //ํ‚ค์ž…๋ ฅ์ด ์žˆ์œผ๋ฉด ๋ฌดํ•œ๋ฃจํ”„ ์ข…๋ฃŒ 
		if (cnt % 200 == 0) { gotoxy(x + 4, y + 1); printf("โ˜…"); }       //cnt๊ฐ€ 200์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์งˆ๋•Œ ๋ณ„์„ ํ‘œ์‹œ 
		if ((cnt % 200 - 100) == 0) { gotoxy(x + 4, y + 1); printf("  "); } //์œ„ ์นด์šดํŠธ์—์„œ 100์นด์šดํŠธ ๊ฐ„๊ฒฉ์œผ๋กœ ๋ณ„์„ ์ง€์›€ 
		if ((cnt % 350) == 0) { gotoxy(x + 13, y + 2); printf("โ˜†"); } //์œ—๋ณ„๊ณผ ๊ฐ™์ง€๋งŒ ์‹œ๊ฐ„์ฐจ๋ฅผ ๋’€์Œ 
		if ((cnt % 350 - 100) == 0) { gotoxy(x + 13, y + 2); printf("  "); }
		Sleep(10); // 00.1์ดˆ ๋”œ๋ ˆ์ด  
	}

	while (kbhit()) getch(); //๋ฒ„ํผ์— ๊ธฐ๋ก๋œ ํ‚ค๊ฐ’์„ ๋ฒ„๋ฆผ 

}

void reset(void) {

	FILE* file = fopen("score.dat", "rt"); // score.datํŒŒ์ผ์„ ์—ฐ๊ฒฐ 
	if (file == 0) { best_score = 0; } //ํŒŒ์ผ์ด ์—†์œผ๋ฉด ๊ฑ ์ตœ๊ณ ์ ์ˆ˜์— 0์„ ๋„ฃ์Œ 
	else {
		fscanf(file, "%d", &best_score); // ํŒŒ์ผ์ด ์—ด๋ฆฌ๋ฉด ์ตœ๊ณ ์ ์ˆ˜๋ฅผ ๋ถˆ๋Ÿฌ์˜ด 
		fclose(file); //ํŒŒ์ผ ๋‹ซ์Œ 
	}

	level = 1; //๊ฐ์ข…๋ณ€์ˆ˜ ์ดˆ๊ธฐํ™” 
	score = 0;
	level_goal = 1000;
	key = 0;
	crush_on = 0;
	cnt = 0;
	speed = 100;

	system("cls"); //ํ™”๋ฉด์ง€์›€ 
	reset_main(); // main_org๋ฅผ ์ดˆ๊ธฐํ™” 
	draw_map(); // ๊ฒŒ์ž„ํ™”๋ฉด์„ ๊ทธ๋ฆผ
	draw_main(); // ๊ฒŒ์ž„ํŒ์„ ๊ทธ๋ฆผ 

	b_type_next = rand() % 7; //๋‹ค์Œ๋ฒˆ์— ๋‚˜์˜ฌ ๋ธ”๋ก ์ข…๋ฅ˜๋ฅผ ๋žœ๋คํ•˜๊ฒŒ ์ƒ์„ฑ 
	new_block(); //์ƒˆ๋กœ์šด ๋ธ”๋ก์„ ํ•˜๋‚˜ ๋งŒ๋“ฆ  

}

void reset_main(void) { //๊ฒŒ์ž„ํŒ์„ ์ดˆ๊ธฐํ™”  
	int i, j;

	for (i = 0; i < MAIN_Y; i++) { // ๊ฒŒ์ž„ํŒ์„ 0์œผ๋กœ ์ดˆ๊ธฐํ™”  
		for (j = 0; j < MAIN_X; j++) {
			main_org[i][j] = 0;
			main_cpy[i][j] = 100;
		}
	}
	for (j = 1; j < MAIN_X; j++) { //y๊ฐ’์ด 3์ธ ์œ„์น˜์— ์ฒœ์žฅ์„ ๋งŒ๋“ฆ 
		main_org[3][j] = CEILLING;
	}
	for (i = 1; i < MAIN_Y - 1; i++) { //์ขŒ์šฐ ๋ฒฝ์„ ๋งŒ๋“ฆ  
		main_org[i][0] = WALL;
		main_org[i][MAIN_X - 1] = WALL;
	}
	for (j = 0; j < MAIN_X; j++) { //๋ฐ”๋‹ฅ๋ฒฝ์„ ๋งŒ๋“ฆ 
		main_org[MAIN_Y - 1][j] = WALL;
	}
}

void reset_main_cpy(void) { //main_cpy๋ฅผ ์ดˆ๊ธฐํ™” 
	int i, j;

	for (i = 0; i < MAIN_Y; i++) {         //๊ฒŒ์ž„ํŒ์— ๊ฒŒ์ž„์— ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ์ˆซ์ž๋ฅผ ๋„ฃ์Œ 
		for (j = 0; j < MAIN_X; j++) {  //์ด๋Š” main_org์™€ ๊ฐ™์€ ์ˆซ์ž๊ฐ€ ์—†๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•จ 
			main_cpy[i][j] = 100;
		}
	}
}

void draw_map(void) { //๊ฒŒ์ž„ ์ƒํƒœ ํ‘œ์‹œ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ํ•จ์ˆ˜  
	int y = 3;             // level, goal, score๋งŒ ๊ฒŒ์ž„์ค‘์— ๊ฐ’์ด ๋ฐ”๋€”์ˆ˜ ๋„ ์žˆ์Œ ๊ทธ y๊ฐ’์„ ๋”ฐ๋กœ ์ €์žฅํ•ด๋‘  
	// ๊ทธ๋ž˜์„œ ํ˜น์‹œ ๊ฒŒ์ž„ ์ƒํƒœ ํ‘œ์‹œ ์œ„์น˜๊ฐ€ ๋ฐ”๋€Œ์–ด๋„ ๊ทธ ํ•จ์ˆ˜์—์„œ ์•ˆ๋ฐ”๊ฟ”๋„ ๋˜๊ฒŒ.. 
	gotoxy(STATUS_X_ADJ, STATUS_Y_LEVEL = y); printf(" LEVEL : %5d", level);
	gotoxy(STATUS_X_ADJ, STATUS_Y_GOAL = y + 1); printf(" GOAL  : %5d", 10 - cnt);
	gotoxy(STATUS_X_ADJ, y + 2); printf("+-  N E X T  -+ ");
	gotoxy(STATUS_X_ADJ, y + 3); printf("|             | ");
	gotoxy(STATUS_X_ADJ, y + 4); printf("|             | ");
	gotoxy(STATUS_X_ADJ, y + 5); printf("|             | ");
	gotoxy(STATUS_X_ADJ, y + 6); printf("|             | ");
	gotoxy(STATUS_X_ADJ, y + 7); printf("+-- -  -  - --+ ");
	gotoxy(STATUS_X_ADJ, y + 8); printf(" YOUR SCORE :");
	gotoxy(STATUS_X_ADJ, STATUS_Y_SCORE = y + 9); printf("        %6d", score);
	gotoxy(STATUS_X_ADJ, y + 10); printf(" LAST SCORE :");
	gotoxy(STATUS_X_ADJ, y + 11); printf("        %6d", last_score);
	gotoxy(STATUS_X_ADJ, y + 12); printf(" BEST SCORE :");
	gotoxy(STATUS_X_ADJ, y + 13); printf("        %6d", best_score);
	gotoxy(STATUS_X_ADJ, y + 15); printf("  โ–ณ   : Shift        SPACE : Hard Drop");
	gotoxy(STATUS_X_ADJ, y + 16); printf("โ—  โ–ท : Left / Right   P   : Pause");
	gotoxy(STATUS_X_ADJ, y + 17); printf("  โ–ฝ   : Soft Drop     ESC  : Quit");
	gotoxy(STATUS_X_ADJ, y + 20); printf("Play Tetris By C");
}

void draw_main(void) { //๊ฒŒ์ž„ํŒ ๊ทธ๋ฆฌ๋Š” ํ•จ์ˆ˜ 
	int i, j;

	for (j = 1; j < MAIN_X - 1; j++) { //์ฒœ์žฅ์€ ๊ณ„์† ์ƒˆ๋กœ์šด๋ธ”๋Ÿญ์ด ์ง€๋‚˜๊ฐ€์„œ ์ง€์›Œ์ง€๋ฉด ์ƒˆ๋กœ ๊ทธ๋ ค์คŒ 
		if (main_org[3][j] == EMPTY) main_org[3][j] = CEILLING;
	}
	for (i = 0; i < MAIN_Y; i++) {
		for (j = 0; j < MAIN_X; j++) {
			if (main_cpy[i][j] != main_org[i][j]) { //cpy๋ž‘ ๋น„๊ตํ•ด์„œ ๊ฐ’์ด ๋‹ฌ๋ผ์ง„ ๋ถ€๋ถ„๋งŒ ์ƒˆ๋กœ ๊ทธ๋ ค์คŒ.
				//์ด๊ฒŒ ์—†์œผ๋ฉด ๊ฒŒ์ž„ํŒ์ „์ฒด๋ฅผ ๊ณ„์† ๊ทธ๋ ค์„œ ๋Š๋ ค์ง€๊ณ  ๋ฐ˜์ง๊ฑฐ๋ฆผ
				gotoxy(MAIN_X_ADJ + j, MAIN_Y_ADJ + i);
				switch (main_org[i][j]) {
				case EMPTY: //๋นˆ์นธ๋ชจ์–‘ 
					printf("  ");
					break;
				case CEILLING: //์ฒœ์žฅ๋ชจ์–‘ 
					printf(". ");
					break;
				case WALL: //๋ฒฝ๋ชจ์–‘ 
					printf("โ–ฉ");
					break;
				case INACTIVE_BLOCK: //๊ตณ์€ ๋ธ”๋Ÿญ ๋ชจ์–‘  
					printf("โ–ก");
					break;
				case ACTIVE_BLOCK: //์›€์ง์ด๊ณ ์žˆ๋Š” ๋ธ”๋Ÿญ ๋ชจ์–‘  
					printf("โ– ");
					break;
				}
			}
		}
	}
	for (i = 0; i < MAIN_Y; i++) { //๊ฒŒ์ž„ํŒ์„ ๊ทธ๋ฆฐ ํ›„ main_cpy์— ๋ณต์‚ฌ  
		for (j = 0; j < MAIN_X; j++) {
			main_cpy[i][j] = main_org[i][j];
		}
	}
}

void new_block(void) { //์ƒˆ๋กœ์šด ๋ธ”๋ก ์ƒ์„ฑ  
	int i, j;

	bx = (MAIN_X / 2) - 1; //๋ธ”๋ก ์ƒ์„ฑ ์œ„์น˜x์ขŒํ‘œ(๊ฒŒ์ž„ํŒ์˜ ๊ฐ€์šด๋ฐ) 
	by = 0;  //๋ธ”๋ก ์ƒ์„ฑ์œ„์น˜ y์ขŒํ‘œ(์ œ์ผ ์œ„) 
	b_type = b_type_next; //๋‹ค์Œ๋ธ”๋Ÿญ๊ฐ’์„ ๊ฐ€์ ธ์˜ด 
	b_type_next = rand() % 7; //๋‹ค์Œ ๋ธ”๋Ÿญ์„ ๋งŒ๋“ฆ 
	b_rotation = 0;  //ํšŒ์ „์€ 0๋ฒˆ์œผ๋กœ ๊ฐ€์ ธ์˜ด 

	new_block_on = 0; //new_block flag๋ฅผ ๋”  

	for (i = 0; i < 4; i++) { //๊ฒŒ์ž„ํŒ bx, by์œ„์น˜์— ๋ธ”๋Ÿญ์ƒ์„ฑ  
		for (j = 0; j < 4; j++) {
			if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i][bx + j] = ACTIVE_BLOCK;
		}
	}
	for (i = 1; i < 3; i++) { //๊ฒŒ์ž„์ƒํƒœํ‘œ์‹œ์— ๋‹ค์Œ์— ๋‚˜์˜ฌ๋ธ”๋Ÿญ์„ ๊ทธ๋ฆผ 
		for (j = 0; j < 4; j++) {
			if (blocks[b_type_next][0][i][j] == 1) {
				gotoxy(STATUS_X_ADJ + 2 + j, i + 6);
				printf("โ– ");
			}
			else {
				gotoxy(STATUS_X_ADJ + 2 + j, i + 6);
				printf("  ");
			}
		}
	}
}

void check_key(void) {
	key = 0; //ํ‚ค๊ฐ’ ์ดˆ๊ธฐํ™”  

	if (kbhit()) { //ํ‚ค์ž…๋ ฅ์ด ์žˆ๋Š” ๊ฒฝ์šฐ  
		key = getch(); //ํ‚ค๊ฐ’์„ ๋ฐ›์Œ
		if (key == 224) { //๋ฐฉํ–ฅํ‚ค์ธ๊ฒฝ์šฐ 
			do { key = getch(); } while (key == 224);//๋ฐฉํ–ฅํ‚ค์ง€์‹œ๊ฐ’์„ ๋ฒ„๋ฆผ 
			switch (key) {
			case LEFT: //์™ผ์ชฝํ‚ค ๋ˆŒ๋ €์„๋•Œ  
				if (check_crush(bx - 1, by, b_rotation) == true) move_block(LEFT);
				break;                            //์™ผ์ชฝ์œผ๋กœ ๊ฐˆ ์ˆ˜ ์žˆ๋Š”์ง€ ์ฒดํฌ ํ›„ ๊ฐ€๋Šฅํ•˜๋ฉด ์ด๋™
			case RIGHT: //์˜ค๋ฅธ์ชฝ ๋ฐฉํ–ฅํ‚ค ๋ˆŒ๋ €์„๋•Œ- ์œ„์™€ ๋™์ผํ•˜๊ฒŒ ์ฒ˜๋ฆฌ๋จ 
				if (check_crush(bx + 1, by, b_rotation) == true) move_block(RIGHT);
				break;
			case DOWN: //์•„๋ž˜์ชฝ ๋ฐฉํ–ฅํ‚ค ๋ˆŒ๋ €์„๋•Œ-์œ„์™€ ๋™์ผํ•˜๊ฒŒ ์ฒ˜๋ฆฌ๋จ 
				if (check_crush(bx, by + 1, b_rotation) == true) move_block(DOWN);
				break;
			case UP: //์œ„์ชฝ ๋ฐฉํ–ฅํ‚ค ๋ˆŒ๋ €์„๋•Œ 
				if (check_crush(bx, by, (b_rotation + 1) % 4) == true) move_block(UP);
				//ํšŒ์ „ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์ฒดํฌ ํ›„ ๊ฐ€๋Šฅํ•˜๋ฉด ํšŒ์ „
				else if (crush_on == 1 && check_crush(bx, by - 1, (b_rotation + 1) % 4) == true) move_block(100);
			}                    //๋ฐ”๋‹ฅ์— ๋‹ฟ์€ ๊ฒฝ์šฐ ์œ„์ชฝ์œผ๋กœ ํ•œ์นธ๋„์›Œ์„œ ํšŒ์ „์ด ๊ฐ€๋Šฅํ•˜๋ฉด ๊ทธ๋ ‡๊ฒŒ ํ•จ(ํŠน์ˆ˜๋™์ž‘)
		}
		else { //๋ฐฉํ–ฅํ‚ค๊ฐ€ ์•„๋‹Œ๊ฒฝ์šฐ 
			switch (key) {
			case SPACE: //์ŠคํŽ˜์ด์Šคํ‚ค ๋ˆŒ๋ €์„๋•Œ 
				space_key_on = 1; //์ŠคํŽ˜์ด์Šคํ‚ค flag๋ฅผ ๋„์›€ 
				while (crush_on == 0) { //๋ฐ”๋‹ฅ์— ๋‹ฟ์„๋•Œ๊นŒ์ง€ ์ด๋™์‹œํ‚ด 
					drop_block();
					score += level; // hard drop ๋ณด๋„ˆ์Šค
					gotoxy(STATUS_X_ADJ, STATUS_Y_SCORE); printf("        %6d", score); //์ ์ˆ˜ ํ‘œ์‹œ  
				}
				break;
			case P: //P(๋Œ€๋ฌธ์ž) ๋ˆŒ๋ €์„๋•Œ 
			case p: //p(์†Œ๋ฌธ์ž) ๋ˆŒ๋ €์„๋•Œ 
				pause(); //์ผ์‹œ์ •์ง€ 
				break;
			case ESC: //ESC๋ˆŒ๋ €์„๋•Œ 
				system("cls"); //ํ™”๋ฉด์„ ์ง€์šฐ๊ณ  
				exit(0); //๊ฒŒ์ž„์ข…๋ฃŒ 
			}
		}
	}
	while (kbhit()) getch(); //ํ‚ค๋ฒ„ํผ๋ฅผ ๋น„์›€ 
}

void drop_block(void) {
	int i, j;

	if (crush_on && check_crush(bx, by + 1, b_rotation) == true) crush_on = 0; //๋ฐ‘์ด ๋น„์–ด์žˆ์œผ๋ฉด crush flag ๋” 
	if (crush_on && check_crush(bx, by + 1, b_rotation) == false) { //๋ฐ‘์ด ๋น„์–ด์žˆ์ง€์•Š๊ณ  crush flag๊ฐ€ ์ผœ์ €์žˆ์œผ๋ฉด 
		for (i = 0; i < MAIN_Y; i++) { //ํ˜„์žฌ ์กฐ์ž‘์ค‘์ธ ๋ธ”๋Ÿญ์„ ๊ตณํž˜ 
			for (j = 0; j < MAIN_X; j++) {
				if (main_org[i][j] == ACTIVE_BLOCK) main_org[i][j] = INACTIVE_BLOCK;
			}
		}
		crush_on = 0; //flag๋ฅผ ๋” 
		check_line(); //๋ผ์ธ์ฒดํฌ๋ฅผ ํ•จ 
		new_block_on = 1; //์ƒˆ๋กœ์šด ๋ธ”๋Ÿญ์ƒ์„ฑ flag๋ฅผ ์ผฌ    
		return; //ํ•จ์ˆ˜ ์ข…๋ฃŒ 
	}
	if (check_crush(bx, by + 1, b_rotation) == true) move_block(DOWN); //๋ฐ‘์ด ๋น„์–ด์žˆ์œผ๋ฉด ๋ฐ‘์œผ๋กœ ํ•œ์นธ ์ด๋™ 
	if (check_crush(bx, by + 1, b_rotation) == false) crush_on++; //๋ฐ‘์œผ๋กœ ์ด๋™์ด ์•ˆ๋˜๋ฉด  crush flag๋ฅผ ์ผฌ
}

int check_crush(int bx, int by, int b_rotation) { //์ง€์ •๋œ ์ขŒํ‘œ์™€ ํšŒ์ „๊ฐ’์œผ๋กœ ์ถฉ๋Œ์ด ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌ 
	int i, j;

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) { //์ง€์ •๋œ ์œ„์น˜์˜ ๊ฒŒ์ž„ํŒ๊ณผ ๋ธ”๋Ÿญ๋ชจ์–‘์„ ๋น„๊ตํ•ด์„œ ๊ฒน์น˜๋ฉด false๋ฅผ ๋ฆฌํ„ด 
			if (blocks[b_type][b_rotation][i][j] == 1 && main_org[by + i][bx + j] > 0) return false;
		}
	}
	return true; //ํ•˜๋‚˜๋„ ์•ˆ๊ฒน์น˜๋ฉด true๋ฆฌํ„ด 
};

void move_block(int dir) { //๋ธ”๋ก์„ ์ด๋™์‹œํ‚ด 
	int i, j;

	switch (dir) {
	case LEFT: //์™ผ์ชฝ๋ฐฉํ–ฅ 
		for (i = 0; i < 4; i++) { //ํ˜„์žฌ์ขŒํ‘œ์˜ ๋ธ”๋Ÿญ์„ ์ง€์›€ 
			for (j = 0; j < 4; j++) {
				if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i][bx + j] = EMPTY;
			}
		}
		for (i = 0; i < 4; i++) { //์™ผ์ชฝ์œผ๋กœ ํ•œ์นธ๊ฐ€์„œ active block์„ ์ฐ์Œ 
			for (j = 0; j < 4; j++) {
				if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i][bx + j - 1] = ACTIVE_BLOCK;
			}
		}
		bx--; //์ขŒํ‘œ๊ฐ’ ์ด๋™ 
		break;

	case RIGHT:    //์˜ค๋ฅธ์ชฝ ๋ฐฉํ–ฅ. ์™ผ์ชฝ๋ฐฉํ–ฅ์ด๋ž‘ ๊ฐ™์€ ์›๋ฆฌ๋กœ ๋™์ž‘ 
		for (i = 0; i < 4; i++) {
			for (j = 0; j < 4; j++) {
				if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i][bx + j] = EMPTY;
			}
		}
		for (i = 0; i < 4; i++) {
			for (j = 0; j < 4; j++) {
				if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i][bx + j + 1] = ACTIVE_BLOCK;
			}
		}
		bx++;
		break;

	case DOWN:    //์•„๋ž˜์ชฝ ๋ฐฉํ–ฅ. ์™ผ์ชฝ๋ฐฉํ–ฅ์ด๋ž‘ ๊ฐ™์€ ์›๋ฆฌ๋กœ ๋™์ž‘
		for (i = 0; i < 4; i++) {
			for (j = 0; j < 4; j++) {
				if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i][bx + j] = EMPTY;
			}
		}
		for (i = 0; i < 4; i++) {
			for (j = 0; j < 4; j++) {
				if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i + 1][bx + j] = ACTIVE_BLOCK;
			}
		}
		by++;
		break;

	case UP: //ํ‚ค๋ณด๋“œ ์œ„์ชฝ ๋ˆŒ๋ €์„๋•Œ ํšŒ์ „์‹œํ‚ด. 
		for (i = 0; i < 4; i++) { //ํ˜„์žฌ์ขŒํ‘œ์˜ ๋ธ”๋Ÿญ์„ ์ง€์›€  
			for (j = 0; j < 4; j++) {
				if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i][bx + j] = EMPTY;
			}
		}
		b_rotation = (b_rotation + 1) % 4; //ํšŒ์ „๊ฐ’์„ 1์ฆ๊ฐ€์‹œํ‚ด(3์—์„œ 4๊ฐ€ ๋˜๋Š” ๊ฒฝ์šฐ๋Š” 0์œผ๋กœ ๋˜๋Œ๋ฆผ) 
		for (i = 0; i < 4; i++) { //ํšŒ์ „๋œ ๋ธ”๋ก์„ ์ฐ์Œ 
			for (j = 0; j < 4; j++) {
				if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i][bx + j] = ACTIVE_BLOCK;
			}
		}
		break;

	case 100: //๋ธ”๋ก์ด ๋ฐ”๋‹ฅ, ํ˜น์€ ๋‹ค๋ฅธ ๋ธ”๋ก๊ณผ ๋‹ฟ์€ ์ƒํƒœ์—์„œ ํ•œ์นธ์œ„๋กœ ์˜ฌ๋ ค ํšŒ์ „์ด ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ 
		//์ด๋ฅผ ๋™์ž‘์‹œํ‚ค๋Š” ํŠน์ˆ˜๋™์ž‘ 
		for (i = 0; i < 4; i++) {
			for (j = 0; j < 4; j++) {
				if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i][bx + j] = EMPTY;
			}
		}
		b_rotation = (b_rotation + 1) % 4;
		for (i = 0; i < 4; i++) {
			for (j = 0; j < 4; j++) {
				if (blocks[b_type][b_rotation][i][j] == 1) main_org[by + i - 1][bx + j] = ACTIVE_BLOCK;
			}
		}
		by--;
		break;
	}
}

void check_line(void) {
	int i, j, k, l;

	int    block_amount; //ํ•œ์ค„์˜ ๋ธ”๋ก๊ฐฏ์ˆ˜๋ฅผ ์ €์žฅํ•˜๋Š” ๋ณ€์ˆ˜ 
	int combo = 0; //์ฝค๋ณด๊ฐฏ์ˆ˜ ์ €์žฅํ•˜๋Š” ๋ณ€์ˆ˜ ์ง€์ •๋ฐ ์ดˆ๊ธฐํ™” 

	for (i = MAIN_Y - 2; i > 3;) { //i=MAIN_Y-2 : ๋ฐ‘์ชฝ๋ฒฝ์˜ ์œ—์นธ๋ถ€ํ„ฐ,  i>3 : ์ฒœ์žฅ(3)์•„๋ž˜๊นŒ์ง€ ๊ฒ€์‚ฌ 
		block_amount = 0; //๋ธ”๋ก๊ฐฏ์ˆ˜ ์ €์žฅ ๋ณ€์ˆ˜ ์ดˆ๊ธฐํ™” 
		for (j = 1; j < MAIN_X - 1; j++) { //๋ฒฝ๊ณผ ๋ฒฝ์‚ฌ์ด์˜ ๋ธ”๋ก๊ฐฏ๋ฃจ๋ฅผ ์…ˆ 
			if (main_org[i][j] > 0) block_amount++;
		}
		if (block_amount == MAIN_X - 2) { //๋ธ”๋ก์ด ๊ฐ€๋“ ์ฐฌ ๊ฒฝ์šฐ 
			if (level_up_on == 0) { //๋ ˆ๋ฒจ์—…์ƒํƒœ๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—(๋ ˆ๋ฒจ์—…์ด ๋˜๋ฉด ์ž๋™ ์ค„์‚ญ์ œ๊ฐ€ ์žˆ์Œ) 
				score += 100 * level; //์ ์ˆ˜์ถ”๊ฐ€ 
				cnt++; //์ง€์šด ์ค„ ๊ฐฏ์ˆ˜ ์นด์šดํŠธ ์ฆ๊ฐ€ 
				combo++; //์ฝค๋ณด์ˆ˜ ์ฆ๊ฐ€  
			}
			for (k = i; k > 1; k--) { //์œ—์ค„์„ ํ•œ์นธ์”ฉ ๋ชจ๋‘ ๋‚ด๋ฆผ(์œ—์ค„์ด ์ฒœ์žฅ์ด ์•„๋‹Œ ๊ฒฝ์šฐ์—๋งŒ) 
				for (l = 1; l < MAIN_X - 1; l++) {
					if (main_org[k - 1][l] != CEILLING) main_org[k][l] = main_org[k - 1][l];
					if (main_org[k - 1][l] == CEILLING) main_org[k][l] = EMPTY;
					//์œ—์ค„์ด ์ฒœ์žฅ์ธ ๊ฒฝ์šฐ์—๋Š” ์ฒœ์žฅ์„ ํ•œ์นธ ๋‚ด๋ฆฌ๋ฉด ์•ˆ๋˜๋‹ˆ๊นŒ ๋นˆ์นธ์„ ๋„ฃ์Œ 
				}
			}
		}
		else i--;
	}
	if (combo) { //์ค„ ์‚ญ์ œ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ์ ์ˆ˜์™€ ๋ ˆ๋ฒจ ๋ชฉํ‘œ๋ฅผ ์ƒˆ๋กœ ํ‘œ์‹œํ•จ  
		if (combo > 1) { //2์ฝค๋ณด์ด์ƒ์ธ ๊ฒฝ์šฐ ๊ฒฝ์šฐ ๋ณด๋„ˆ์Šค๋ฐ ๋ฉ”์„ธ์ง€๋ฅผ ๊ฒŒ์ž„ํŒ์— ๋„์› ๋‹ค๊ฐ€ ์ง€์›€ 
			gotoxy(MAIN_X_ADJ + (MAIN_X / 2) - 1, MAIN_Y_ADJ + by - 2); printf("%d COMBO!", combo);
			Sleep(500);
			score += (combo * level * 100);
			reset_main_cpy(); //ํ…์ŠคํŠธ๋ฅผ ์ง€์šฐ๊ธฐ ์œ„ํ•ด main_cpy์„ ์ดˆ๊ธฐํ™”.
			//(main_cpy์™€ main_org๊ฐ€ ์ „๋ถ€ ๋‹ค๋ฅด๋ฏ€๋กœ ๋‹ค์Œ๋ฒˆ draw()ํ˜ธ์ถœ์‹œ ๊ฒŒ์ž„ํŒ ์ „์ฒด๋ฅผ ์ƒˆ๋กœ ๊ทธ๋ฆฌ๊ฒŒ ๋จ) 
		}
		gotoxy(STATUS_X_ADJ, STATUS_Y_GOAL); printf(" GOAL  : %5d", (cnt <= 10) ? 10 - cnt : 0);
		gotoxy(STATUS_X_ADJ, STATUS_Y_SCORE); printf("        %6d", score);
	}
}

void check_level_up(void) {
	int i, j;

	if (cnt >= 10) { //๋ ˆ๋ฒจ๋ณ„๋กœ 10์ค„์”ฉ ์—†์• ์•ผํ•จ. 10์ค„์ด์ƒ ์—†์•ค ๊ฒฝ์šฐ 
		draw_main();
		level_up_on = 1; //๋ ˆ๋ฒจ์—… flag๋ฅผ ๋„์›€ 
		level += 1; //๋ ˆ๋ฒจ์„ 1 ์˜ฌ๋ฆผ 
		cnt = 0; //์ง€์šด ์ค„์ˆ˜ ์ดˆ๊ธฐํ™”   

		for (i = 0; i < 4; i++) {
			gotoxy(MAIN_X_ADJ + (MAIN_X / 2) - 3, MAIN_Y_ADJ + 4);
			printf("             ");
			gotoxy(MAIN_X_ADJ + (MAIN_X / 2) - 2, MAIN_Y_ADJ + 6);
			printf("             ");
			Sleep(200);

			gotoxy(MAIN_X_ADJ + (MAIN_X / 2) - 3, MAIN_Y_ADJ + 4);
			printf("โ˜†LEVEL UP!โ˜†");
			gotoxy(MAIN_X_ADJ + (MAIN_X / 2) - 2, MAIN_Y_ADJ + 6);
			printf("โ˜†SPEED UP!โ˜†");
			Sleep(200);
		}
		reset_main_cpy(); //ํ…์ŠคํŠธ๋ฅผ ์ง€์šฐ๊ธฐ ์œ„ํ•ด main_cpy์„ ์ดˆ๊ธฐํ™”.
		//(main_cpy์™€ main_org๊ฐ€ ์ „๋ถ€ ๋‹ค๋ฅด๋ฏ€๋กœ ๋‹ค์Œ๋ฒˆ draw()ํ˜ธ์ถœ์‹œ ๊ฒŒ์ž„ํŒ ์ „์ฒด๋ฅผ ์ƒˆ๋กœ ๊ทธ๋ฆฌ๊ฒŒ ๋จ) 

		for (i = MAIN_Y - 2; i > MAIN_Y - 2 - (level - 1); i--) { //๋ ˆ๋ฒจ์—…๋ณด์ƒ์œผ๋กœ ๊ฐ ๋ ˆ๋ฒจ-1์˜ ์ˆ˜๋งŒํผ ์•„๋žซ์ชฝ ์ค„์„ ์ง€์›Œ์คŒ 
			for (j = 1; j < MAIN_X - 1; j++) {
				main_org[i][j] = INACTIVE_BLOCK; // ์ค„์„ ๋ธ”๋ก์œผ๋กœ ๋ชจ๋‘ ์ฑ„์šฐ๊ณ  
				gotoxy(MAIN_X_ADJ + j, MAIN_Y_ADJ + i); // ๋ณ„์„ ์ฐ์–ด์คŒ.. ์ด๋ป๋ณด์ด๊ฒŒ 
				printf("โ˜…");
				Sleep(20);
			}
		}
		Sleep(100); //๋ณ„์ฐ์€๊ฑฐ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด delay 
		check_line(); //๋ธ”๋ก์œผ๋กœ ๋ชจ๋‘ ์ฑ„์šด๊ฒƒ ์ง€์šฐ๊ธฐ
		//.check_line()ํ•จ์ˆ˜ ๋‚ด๋ถ€์—์„œ level up flag๊ฐ€ ์ผœ์ ธ์žˆ๋Š” ๊ฒฝ์šฐ ์ ์ˆ˜๋Š” ์—†์Œ.         
		switch (level) { //๋ ˆ๋ฒจ๋ณ„๋กœ ์†๋„๋ฅผ ์กฐ์ ˆํ•ด์คŒ. 
		case 2:
			speed = 50;
			break;
		case 3:
			speed = 25;
			break;
		case 4:
			speed = 10;
			break;
		case 5:
			speed = 5;
			break;
		case 6:
			speed = 4;
			break;
		case 7:
			speed = 3;
			break;
		case 8:
			speed = 2;
			break;
		case 9:
			speed = 1;
			break;
		case 10:
			speed = 0;
			break;
		}
		level_up_on = 0; //๋ ˆ๋ฒจ์—… flag๊บผ์คŒ

		gotoxy(STATUS_X_ADJ, STATUS_Y_LEVEL); printf(" LEVEL : %5d", level); //๋ ˆ๋ฒจํ‘œ์‹œ 
		gotoxy(STATUS_X_ADJ, STATUS_Y_GOAL); printf(" GOAL  : %5d", 10 - cnt); // ๋ ˆ๋ฒจ๋ชฉํ‘œ ํ‘œ์‹œ 

	}
}

void check_game_over(void) {
	int i;

	int x = 5;
	int y = 5;

	for (i = 1; i < MAIN_X - 2; i++) {
		if (main_org[3][i] > 0) { //์ฒœ์žฅ(์œ„์—์„œ ์„ธ๋ฒˆ์งธ ์ค„)์— inactive๊ฐ€ ์ƒ์„ฑ๋˜๋ฉด ๊ฒŒ์ž„ ์˜ค๋ฒ„ 
			gotoxy(x, y + 0); printf("โ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–ค"); //๊ฒŒ์ž„์˜ค๋ฒ„ ๋ฉ”์„ธ์ง€ 
			gotoxy(x, y + 1); printf("โ–ค                              โ–ค");
			gotoxy(x, y + 2); printf("โ–ค  +-----------------------+   โ–ค");
			gotoxy(x, y + 3); printf("โ–ค  |  G A M E  O V E R ... |   โ–ค");
			gotoxy(x, y + 4); printf("โ–ค  +-----------------------+   โ–ค");
			gotoxy(x, y + 5); printf("โ–ค   YOUR SCORE: %6d         โ–ค", score);
			gotoxy(x, y + 6); printf("โ–ค                              โ–ค");
			gotoxy(x, y + 7); printf("โ–ค  Press any key to restart..  โ–ค");
			gotoxy(x, y + 8); printf("โ–ค                              โ–ค");
			gotoxy(x, y + 9); printf("โ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–ค");
			last_score = score; //๊ฒŒ์ž„์ ์ˆ˜๋ฅผ ์˜ฎ๊น€ 

			if (score > best_score) { //์ตœ๊ณ ๊ธฐ๋ก ๊ฐฑ์‹ ์‹œ 
				FILE* file = fopen("score.dat", "wt"); //score.dat์— ์ ์ˆ˜ ์ €์žฅ                

				gotoxy(x, y + 6); printf("โ–ค  โ˜…โ˜…โ˜… BEST SCORE! โ˜…โ˜…โ˜…   โ–ค  ");

				if (file == 0) { //ํŒŒ์ผ ์—๋Ÿฌ๋ฉ”์„ธ์ง€  
					gotoxy(0, 0);
					printf("FILE ERROR: SYSTEM CANNOT WRITE BEST SCORE ON \"SCORE.DAT\"");
				}
				else {
					fprintf(file, "%d", score);
					fclose(file);
				}
			}
			Sleep(1000);
			while (kbhit()) getch();
			key = getch();
			reset();
		}
	}
}

void pause(void) { //๊ฒŒ์ž„ ์ผ์‹œ์ •์ง€ ํ•จ์ˆ˜ 
	int i, j;

	int x = 5;
	int y = 5;

	for (i = 1; i < MAIN_X - 2; i++) { //๊ฒŒ์ž„ ์ผ์‹œ์ •์ง€ ๋ฉ”์„ธ์ง€ 
		gotoxy(x, y + 0); printf("โ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–ค");
		gotoxy(x, y + 1); printf("โ–ค                              โ–ค");
		gotoxy(x, y + 2); printf("โ–ค  +-----------------------+   โ–ค");
		gotoxy(x, y + 3); printf("โ–ค  |       P A U S E       |   โ–ค");
		gotoxy(x, y + 4); printf("โ–ค  +-----------------------+   โ–ค");
		gotoxy(x, y + 5); printf("โ–ค  Press any key to resume..   โ–ค");
		gotoxy(x, y + 6); printf("โ–ค                              โ–ค");
		gotoxy(x, y + 7); printf("โ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–คโ–ค");
	}
	getch(); //ํ‚ค์ž…๋ ฅ์‹œ๊นŒ์ง€ ๋Œ€๊ธฐ 

	system("cls"); //ํ™”๋ฉด ์ง€์šฐ๊ณ  ์ƒˆ๋กœ ๊ทธ๋ฆผ 
	reset_main_cpy();
	draw_main();
	draw_map();

	for (i = 1; i < 3; i++) { // ๋‹ค์Œ๋ธ”๋ก ๊ทธ๋ฆผ 
		for (j = 0; j < 4; j++) {
			if (blocks[b_type_next][0][i][j] == 1) {
				gotoxy(MAIN_X + MAIN_X_ADJ + 3 + j, i + 6);
				printf("โ– ");
			}
			else {
				gotoxy(MAIN_X + MAIN_X_ADJ + 3 + j, i + 6);
				printf("  ");
			}
		}
	}
}

Year of Coding : 2015