/*
#include<stdio.h>
#include <windows.h>
void gotoxy(int x, int y)
{
COORD Pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
int main()
{
char n;
printf ("안아줘요\n");
Sleep(1000);
printf ("a:안아준다 b:자리를 떠난다\n");
gotoxy(10, 2);
scanf ("%c", &n);
system("cls");
if (n=='a'){
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 14 );
printf ("안아줬어요");
SetConsoleTitle( "HAPPY" );
}
else if (n=='b'){
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 3 );
printf ("너무해요..");
SetConsoleTitle( "SAD..." );
}
else {
printf ("???");
}
return 0;
}
*/
/***
*****게임 기능 정리**********
1. 상하좌우 키보드로 플레이어 *을 움직인다
2. 아이템@를 획득하면 체력이 10 상승한다.
3. 함정 !를 건들이면 체력이 10 깎인다.
4. 체력이 0이 될 경우 게임을 끝낸다.
5. Q를 누르면 종료창을 띄운다. (a=종료, b=취소)
6. 30*30밖으로는 못나가도록한다, 맵의 경계선 표시 (숙제)
***/
#include <stdio.h>
#include <conio.h>
#include <windows.h>
// 상하좌우 상수값 설정
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
int hp=10;
void gotoxy(int x, int y)
{
COORD Pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
void init() //초기상태
{
gotoxy(50,2);
printf("체력 : %d",hp);
}
int main(void) {
char c;
srand(time(NULL)); //랜덤 시드 설정 (최초 한 번만!)
int random = rand()%30;
int random2=rand()%30;
int random3 = rand()%30;
int random4=rand()%30;
int x=10, y=10;
for (;;) {
if (_kbhit()) { //키보드 입력 확인 (true / false)
c = _getch(); // 방향키 입력시 224 00이 들어오게 되기에 앞에 있는 값 224를 없앰
if(c=='q')
{
gotoxy (0,30);
printf ("정말로 종료 하시겠습니까?\n예:a 아니요:b");
c=getch();
if (c=='a'){
return 0;
}
}
if (c == -32) { // -32로 입력되면
c = _getch(); // 새로 입력값을 판별하여 상하좌우 출력
switch (c) {
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
case UP:
y--;
break;
case DOWN:
y++;
break;
}
}
system("cls");
gotoxy(random, random2);
printf ("@");
if (random==x&&random2==y){
random = rand()%30;
random2 = rand()%30;
hp+=10;
}
gotoxy(random3, random4);
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 1 );
printf ("!");
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 15 );
if (random3==x&&random4==y){
hp-=10;
}
init();
gotoxy(x,y);
printf("*");
}
if (hp==0){
gotoxy(0, 31);
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 9);
printf ("Game over");
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 15 );
return 0;
}
}
return 0;
}