/*
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
*/
#include <stdio.h>
#include <windows.h>
#define UP 0
#define DOWN 1
#define LEFT 2
#define RIGHT 3
#define SUBMIT 4
enum
{
black,
blue,
green,
cyan,
red,
purple,
brown,
lightgray,
darkgray,
lightblue,
lightgreen,
lightcyan,
lightred,
lightpurple,
yellow,
white
};
void gLoop(int);
void move(int*, int*, int, int, int*, int*, int*);
int keyControl();
void inif();
void titleDraw();
int menuDraw();
int maplistDraw();
void infoDraw();
void drawMap(int*, int*);
void drawUI(int*, int*, int*, int*);
void wasd(int, int);
int main()
{
inif();
while(1)
{
titleDraw();
int menuCode = menuDraw();
if(menuCode == 0)
{
int n = maplistDraw();
if(n == 0)
{
gLoop(0);
}
else if(n == 1)
{
gLoop(1);
}
}
else if(menuCode == 1)
{
infoDraw();
}
else if(menuCode == 2)
{
return 0;
}
system("cls");
setColor(white, black);
}
return 0;
}
void infoDraw()
{
system("cls");
printf("\n\n");
printf(" [ 조작법 ]\n\n");
printf(" 이동 : W, A, S, D\n");
printf(" 선택 : 스페이스 바\n\n\n");
printf(" 개발자: 랑이 1004\n\n");
printf(" 스페이스 바를 누르면 메인화면으로 이동합니다.");
printf(" tip : 열쇠는 파란벽을 폭탄은 빨간벽을 부숩니다.");
while(1)
{
if(keyControl() == SUBMIT)
{
break;
}
}
}
int keyControl()
{
char temp = getch();
if(temp == 'w' || temp == 'W')
{
return UP;
}
else if(temp == 'a' || temp == 'A')
{
return LEFT;
}
else if(temp == 's' || temp == 'S')
{
return DOWN;
}
else if(temp == 'd' || temp == 'D')
{
return RIGHT;
}
else if(temp == ' ')
{
return SUBMIT;
}
}
void wasd(int x, int y)
{
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD Pos;
Pos.X = x;
Pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
void inif()
{
system("mode con cols=56 lines=35 | title 굉장나 엄청해한 게임");
HANDLE concoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO ConsoleCursor;
ConsoleCursor.bVisible = 0;
ConsoleCursor.dwSize = 1;
SetConsoleCursorInfo(concoleHandle, &ConsoleCursor);
}
void setColor(int forground, int background)
{
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
int code = forground + background * 16;
SetConsoleTextAttribute(consoleHandle, code);
}
void titleDraw()
{
char game[500][500]=
{" $$$$$$ %% %% ^^^^^ &&\n",
" $$ %% %% ^^ ^^ &&\n",
" $$ %%%% %% ^^ ^^ &&\n",
" $$ %% %% ^^ ^^ &&\n",
" %% %% ^^^^^ &&\n",
" \n",
" ######## \n",
" ## ## \n",
" ## ## \n",
" ######## \n" };
printf("\n\n");
printf(" [무려 1부 판매]\n");
printf("\n\n");
printf(" [굉장나고 엄청해한 게임]\n");
for(int i=0;i<strlen(game);i++)
{
for(int j=0;game[i][j]!=NULL;j++)
{
if(game[i][j]=='#')
{
setColor(lightgray, lightgray);
}
else if(game[i][j]=='$')
{
setColor(red, red);
}
else if(game[i][j]=='%')
{
setColor(brown, brown);
}
else if(game[i][j]=='^')
{
setColor(lightgreen, lightgreen);
}
else if(game[i][j]=='&')
{
setColor(blue, blue);
}
else
{
setColor(white, black);
}
printf("%c",game[i][j]);
}
}
}
int menuDraw()
{
int x = 20;
int y = 18;
wasd(x-2, y);
printf("> 게 임 시 작 ");
wasd(x, y+1);
printf("게 임 정 보 ");
wasd(x, y+2);
printf(" 종 료 ");
while(1)
{
int n = keyControl();
switch(n)
{
case UP:
{
if(y > 18)
{
wasd(x-2, y);
printf(" ");
wasd(x-2, --y);
printf(">");
}
break;
}
case DOWN:
{
if(y < 20)
{
wasd(x-2, y);
printf(" ");
wasd(x-2, ++y);
printf(">");
}
break;
}
case SUBMIT:
{
return y-18;
}
}
}
}
int maplistDraw()
{
int x = 24;
int y = 6;
system("cls");
printf("\n\n");
printf(" [맵선택]\n\n ");
wasd(x-2, y);
printf("> 쉬움");
wasd(x, y+1);
printf("어려움");
wasd(x, y+2);
printf("뒤로");
while(1)
{
int n = keyControl();
switch(n)
{
case UP:
{
if(y>6)
{
wasd(x-2, y);
printf(" ");
wasd(x-2, --y);
printf(">");
}
break;
}
case DOWN:
{
if(y<8)
{
wasd(x-2, y);
printf(" ");
wasd(x-2, ++y);
printf(">");
}
break;
}
case SUBMIT:
{
return y-6;
}
}
}
}
char tempMap[25][56]={};
char map1[25][56] =
{
{"11111111111111111111111111111111111111111111111111111111"},
{"11000000000000110000000000000000000000000000000000000011"},
{"11000000000000110000000000000000000000000000000000000011"},
{"11000000000000110000000000000000000000000000000000000011"},
{"11000000000000110001111111111111111111111111111111110011"},
{"11000001100000110000000000000000000000000000000000110011"},
{"11000001100000110000000000000000000000000000000000110011"},
{"11000001100000110000000000000000000000000000000000110011"},
{"11000001100000110000000000000000000000000000000000110011"},
{"11000001100000110001111111111111111111111111111111110011"},
{"11000001100000110000000000000000000000000000000000110011"},
{"11000001100000110000000000000000000000000000000000110011"},
{"11000001100000110000000000000000000000000000000000110011"},
{"11000001100000110000000000000000000000000000000000110011"},
{"11000001100000110000000000000000000000000000000000110011"},
{"11000001100000111111111000000000000000000000000000110011"},
{"11000001100000000000011000000000000000000000000000110011"},
{"11000001100000000000011000000000000000000000000000000011"},
{"110000011000001100k0011000000000000000000000000111111111"},
{"11000001100000110000011000000000000000000000000110000011"},
{"11000001100000110000011000000000000000000000000110000011"},
{"1100s0011000001111111111111111111111111111111111100q0011"},
{"11000001100000n00000000000000000000000000000000000000011"},
{"11111111111111111111111111111111111111111111111111111111"},
};
char map2[25][56] =
{
{"11111111111111111111111111111111111111111111111111111111"},
{"10000k100010001000010100000111100000001111u1000010100001"},
{"1011101000100010k001000101000011111111100001001010101001"},
{"101000101010101111b11111110100100000000001000110000001u1"},
{"1000101010101000000100000b011000111111111111111111111001"},
{"10111n101000100000k1011111111100100000010000000000000001"},
{"1000100010111111111101000000k101111100010000000000000001"},
{"111010001n1000000001010111111100001000010000000000000001"},
{"1n001111101000110101010000000n11101111010000000000000001"},
{"1011100000101111u0k1010111111100001001010000000000000001"},
{"100010111110011111110n0100000000000001010000000000000001"},
{"10101010u11101000111011100000000000000000000000000000001"},
{"101k1010000001010000010000000000000000000000000000000001"},
{"101110101111b1n11111110000000000000000000000000000000001"},
{"10001011100001000000010000000000000000000000000000000001"},
{"1110101u110111001111010000000000000000000000000000000001"},
{"10001010100011000110010010000000000000000000000000000001"},
{"100u1010111001101100011110000000000000000000000000000001"},
{"1n111010100011001101110010000000000000000000000000000001"},
{"100k1010101111011100000011111100000000000000000000000001"},
{"10001010100001001111110000000100000000000000000000000001"},
{"10s0101n101111000n0u10011b111110000000000000000000000001"},
{"10001000000001111111101100100000000000000000000000000001"},
{"1000100000000n0000b0001k0k100000000000000000000000000001"},
{"11111111111111111111111111111111111111111111111111111111"},
};
void drawMap(int* x, int* y)
{
system("cls");
int h, w;
for(h=0; h<25; h++)
{
for(w=0; w<56; w++)
{
char temp = tempMap[h][w];
if(temp == '0')
{
setColor(black, black);
printf(" ");
}
else if(temp == '1')
{
setColor(white, white);
printf("#");
}
else if(temp == 's')
{
*x = w;
*y = h;
setColor(lightcyan, black);
printf("A");
}
else if(temp == 'q')
{
setColor(yellow, black);
printf("@");
}
else if(temp == 'n')
{
setColor(blue, blue);
printf("$");
}
else if(temp == 'k')
{
setColor(yellow, black);
printf("*");
}
else if(temp == 'u')
{
setColor(darkgray, black);
printf("#");
}
else if(temp == 'b')
{
setColor(red, red);
printf("*");
}
}
printf("\n");
}
setColor(white, black);
}
void gLoop(int mapCode)
{
int x, y;
int key = 0;
int bom = 0;
int playing = 1;
if(mapCode == 0)
{
memcpy(tempMap, map1, sizeof(tempMap));
}
else if(mapCode == 1)
{
memcpy(tempMap, map2, sizeof(tempMap));
}
drawMap(&x, &y);
while(playing)
{
drawUI(&x, &y, &key, &bom);
switch(keyControl())
{
case UP:
{
move(&x, &y, 0, -1, &key, &playing, &bom);
break;
}
case DOWN:
{
move(&x, &y, 0, 1, &key, &playing, &bom);
break;
}
case RIGHT:
{
move(&x, &y, 1, 0, &key, &playing, &bom);
break;
}
case LEFT:
{
move(&x, &y, -1, 0, &key, &playing, &bom);
break;
}
case SUBMIT:
{
playing = 0;
}
}
}
}
void move(int* x, int* y, int _x, int _y, int* key, int* playing, int* bom)
{
char mapObject = tempMap[*y + _y][*x + _x];
setColor(white, black);
if(mapObject == '0')
{
wasd(*x, *y);
printf(" ");
setColor(lightcyan, black);
wasd(*x + _x, *y + _y);
printf("A");
*x += _x;
*y += _y;
}
else if(mapObject == 'k')
{
*key += 1;
tempMap[*y + _y][*x + _x] = '0';
wasd(*x + _x, *y + _y);
printf(" ");
}
else if(mapObject == 'n')
{
if(*key > 0)
{
*key -= 1;
tempMap[*y + _y][*x + _x] = '0';
setColor(white, black);
wasd(*x + _x, *y + _y);
printf(" ");
}
}
else if(mapObject == 'u')
{
*bom += 1;
tempMap[*y + _y][*x + _x] = '0';
wasd(*x + _x, *y + _y);
printf(" ");
}
else if(mapObject == 'b')
{
if(*bom > 0)
{
*bom -= 1;
tempMap[*y + _y][*x + _x] = '0';
setColor(white, black);
wasd(*x + _x, *y + _y);
printf(" ");
}
}
else if(mapObject == 'q')
{
*playing = 0;
wasd(22, 12);
char clearmassage[] = "*GAME CLEAR!*";
for(int aa = 0; clearmassage[aa]!=NULL; aa++)
{
setColor(cyan, black);
printf("%c", clearmassage[aa]); Sleep(150);
}
Sleep(1500);
setColor(white, black);
}
}
void drawUI(int* x, int* y, int* key, int* bom)
{
setColor(white, black);
wasd(3, 29);
printf("위치 : %02d, %02d", *x, *y);
setColor(yellow, black);
wasd(34, 28 );
printf("열쇠 : %d개 ", *key);
wasd(34, 30);
printf("폭탄 : %d개", *bom);
}