#include<iostream>

#include<windows.h> 

#include<conio.h> 

#include<time.h> 


using namespace std;


void gotoxy(int x, int y);

void map(); // 맵

void bPoint(); // 볼 위치

void jump(); // 볼 점프


int x = 2, y = 9, loopX = 0; // 볼 위치 x, y 변수

char inputKey = 0; // 입력키 확인

int hd[20], hdCount=0; // 허들, 허들 라운드 수

int hdCheck = 0; // 허들 충돌 체크 변수


int main() {

srand(time(NULL));


int rNum; // 임의의 수를 받을 변수 

// 허들 초기화

for (int i = 0; i < 20; i++){

rNum = rand() % 25 + 10;

hd[i] = rNum;

}


do

{

while (!kbhit())

{

system("cls");

map();

bPoint();

Sleep(200);

if (hdCheck == 1) break;

}

jump();

} while (hdCheck == 0);

gotoxy(2, 11);

cout << " 장애물에 충돌하여 게임을 종료합니다." << endl;



return 0;

}

void gotoxy(int x, int y)

{


COORD Pos = { x - 1, y - 1 };


SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);


}

void map() {

printf("공튕기기");

gotoxy(hd[hdCount], 9);

printf("▲");

gotoxy(2, 10);

printf("───────────────────\n");

}

void bPoint() {

gotoxy(x, y);

cout << "●";

if (x < 40 && loopX == 0) {

x += 2;

if (x == 38) {

loopX = 1;

hdCount++;

}

if (hdCount == 20)

hdCount = 0;

if (hd[hdCount] == x && y == 9) hdCheck = 1;

if (loopX == 0)

{

if ((hd[hdCount] + 1) == x && y == 9) {

hdCheck = 1;

}

}

else {

if ((hd[hdCount] - 1) == x && y == 9) {

hdCheck = 1;

}

}

}

else {

x -= 2;

if (x == 2) {

loopX = 0;

hdCount++;

}

if (hdCount == 20)

hdCount = 0;

if (hd[hdCount] == x && y == 9) hdCheck = 1;

if (loopX == 0)

{

if ((hd[hdCount] + 1) == x && y == 9) {

hdCheck = 1;

}

}

else {

if ((hd[hdCount] - 1) == x && y == 9) {

hdCheck = 1;

}

}

}

}

void jump() {

inputKey = getch();

if (inputKey == 72) {

if (loopX == 0) {

gotoxy(x - 2, y);

cout << "  ";

}

else {

gotoxy(x + 2, y);

cout << "  ";

}


if (y == 9) {

y--;

if (x < 40 && loopX == 0) {

x += 2;

if (x == 38) {

loopX = 1;

hdCount++;

}

if (hdCount == 20)

hdCount = 0;

}

else {

x -= 2;

if (x == 2) {

loopX = 0;

hdCount++;

}

if (hdCount == 20)

hdCount = 0;

}

gotoxy(x, y);

cout << "●";

Sleep(200);


gotoxy(x, y);

cout << "  ";

if (x < 40 && loopX == 0) {

x += 2;

if (x == 38) {

loopX = 1;

hdCount++;

}

if (hdCount == 20)

hdCount = 0;

}

else {

x -= 2;

if (x == 2) {

loopX = 0;

hdCount++;

}

if (hdCount == 20)

hdCount = 0;

}

gotoxy(x, y);

cout << "●";

Sleep(200);


gotoxy(x, y);

cout << "  ";

y++;

if (x < 40 && loopX == 0) {

x += 2;

if (x == 38) {

loopX = 1;

hdCount++;

}

if (hdCount == 20)

hdCount = 0;

if (hd[hdCount] == x && y == 9) hdCheck = 1;

if (loopX == 0)

{

if ((hd[hdCount] + 1) == x && y == 9) {

hdCheck = 1;

}

}

else {

if ((hd[hdCount] - 1) == x && y == 9) {

hdCheck = 1;

}

}

}

else {

x -= 2;

if (x == 2) {

loopX = 0;

hdCount++;

}

if (hdCount == 20)

hdCount = 0;

if (hd[hdCount] == x && y == 9) hdCheck = 1;

if (loopX == 0) 

{

if ((hd[hdCount] + 1) == x && y == 9) {

hdCheck = 1;

}

}

else {

if ((hd[hdCount] - 1) == x && y == 9) {

hdCheck = 1;

}

}

}

gotoxy(x, y);

cout << "●";

}

}

}


ㅡㅡ 구동화면 ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

그냥 공이 좌우로 정해진 공간 만큼 오가면서 랜덤으로 생성되는 장애물을 


화살표(↑) 키를 눌러 점프해 피하는 게임


보다시피 장애물에 닿으면 죽음 끝






'SGA 스터디 > C++ 코딩' 카테고리의 다른 글

c 자유 낙하 공식  (0) 2015.11.12
strcpy 문자열 복사 , strcmp 문자열 비교 함수 작성  (0) 2015.10.12
카드 뒤집기  (0) 2015.08.14
월남뽕  (0) 2015.08.13
별찍기  (0) 2015.08.11

+ Recent posts