#include "turboc.h"
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define STAGE 3
void MapDrow();
void KeyDown();
int Cheracter();
int nx, ny;
int ston;
int n_stage;
char chMap[STAGE][10][15] = {
{
"###############",
"#STAGE 1 ######",
"###############",
"##### #########",
"##### #########",
"##### #O#O####",
"#####! @@ @ O##",
"###### ####",
"###############",
"###############"
},
{
"###############",
"###############",
"### ! ###",
"##### #########",
"##### # # ###",
"##### #O#O####",
"##### @@ @ O##",
"###### ####",
"### #########",
"###############"
},
{
"###############",
"###############",
"###############",
"#####O#O#######",
"##### # #######",
"### @@O#O####",
"### # @#@####",
"###### ! ####",
"###############",
"###############"
},
};
void main(){
MapDrow();
n_stage = 0;
while(1){
Cheracter();
KeyDown();
}
}
void MapDrow(){
int i;
int j;
system("cls");
for(i=0 ; i<10; i++){
for(j=0; j<15; j++){
printf("%c", chMap[n_stage][i][j]);
}
printf("\n");
}
}
void KeyDown(){
int key;
int x = 0;
int y = 0;
key = getch();
switch(key){
case UP:
x = -1;
break;
case DOWN:
x = 1;
break;
case LEFT:
y = -1;
break;
case RIGHT:
y = 1;
break;
}
if(chMap[n_stage][nx+x][ny+y] =='#' || chMap[n_stage][nx+x][ny+y] == 'O'){
chMap[n_stage][nx][ny] = '!';
}else if(chMap[n_stage][nx+x][ny+y] == '@'){
if(chMap[n_stage][nx+x*2][ny+y*2] == 'O'){
chMap[n_stage][nx+x*2][ny+y*2] = '@';
chMap[n_stage][nx+x][ny+y] = '!';
}else if(chMap[n_stage][nx+x*2][ny+y*2] == ' '){
chMap[n_stage][nx+x*2][ny+y*2] = '@';
chMap[n_stage][nx+x][ny+y] = '!';
}else if(chMap[n_stage][nx+x*2][ny+y*2] == '#' || chMap[n_stage][nx+x*2][ny+y*2] == '@'){
chMap[n_stage][nx+x][ny+y] = '@';
chMap[n_stage][nx][ny] = '!';
}
}else{
chMap[n_stage][nx+x][ny+y] = '!';
}
MapDrow();
}
int Cheracter(){
int x, y;
ston = 0;
for(x =0; x<10; x++){
for(y=0; y<15; y++){
if(chMap[n_stage][x][y] == '!'){
nx = x;
ny = y;
chMap[n_stage][x][y] = ' ';
}
if(chMap[n_stage][x][y] == 'O'){
ston++;
}
}
}
gotoxy(20, 0);printf("남은 구멍 : %d", ston);
if(ston == 0){
n_stage++;
if(n_stage == STAGE){
gotoxy(0,15);exit(0);
}
MapDrow();
Cheracter();
}
'프로그래밍 > C, C++, C#' 카테고리의 다른 글
[Win32 API]미니게임-테트리스/푸시푸시/지뢰찾기 (3) | 2011.12.22 |
---|---|
[C++]randomize() (0) | 2011.10.03 |
[c언어]금액 잔돈 변환 (0) | 2011.03.30 |