본문 바로가기
학부공부/C_Basic

2. Project_64 PuyoPuyo[C Basic]

by sonpang 2021. 11. 7.
반응형

2.1. Environment

Windows 10

Visual Studio 2017

Programming language: C (C++ will not be allowed.)

 

2.2. Project

Write a program “64 PuyoPuyo

64 PuyoPuyo is a block-matching puzzle game

Each block consists of a number and a binary arithmetic operator (addition or difference)

Merge two numbers with one operator

When it reaches 64, the block vanishes and user earns points

Goal of each stage is to earn certain points

 

New Block

The number of a new block has one of the following numbers with certain ratio

  • 2 for 50%

  • 4 for 30%

  • 8 for 20%

The arithmetic operator of a new block has one of the following operators with certain ratio

  1. Addition (+) for 50%

  2. Difference (-)  for 50% (e.g., 3-5 = 2, not -2)

  • From stage 1 to 3, only addition is assigned to the block

Each block should be created and starts falling from the top of game screen

It consists of two blocks of numbers and operators and is generated only in the horizontal direction

The horizontal coordinate of new blocks should be determined randomly

If the block cannot fall anymore, the next block should be created, and starts falling down again

 

Block control

While the block is falling, the player can flip the block (change the locations of number and operator) with ‘up’ direction key, and move the block to down, left, or right with each corresponding direction keys from the keyboard

  1. Cannot move after the block reaches to the bottom or other blocks which are already laid down

  2. Cannot move beyond boundary of the game screen

The player can ‘Hard drop’ the block right away with ‘Space bar’ to the bottom

 

Separation of block

A block can be separated as follows

 

Merging blocks

When the falling block reached to the bottom or another block which is already laid down, program finds out if there are any of surrounding blocks that can be merged

  1. Blocks can be merged if adjacent blocks are in an order of ‘number’ ‘operator’ ‘number’

  2. Blocks can be merged between vertical and horizontal adjacent blocks

The merging can happen consecutively

  • If a merged output results in another merging condition, those blocks should be merged consecutively

 

Merging Rule

When horizontal blocks are merged, the result is assigned to the leftmost position

When vertical blocks are merged, the result is assigned to the lowest position

When different operators are mixed in one expression, addition has higher precedence level than difference

When the merging (calculation) result is zero, then the block becomes * block, which means it is a dead block

 

Merging Example

 

Merging Rule

If both vertical and horizontal operations become possible at the same time, horizontal operations should be done first

 

Stages

The game has 6 stages with different goal, block speed, and operators

Stage Goal point Block speed Operator
1 100 1 (Initial speed) +
2 300 1.3
3 500 1.5
4 600 1.7 +, -
5 750 2
6 850 2.5

Player wins the stage when having reached the goal point

Player wins the game when cleared all stages

Player loses game when blocks reach up to the top of the game screen

The player must complete the previous stage for moving to the next stage

Each time the player move on to next stages,  corresponding values of goal point and block speed need to be set and continues the game

 

Scoring Rule

When 2 blocks of 64 vanish, then player earns 10 points

  • 2 blocks – 10 points, 3 blocks – 20 points, 4 blocks – 30 points, and so on…

  • When ‘Hard drop’ the block, 5 points are increased as a bonus

The score will be accumulated after the player clear the stages

  • The score is reset when the game ends

The highest score is displayed until the program ends

 

Function key

Player can ‘Pause’ game with pressing ‘p’ key from keyboard and resume by pressing ‘p’ again

Player can go back to ‘Main menu’ by pressing ‘Esc’ key from keyboard while playing game

Player can ‘Exit game’ by pressing ‘Esc’ key from keyboard in the main menu

 

Note

Use the given sample code to complete your project

You can add or modify the specified area in the sample code as you want

Exceptions need to be well handled including invalid inputs

반응형

 

2.3. Code

#include<stdio.h>
#include<time.h>
#include<conio.h>
#include<stdlib.h>
#include<windows.h>
#include<math.h>

// COSE101, Spring Semester, 2019
// Computer Science and Engineering, College of Informatics, Korea University, Seoul.Son Hyegang

#define LEFT 75
#define RIGHT 77
#define DOWN 80
#define UP 72
#define SPACE 32 
#define p 112 
#define P 80 
#define ESC 27

#define MAP_ADJ_X 10
#define MAP_ADJ_Y 5
#define X 8
#define Y 5

typedef struct _block {
	int pos_x; //position of block
	int pos_y;
	int num;
	int nextnum;
	int isactive;
}Block;

Block block, block2;

/* 'DO NOT MODIFY THESE FUNCTIONS.'		'이 함수들을 고치지 마세요.'		 */
void removeCursorFromCMD();
void setCoordinate(int x, int y); //cmd에서 커서를 x, y 위치로 세팅

								  /* display fuctions */
void goMainMenuScreen(); // 메인메뉴로 이동 Moving to main menu.
void printGameScreen();  // 게임화면 출력	 Printing game screen.
void printPauseScreen(); // 일시 정지 화면	 Prining pause screen.
void printEndScreen(int endType); //  // 스테이지 종료 화면 출력. 스테이지클리어, 모든스테이지클리어, 패배.
								  //Printing result of end of stages including 'cleared the stage', 'cleared whole stages', and 'lost'.
void clearScreen();
/* 'DO NOT MODIFY THESE FUNCTIONS.' ends	'이 함수들을 고치지 마세요' 끝.	*/

/* @ --- You can modify following functions ----  이 아래에있는 함수들을 고치세요.  */
//Implement these functions below to complete your project.
//이 함수들을 구현하셔서 프로젝트를 완성하세요.

/* Block generating functions */
int getRandomNumber();
void newBlock();

/* block control and merging functions  */
int takeBlockControl();				//블록 조작 방향 입력 받음			Taking input for moving blocks
void flipBlock();					// Fliping function.
void moveBlock(int direction);		// 입력 받은 방향으로 블록 이동		Moving blocks to corresponding direction of input key.
int checkAdjacentBlock(int, int);	//Checking adjacent blocks for merging conditions
void checkNumber(int, int);			// 블록 인접 블록숫자 확인			Checking number of adjacent block
void calculationHorizontal(int, int);
void calculationVertical(int, int);
void calculationLine(int);
void fallingblock();
int isdigit(int, int);
void isscore(int, int);
									/* game flow control functions */
int isStageEnd();  
void setGameFlow(int type); 

int time_interval_moveBlockDown = 100;
int goal = 64;
int currentStage = 0;
int score = 0;
int best_score = 0;
int gameScreen[X][Y] = { 0 };

 

//Son hyegang
void main() {
	system("mode con cols=120 lines=38");
	srand(time(NULL));
	removeCursorFromCMD();
	goMainMenuScreen();

	while (1) {
		for (int j = 0; j < 5; j++) {
			if (takeBlockControl() == SPACE) break;
			printGameScreen();
			Sleep(time_interval_moveBlockDown);
		}
		moveBlock(DOWN);
		if (!block.isactive && !block2.isactive) { // 이 부분은 떨어지는 블록이 바닥이나 다른블록에 닿았는지 체크합니다. This statement is cheking that wether the falling blocks got touched by floor or other blocks.
			checkNumber(block.pos_x, block.pos_y); //Son hyegang
			if (isStageEnd() != 1)
				newBlock();
		}
	}
}

 

int getRandomNumber() {
	int random = rand() % 10 + 1;
	if (random <= 5)
		return 2;
	else if(random <= 8)
		return 4;
	else
		return 8;
}

 

char getRandomOper() {
	if (currentStage <= 3)
		return '+';
	else {
		if (rand() % 2)
			return '+';
		else
			return '-';
	}
}

 

void newBlock() {
	if (block.nextnum == 0) {
		block.num = getRandomNumber();
		block2.num = getRandomOper();
	}
	else {
		block.num = block.nextnum; 
		block2.num = block2.nextnum;
	}
	block.nextnum = getRandomNumber(); 
	block2.nextnum = getRandomOper();  

	block.pos_x = 0;
	block.pos_y = rand()%4;
	block.isactive = 1;
	gameScreen[block.pos_x][block.pos_y] = block.num;

	block2.pos_x = 0;
	block2.pos_y = block.pos_y+1;
	block2.isactive = 1;
	gameScreen[block2.pos_x][block2.pos_y] = block2.num;
}

 

int takeBlockControl() {//Son Hyegnag
	int input_blockControl = 0;

	if (_kbhit()) {
		input_blockControl = _getch();
		if (input_blockControl == 224 && block.isactive && block2.isactive) { //방향키인경우  Cases for direction keys
			do { input_blockControl = _getch(); } while (input_blockControl == 224);//방향키지시값을 버림  dropping the value of direction
			switch (input_blockControl) {
			case UP:
				flipBlock();
				break;
			case LEFT:
				moveBlock(LEFT);
				break;
			case RIGHT:
				moveBlock(RIGHT);
				break;
			case DOWN:
				moveBlock(DOWN);
				break;
			}
		}
		else { //방향키가 아닌경우  Cases for other keys//Son Hyegnag
			switch (input_blockControl) {
			case SPACE:
				score += 5;
				while(block.isactive||block2.isactive)
					moveBlock(DOWN);
				break;
			case P:
			case p:
				printPauseScreen();
				break;
			case ESC:
				printEndScreen(0);
				break;
			}
		}
	}
	while (_kbhit()) _getch(); //키버퍼를 비움. Emptying key buffer.
	return 0;
}

 

void flipBlock(void) {
	int temp = block.num;
	block.num = block2.num;
	block2.num = temp;
}

 

void moveBlock(int direction) { // 좌,우,아래 입력시 움직임 함수	Moving blocks for left, reight, and down input
	switch (direction) {//Son Hyegnag
	case LEFT:
		if (!gameScreen[block.pos_x][block.pos_y - 1] && block.pos_y > 0) {
			gameScreen[block2.pos_x][block2.pos_y] = 0;
			gameScreen[block.pos_x][block.pos_y-1] = block.num;
			gameScreen[block2.pos_x][block2.pos_y - 1] = block2.num;
			block.pos_y--;
			block2.pos_y--;
		}
		break;
	case RIGHT:
		if (!gameScreen[block2.pos_x][block2.pos_y + 1] && block2.pos_y < 4) {
			gameScreen[block.pos_x][block.pos_y] = 0;
			gameScreen[block.pos_x][block.pos_y+1] = block.num;
			gameScreen[block2.pos_x][block2.pos_y+1] = block2.num;
			block.pos_y++;
			block2.pos_y++;
		}
		break;
	case DOWN:
		if (block.pos_x < X - 1 && gameScreen[block.pos_x + 1][block.pos_y] == 0) {
			gameScreen[block.pos_x + 1][block.pos_y] = block.num;
			gameScreen[block.pos_x][block.pos_y] = 0;
			block.pos_x++;
		}
		else {
			block.isactive = 0;
		}

		if (block2.pos_x < X - 1 && gameScreen[block2.pos_x + 1][block2.pos_y] == 0) {
			gameScreen[block2.pos_x + 1][block2.pos_y] = block2.num;
			gameScreen[block2.pos_x][block2.pos_y] = 0;
			block2.pos_x++;
		}
		else {
			block2.isactive = 0;
		}
	}
}

 

int isdigit(int x, int y) {
	if (gameScreen[x][y] == 43 || gameScreen[x][y] == 45 || gameScreen[x][y] == 0 || gameScreen[x][y] == 999)
		return 0;
	return 1;
}

 

void isscore(int x, int y) {
	printGameScreen();
	Sleep(200);
	static int firstcheck = 0;
	if (x == X && y == Y) {
		firstcheck = 0;
		return;
	}
	if (!firstcheck && gameScreen[x][y] == 64) {
		firstcheck++;
		gameScreen[x][y] = 0;
	}
	else {
		if (gameScreen[x][y] == 0)
			gameScreen[x][y] = 999;
		if (gameScreen[x][y] == 64) {
			score += 10;
			gameScreen[x][y] = 0;
		}
	}
	fallingblock();
}

 

void fallingblock() {//Son Hyegang
	for (int j = 0; j < Y; j++) {
		for (int i = X - 1; i > 1 ; i--) {
			if (!gameScreen[i][j] && gameScreen[i - 1][j]) {
				gameScreen[i][j] = gameScreen[i - 1][j];
				gameScreen[i - 1][j] = 0;
			}
		}
	}
}

 

int checkAdjacentBlock(int x, int y) { 
	for (int k = X - 1;k > 0;k--) {
		if (isdigit(k, 0) && isdigit(k, 2) && isdigit(k, 4) && (gameScreen[k][1] == 43 || gameScreen[k][1] == 45) && (gameScreen[k][3] == 43 || gameScreen[k][3] == 45)) {
			calculationLine(k);
			printGameScreen();
			Sleep(100);
			return 1;
		}
	}
	if (isdigit(x, y - 1) && isdigit(x, y + 1) && (gameScreen[x][y] == 43 || gameScreen[x][y] == 45)) {
		if (y != 0 && y != Y - 1) {
			calculationHorizontal(x, y);
			return 1;
		}
	}
	
	if (isdigit(x - 1, y) && isdigit(x + 1, y) && (gameScreen[x][y] == 43 || gameScreen[x][y] == 45)) {
		if (x != 0 && x != X - 1) {//Son Hyegang
			calculationVertical(x, y);
			return 1;
		}
	}
	return 0;
}

 

void calculationHorizontal(int x, int y) {
	if (gameScreen[x][y] == 43) {
		gameScreen[x][y - 1] += gameScreen[x][y + 1];
		gameScreen[x][y] = 0;
		gameScreen[x][y + 1] = 0;
	}
	if (gameScreen[x][y] == 45) {//Son Hyegang
		gameScreen[x][y - 1] = abs(gameScreen[x][y + 1] - gameScreen[x][y - 1]);
		gameScreen[x][y] = 0;
		gameScreen[x][y + 1] = 0;
	}	
	isscore(x, y - 1);
	fallingblock();
	printGameScreen();
	Sleep(100);
}

 

void calculationVertical(int x, int y) {
	if (gameScreen[x][y] == 43) {
		gameScreen[x + 1][y] += gameScreen[x - 1][y];
		gameScreen[x][y] = 0;
		gameScreen[x - 1][y] = 0;
	}
	if (gameScreen[x][y] == 45) {//Son Hyegang
		gameScreen[x + 1][y] = abs(gameScreen[x - 1][y] - gameScreen[x + 1][y]);
		gameScreen[x][y] = 0;
		gameScreen[x - 1][y] = 0;
	}
	isscore(x + 1, y);
	fallingblock();
	printGameScreen();
	Sleep(100);
}

 

void calculationLine(int x) {
	if (gameScreen[x][1] == 43 && gameScreen[x][3] == 43) {//Son Hyegang
		gameScreen[x][0] += (gameScreen[x][2] + gameScreen[x][4]);
	}
	if (gameScreen[x][1] == 43 && gameScreen[x][3] == 45) {
		gameScreen[x][0] += gameScreen[x][2];
		gameScreen[x][0] = abs(gameScreen[x][0] - gameScreen[x][4]);
	}
	if (gameScreen[x][1] == 45 && gameScreen[x][3] == 43) {
		gameScreen[x][2] += gameScreen[x][4];
		gameScreen[x][0] = abs(gameScreen[x][0] - gameScreen[x][2]);
	}
	if (gameScreen[x][1] == 45 && gameScreen[x][3] == 45) {
		gameScreen[x][2] = abs(gameScreen[x][2] - gameScreen[x][4]);
		gameScreen[x][0] = abs(gameScreen[x][0] - gameScreen[x][2]);
	}
	gameScreen[x][1] = 0;
	gameScreen[x][2] = 0;
	gameScreen[x][3] = 0;
	gameScreen[x][4] = 0;
	isscore(x, 0);
	fallingblock();
	printGameScreen();//Son Hyegang
	Sleep(100);
}

 

void checkNumber(int x, int y) {

	checkAdjacentBlock(x, y);
	printGameScreen();
	Sleep(200);
	for (int i = X - 1; i > 0; i--) {//Son Hyegang
		for (int j = 0; j < Y ; j++) {
			if (checkAdjacentBlock(i, j)) {
				printGameScreen();
				Sleep(200);
				i = X;
				break;
			}
		}
	}
}

 

void setGameFlow(int setGameFlowType) {
	switch (setGameFlowType) {
	case 0:  /* initialize game */
		if (best_score < score)
			best_score = score;
		isscore(X, Y);
		currentStage = 0;
		score = 0;

	case 1://Son Hyegang
		currentStage++;
		switch (currentStage) {
		case 1:
			time_interval_moveBlockDown = 100;
			goal = 100;
			break;
		case 2:
			time_interval_moveBlockDown = 76;
			goal = 300;
			break;
		case 3:
			time_interval_moveBlockDown = 67;
			goal = 500;
			break;
		case 4:
			time_interval_moveBlockDown = 59;
			goal = 600;
			break;
		case 5:
			time_interval_moveBlockDown = 50;
			goal = 750;
			break;
		case 6:
			time_interval_moveBlockDown = 40;
			goal = 850;
			break;
		}
		clearScreen();
		newBlock();
		break;

	default://Son Hyegang
		clearScreen();
		setCoordinate(MAP_ADJ_X + 2, MAP_ADJ_Y + 13); printf(" @System error: state end condition currupted.");
		exit(0);
	}
}

 

int isStageEnd() {//Son Hyegang
	for (int i = X - 1; i > 1; i--) {
		for (int j = 0; j < Y; j++) {
			if (score >= goal) {
				currentStage < 7 ? printEndScreen(1) : printEndScreen(2);
				return 1;
			}
		}
	}
	for (int i = 0; i < Y; i++) {
		if (gameScreen[0][i] != 0) {
			printEndScreen(0);
			return 1;
		}
	}
	return 0;
}

 

/* @ ↓↓↓'DO NOT MODIFY FROM HERE.'↓↓↓ starts		 이 아래로는 수정하지 마세요.	*/
void removeCursorFromCMD() { // cmd에서 깜빡이는 커서없앰 Concealing cursor from cmd.
	CONSOLE_CURSOR_INFO CurInfo;
	CurInfo.dwSize = 1;
	CurInfo.bVisible = FALSE;
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &CurInfo);
}

 

void setCoordinate(int x, int y) { //cmd에서 커서 위치를 x, y로 세팅   Setting curser to (x,y).
	COORD pos = { 2 * x,y };
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

 

void printGameScreen() {
	int i, j, k;
//Son Hyegang
	for (i = 0; i < X; i++) {
		for (j = 0; j < Y; j++) {
			setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3));
			if (gameScreen[i][j] == 0) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
				if (i == 0) {
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3) - 1);
					printf("             ");
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3));
					printf("     ┿      ");
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3) + 1);
					printf("             ");
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3) + 2);
					printf("-------------");
				}
				else {
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3));
					printf("             ");
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3) + 1);
					printf("     ┿      ");
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3) + 2);
					printf("             ");
				}
			}

			else {
				for (k = 0; k < 12;) if (1 << (++k) == gameScreen[i][j]) break;//Son Hyegang
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), k + 1);
				if (gameScreen[i][j] == 45 || gameScreen[i][j] == 43)
					SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);

				if (i == 0) {
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3) - 1);
					printf("┌─────────┐ ");
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3));
					if (gameScreen[i][j] == 45)
						printf("   %4c", gameScreen[i][j]);
					else if (gameScreen[i][j] == 43)
						printf("   %4c", gameScreen[i][j]);
					else if (gameScreen[i][j] == 999)
						printf("      *", gameScreen[i][j]);
					else
						printf("   %4d", gameScreen[i][j]);
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3) + 1);
					printf("└─────────┘ ");//Son Hyegang
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3) + 2);

				}
				else {
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3));
					printf("┌─────────┐  ");
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3) + 1);
					if (gameScreen[i][j] == 45)
						printf("   %4c", gameScreen[i][j]);
					else if (gameScreen[i][j] == 43)
						printf("   %4c", gameScreen[i][j]);
					else if (gameScreen[i][j] == 999)
						printf("      *", gameScreen[i][j]);
					else
						printf("   %4d", gameScreen[i][j]);
					setCoordinate(MAP_ADJ_X + (j * 6), MAP_ADJ_Y + (i * 3) + 2);
					printf("└─────────┘  ");
				}

			}
		}
	}
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y); printf(" Stage : %4d", currentStage);
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 1); printf(" GOAL  : %4d", goal);
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 2); printf(" SPEED  : %.1f", 100.0 / (float)time_interval_moveBlockDown);
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 3); printf("+-  N E X T  -+ ");
	for (k = 0; k < 12;) if (1 << (++k) == block.nextnum) break;//Son Hyegang
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), k + 1);
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 4); printf("  ┌─────────┐    ");
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 5); printf("     %4d    ", block.nextnum);
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 6); printf("  └─────────┘    ");
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 7); printf("  ┌─────────┐    ");
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 8); printf("     %4c    ", block2.nextnum);
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 9); printf("  └─────────┘    ");
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 10); printf("+-- -  -  - --+ ");
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 11); printf(" YOUR SCORE :");
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 12); printf("        %6d", score);
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 13); printf(" BEST SCORE :");
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 14); printf("        %6d", best_score);

	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 15); printf("  △   : Flip");
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 16); printf("◁  ▷ : Left / Right");
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 17); printf("  ▽   : Soft Drop ");
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 18); printf(" SPACE : Hard Drop");
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 19); printf("   P   : Pause");
	setCoordinate(MAP_ADJ_X + 32, MAP_ADJ_Y + 20); printf("  ESC  : Quit");

}

 

void goMainMenuScreen() { //시작화면 출력 함수. Printing out main menu.
	int x = 19;
	int y = 9;//Son Hyegang
	int input_command = 0;

	setCoordinate(x, y + 2); printf("──────────────────────────────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("☆ ────────────────────────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("o ☆ ─────────────────────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("yo ☆ ────────────────────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("yoPuyo ☆ ─────────────────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("PuyoPuyo ☆ ────────────────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("─ 64 PuyoPuyo ☆─────────────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("─── 64 PuyoPuyo ☆ ───────────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("──── 64 PuyoPuyo ☆ ──────────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("─────  64 PuyoPuyo ☆ ────────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("───────  64 PuyoPuyo ☆ ──────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("────────  64 PuyoPuyo ☆ ─────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("─────────  64 PuyoPuyo ☆ ────────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("──────────  64 PuyoPuyo ☆ ───────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("───────────  64 PuyoPuyo ☆ ──────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("────────────  64 PuyoPuyo ☆ ─────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("─────────────  64 PuyoPuyo ☆ ────");
	Sleep(30);
	setCoordinate(x, y + 2); printf("──────────────  64 PuyoPuyo ☆ ───");
	Sleep(30);
	setCoordinate(x, y + 2); printf("───────────────  64 PuyoPuyo ☆ ──");
	Sleep(30);
	setCoordinate(x, y + 2); printf("────────────────  64 PuyoPuyo ☆ ─");


	setCoordinate(x + 2, y + 4); printf(" Press any key to start");

	setCoordinate(x, y + 6);  printf(" ▤▤▤▤ HOW TO CONTROL ▤▤▤▤");
	setCoordinate(x, y + 7);  printf(" ▤                            ▤");
	setCoordinate(x, y + 8);  printf(" ▤      △   : Flip           ▤");
	setCoordinate(x, y + 9); printf(" ▤    ◁  ▷ : Left / Right   ▤");
	setCoordinate(x, y + 10); printf(" ▤      ▽   : Soft Drop      ▤");
	setCoordinate(x, y + 11); printf(" ▤    SPACE  : Hard Drop      ▤");
	setCoordinate(x, y + 12); printf(" ▤      P    : Pause          ▤");
	setCoordinate(x, y + 13); printf(" ▤     ESC   : Quit           ▤");
	setCoordinate(x, y + 14); printf(" ▤                            ▤");
	setCoordinate(x, y + 15); printf(" ▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤");

	setCoordinate(x, y + 16); printf("          ESC: Exit game.     ");



	while (_kbhit())
		_getch();//Son Hyegang
	input_command = _getch();


	if (input_command == ESC) {
		clearScreen();
		exit(0);
	}
	else
		setGameFlow(0); /* Reset the game */

}

 

void printPauseScreen() { // 게임 일시정지		Pause game.
	int x = MAP_ADJ_X + 8;
	int y = MAP_ADJ_Y + 5;

	setCoordinate(x, y + 0); printf("▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤");
	setCoordinate(x, y + 1); printf("▤                              ▤");
	setCoordinate(x, y + 2); printf("▤  +-----------------------+   ▤");
	setCoordinate(x, y + 3); printf("▤  |       P A U S E       |   ▤");
	setCoordinate(x, y + 4); printf("▤  +-----------------------+   ▤");
	setCoordinate(x, y + 5); printf("▤   Press any key to resume.   ▤");
	setCoordinate(x, y + 6); printf("▤                              ▤");
	setCoordinate(x, y + 7); printf("▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤");

	_getch();

	system("cls");
	printGameScreen();
}

 

void printEndScreen(int endType) {
	int input_command = 0;
	int x = MAP_ADJ_X + 8;//Son Hyegang

	switch (endType) {
	case 0:
		setCoordinate(x, MAP_ADJ_Y + 5);  printf("▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤");
		setCoordinate(x, MAP_ADJ_Y + 6);  printf("▤                              ▤");
		setCoordinate(x, MAP_ADJ_Y + 7);  printf("▤  +-----------------------+   ▤");
		setCoordinate(x, MAP_ADJ_Y + 8);  printf("▤  |  G A M E  O V E R..   |   ▤");
		setCoordinate(x, MAP_ADJ_Y + 9);  printf("▤  +-----------------------+   ▤");
		setCoordinate(x, MAP_ADJ_Y + 10); printf("▤   YOUR SCORE: %6d         ▤", score);
		setCoordinate(x, MAP_ADJ_Y + 11); printf("▤                              ▤");
		setCoordinate(x, MAP_ADJ_Y + 12); printf("▤   Press any key to restart.  ▤");
		setCoordinate(x, MAP_ADJ_Y + 13); printf("▤                              ▤");
		setCoordinate(x, MAP_ADJ_Y + 14); printf("▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤");
		setCoordinate(x, MAP_ADJ_Y + 16); printf("      ESC: Back to main menu.     ");

		while (_kbhit()) _getch();
		input_command = _getch();

		if (input_command == ESC) {
			while (_kbhit()) _getch();
			clearScreen();//Son Hyegang
			goMainMenuScreen();
			return;
		}

		setGameFlow(0); /* Reset the game */
		break;

	case 1:
		setCoordinate(x, MAP_ADJ_Y + 5);  printf("▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤");
		setCoordinate(x, MAP_ADJ_Y + 6);  printf("▤                              ▤");
		setCoordinate(x, MAP_ADJ_Y + 7);  printf("▤  +-----------------------+   ▤");
		setCoordinate(x, MAP_ADJ_Y + 8);  printf("▤  |      STAGE CLEAR      |   ▤");
		setCoordinate(x, MAP_ADJ_Y + 9);  printf("▤  +-----------------------+   ▤");
		setCoordinate(x, MAP_ADJ_Y + 10); printf("▤   YOUR SCORE: %6d         ▤", score);
		setCoordinate(x, MAP_ADJ_Y + 11); printf("▤                              ▤");
		setCoordinate(x, MAP_ADJ_Y + 12); printf("▤ Press any key to next stage. ▤");
		setCoordinate(x, MAP_ADJ_Y + 13); printf("▤                              ▤");
		setCoordinate(x, MAP_ADJ_Y + 14); printf("▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤");

		while (_kbhit()) _getch();
		input_command = _getch();

		setGameFlow(1); /* To next stage */
		break;

	case 2:
		setCoordinate(x, MAP_ADJ_Y + 5);  printf("▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤");
		setCoordinate(x, MAP_ADJ_Y + 6);  printf("▤                                      ▤");
		setCoordinate(x, MAP_ADJ_Y + 7);  printf("▤  +-------------------------------+   ▤");
		setCoordinate(x, MAP_ADJ_Y + 8);  printf("▤  | WINNER WINNER CHICKEN DINNER! |   ▤");
		setCoordinate(x, MAP_ADJ_Y + 9);  printf("▤  +-------------------------------+   ▤");
		setCoordinate(x, MAP_ADJ_Y + 10); printf("▤         YOUR SCORE: %6d           ▤", score);
		setCoordinate(x, MAP_ADJ_Y + 11); printf("▤                                      ▤");
		setCoordinate(x, MAP_ADJ_Y + 12); printf("▤         Cleared final stage.         ▤");
		setCoordinate(x, MAP_ADJ_Y + 13); printf("▤                                      ▤");
		setCoordinate(x, MAP_ADJ_Y + 14); printf("▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤▤");

		while (_kbhit()) _getch();
		input_command = _getch();
		setGameFlow(0); /* Reset the game */
		break;

	default:
		clearScreen();
		setCoordinate(x, MAP_ADJ_Y + 13); printf(" @System error: state end condition currupted.");
		exit(0);
	}
}

 

void clearScreen() {
	for (int i = 0; i < X; i++) {//Son Hyegang
		for (int j = 0; j < Y; j++) {
			gameScreen[i][j] = 0;
		}
	}
	block.pos_x = 0;
	block.pos_x = 0;
	block.num = 0;
	block.nextnum = 0;
	block.isactive = 0;

	block2.pos_x = 0;
	block2.pos_x = 0;
	block2.num = 0;//Son Hyegang
	block2.nextnum = 0;
	block2.isactive = 0;

	system("cls");
}
/* @ '↑↑↑DO NOT MODIFY.↑↑↑'ends. */

 

2.4. Results

 

 

 

 

 

반응형

'학부공부 > C_Basic' 카테고리의 다른 글

1. Project_KU Mobile Phone Bill Calculator[C Basic]  (0) 2021.11.07
1. Quiz[C Basic]  (0) 2021.11.07
10. File[C Basic]  (0) 2021.11.07
9. Struct[C Basic]  (0) 2021.11.07
8. Bit operator[C Basic]  (0) 2021.11.07

댓글