#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
#define LEFT_WALL 1
#define TOP_WALL 1
#define RIGHT_WALL 42
#define BOTTOM_WALL 22
#define MIN_X (LEFT_WALL + 2)
#define MAX_X (RIGHT_WALL - 2)
#define TARGET_Y 3
#define HORSE_Y 20
#define GAME_COUNT 10 //
#define COLOR_WHITE 7
#define COLOR_GRAY 8
#define COLOR_LIGHT_GREEN 10
#define COLOR_LIGHT_CYAN 11
#define COLOR_LIGHT_RED 12
#define COLOR_LIGHT_YELLOW 14
void Difficulty_Level(void);
void gotoxy(int x, int y);
void hide_cursor(void);
void setColor(int color);
void intro_game(void);
void draw_rectangle(void);
void display_text(int turn, int success_count);
int random_target_x(void);
void draw_target(int target_x);
int move_horse_until_key(void);
int shoot_arrow(int horse_x, int target_x);
void game_control(int *success_count, int target_x);
int level;
int aim_hack;
int critical_hack;
int super_critical_hack;
int your_score = 0;
int combo = 0;
//-------------------------------------------
int main(){
int turn;
int target_x;
srand((unsigned int)time(NULL));
hide_cursor();
intro_game();
Difficulty_Level();
for(turn=1; turn<=GAME_COUNT; turn++){
system("cls");
draw_rectangle();
target_x = random_target_x();
draw_target(target_x);
display_text(turn, your_score);
game_control(&your_score, target_x);
}
system("cls");
setColor(COLOR_LIGHT_YELLOW);
printf("Game FINISHED!\n\n");
setColor(COLOR_WHITE);
printf("Total Chance : %d\n", GAME_COUNT);
printf("Score : %d\n", your_score);
printf("Combo : %d\n", combo);
return 0;
}
//-------------------------------------------
void Difficulty_Level(void){
system("cls");
printf("난이도를 설정해 주세요.\n");
printf("난이도(배) 만큼 어려워 집니다.\n");
printf("자연수만 입력해 주세요.\n");
while(1){
scanf("%d", &level);
if(level>0)break;
}
printf("\n\n");
printf("아무 키나 누르면 시작합니다");
getch();
}
void gotoxy(int x, int y){
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void hide_cursor(void){
CONSOLE_CURSOR_INFO cursorInfo;
cursorInfo.dwSize = 1;
cursorInfo.bVisible = FALSE;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
}
void setColor(int color){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color);
//ex) setColor(14);
}
void intro_game(void){
system("cls");
printf("Horse Arrow Game\n\n");
printf("말이 자동으로 좌우로 움직입니다.\n");
printf("SPACE 키를 눌러 화살을 쏘세요.\n");
printf("화면 상단의 표적을 맞추세요.\n\n");
printf("당신에게는 %d번의 기회가 있습니다.\n\n", GAME_COUNT);
printf("난이도를 설정하려면 아무 키나 누르세요.");
getch();
}
void draw_rectangle(void){
int x, y;
system("cls");
setColor(COLOR_GRAY);
for(x=LEFT_WALL; x<=RIGHT_WALL; x++){
gotoxy(x, TOP_WALL);
printf("-");
gotoxy(x, BOTTOM_WALL);
printf("-");
}
for(y=TOP_WALL; y<=BOTTOM_WALL; y++){
gotoxy(LEFT_WALL, y);
printf("|");
gotoxy(RIGHT_WALL, y);
printf("|");
}
gotoxy(LEFT_WALL, TOP_WALL);
printf("┌");
gotoxy(RIGHT_WALL, TOP_WALL);
printf("┐");
gotoxy(LEFT_WALL, BOTTOM_WALL);
printf("└");
gotoxy(RIGHT_WALL, BOTTOM_WALL);
printf("┘");
setColor(COLOR_WHITE);
}
void display_text(int turn, int your_score){
setColor(COLOR_LIGHT_CYAN);
gotoxy(RIGHT_WALL + 4, 3);
if(turn == GAME_COUNT){
printf("Turn : %2d / %2d (Last Turn)", turn, GAME_COUNT);
}else {
printf("Turn : %2d / %2d", turn, GAME_COUNT);
}
gotoxy(RIGHT_WALL + 4, 4);
printf("Score : %2d", your_score);
gotoxy(RIGHT_WALL + 4, 5);
printf("Combo : %2d (점수에는 콤보의 절반이 소수점 첫쨰자리에서 내림되어 반영)", combo);
gotoxy(RIGHT_WALL + 4, 7);
printf("Press SPACE");
gotoxy(RIGHT_WALL + 4, 8);
printf("to shoot.");
setColor(COLOR_WHITE);
}
int random_target_x(void){
int range = MAX_X - MIN_X + 1;
return MIN_X + rand() % range;
}
void draw_target(int target_x){
setColor(COLOR_LIGHT_RED);
gotoxy(target_x, TARGET_Y);
printf("T");
setColor(COLOR_WHITE);
}
int move_horse_until_key(void){
int x = MIN_X;
int dir = 1;
int key;
while(1){
setColor(COLOR_LIGHT_YELLOW);
gotoxy(x, HORSE_Y);
printf("H");
setColor(COLOR_WHITE);
Sleep(50/level);
if(kbhit()){
key = getch();
if(key == ' '){
aim_hack = 0;
gotoxy(x, HORSE_Y);
printf(" ");
return x;
}
if(key == 'a' || key == 'A'){
aim_hack = 1;
gotoxy(x, HORSE_Y);
printf(" ");
return x;
}
if(key == 'c' || key == 'C'){
critical_hack = 1;
}
if(key == 's' || key == 'S'){
super_critical_hack = 1;
}
if(key == 'l' || key == 'L'){
(your_score)++;
setColor(COLOR_LIGHT_CYAN);
gotoxy(RIGHT_WALL + 4, 4);
printf("Score : %2d", your_score);
setColor(COLOR_WHITE);
}
}
gotoxy(x, HORSE_Y);
printf(" ");
x += dir;
if(x >= MAX_X){
x = MAX_X;
dir = - 1;
}
if(x <= MIN_X){
x = MIN_X;
dir = 1;
}
}
}
int shoot_arrow(int horse_x, int target_x){
int y;
if(aim_hack == 1){
horse_x = target_x;
}
for(y=HORSE_Y-1; y>=TARGET_Y; y--){
setColor(COLOR_LIGHT_GREEN);
gotoxy(horse_x, y);
printf("^");
setColor(COLOR_WHITE);
Sleep(25/level);
if(y > TARGET_Y){
gotoxy(horse_x, y);
printf(" ");
}
}
if(horse_x == target_x){
setColor(COLOR_LIGHT_RED);
gotoxy(target_x, TARGET_Y);
printf("*");
setColor(COLOR_WHITE);
gotoxy(RIGHT_WALL + 4, 9);
if(rand() % 100<5 || super_critical_hack == 1){
printf("Super Critical!");
super_critical_hack = 0;
return 3;
}else if(rand() % 10 == 0 || critical_hack == 1){
printf("Critical!");
critical_hack = 0;
return 2;
}else {
printf("Hit!");
return 1;
}
}else {
gotoxy(horse_x, TARGET_Y);
printf(" ");
draw_target(target_x);
gotoxy(RIGHT_WALL + 4, 9);
printf("Miss");
combo = 0;
return 0;
}
}
void game_control(int *your_score, int target_x){
int horse_x;
int result;
horse_x = move_horse_until_key();
result = shoot_arrow(horse_x, target_x);
if(result == 1){
(*your_score)+=(1 + combo/2);
combo++;
}else if(result == 2){
(*your_score)+=(2 + combo/2);
combo++;
}else if(result == 3){
(*your_score)+=(5 + combo/2);
combo++;
}
gotoxy(1, BOTTOM_WALL + 2);
printf("다음 턴을 위해 아무 키나 누르세요.");
getch();
}
//치트 목록
//a or A : 에임 핵
//c or C : 크리티컬 확정 발동
//s or S : 슈퍼 크리티컬 확정 발동
//l or L : 점수 올리기
To embed this project on your website, copy the following code and paste it into your website's HTML: