/*
#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 keyControl();
void inif();
void titleDraw();
int menuDraw();
int maplistDraw();
void infoDraw();
void drawMap(int*, int*);
void drawUI(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(" 스페이스 바를 누르면 메인화면으로 이동합니다.");
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"},
{"10000000000010000000000000000000000000000000000000000001"},
{"10000000000010000000000000000000000000000000000000000001"},
{"10000000000010000000000000000000000000000000000000000001"},
{"10000000000010000011111111111111111111111111111111100001"},
{"10000010000010000000000000000000000000000000000001100001"},
{"10000010000010000000000000000000000000000000000001100001"},
{"10000010000010000000000000000000000000000000000001100001"},
{"10000010000010000000000000000000000000000000000001100001"},
{"10000010000010000011111111111111111111111111111111100001"},
{"10000010000010000000000000000000000000000000000001100001"},
{"10000010000010000000000000000000000000000000000001100001"},
{"10000010000010000000000000000000000000000000000001100001"},
{"10000010000010000000000000000000000000000000000001100001"},
{"10000010000010000000000000000000000000000000000001100001"},
{"10000010000011111110000000000000000000000000000001100001"},
{"10000010000000000010000000000000000000000000000001100001"},
{"10000010000010000010000000000000000000000000000000000001"},
{"100000100000100k0010000000000000000000000000000001111111"},
{"10000010000010000010000000000000000000000000000001000001"},
{"10000010000010000010000000000000000000000000000001000001"},
{"100s001000001111111111111111111111111111111111111100q001"},
{"100000100000l0000000000000000000000000000000000000000001"},
{"11111111111111111111111111111111111111111111111111111111"},
};
char map2[25][56] =
{
{"11111111111111111111111111111111111111111111111111111111"},
{"10000000000000000000000000000000000000000000000000000001"},
{"10000000000000000000000000000000000000000000000000000001"},
{"10000000000000000000000000000000000000000000000000000001"},
{"10000000000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"100s001000000000000000000000000000000000000000000000q001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"10000010000000000000000000000000000000000000000000000001"},
{"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 == 'l')
{
setColor(blue, blue);
printf("$");
}
else if(temp == 'k')
{
setColor(yellow, black);
printf("*");
}
}
printf("\n");
}
setColor(white, black);
}
void gLoop(int mapCode)
{
int x, y;
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);
switch(keyControl())
{
case UP:
{
move(&x, &y, 0, -1);
break;
}
case DOWN:
{
move(&x, &y, 0, 1);
break;
}
case RIGHT:
{
move(&x, &y, 1, 0);
break;
}
case LEFT:
{
move(&x, &y, -1, 0);
break;
}
case SUBMIT:
{
playing = 0;
}
}
}
}
void move(int* x, int* y, int _x, int _y)
{
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 == '1')
{
}
}
void drawUI(int* x, int* y)
{
setColor(white, black);
wasd(3, 29);
printf("위치 : %02d, %02d", *x, *y);
setColor(yellow, black);
wasd(34, 29);
printf("아이템(추가예정)");
}