/*
#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*);
int keyControl();
void inif();
void titleDraw();
int menuDraw();
int maplistDraw();
void infoDraw();
void drawMap(int*, int*);
void drawUI(int*, 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 : 열쇠는 파란벽을 폭탄은 빨간벽을 부숩니다.");
printf(" tip : 락픽은 초록벽을 부수며, 3개밖에 없습니다.");
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"},
{"10000k1000100010000101000001111kkkkkkkk11u10000010100001"},
{"1011101000100010k001000101000011111111100001001010101001"},
{"101000101010101111b11111110100100000000001000110000001u1"},
{"1000101010101000000100000b011000111111111111111111111q11"},
{"10111n101000100000k101111111110000010011000000b000001r11"},
{"1000100010111111111101000000k101110000011101111111101r11"},
{"111010001n100000000101011111110000101011000b0000uh101r11"},
{"1n001111101000110101010000000n111n111001011111111n100001"},
{"1011100000101111u0k101011111101k000001010001000110111111"},
{"100010111110011111110n010000101011100n01010b11u010000001"},
{"10101010u1110100011101110000b00010111111k110011011111101"},
{"101k1010000001010000011101111111100000011100u1hn00000101"},
{"101110101111b1n1111111k100b01010n01001000101111101110101"},
{"10001011100001000000010111101000111111110101k010k1h10101"},
{"1110101u11011100111101000000101110u100k10100100011010101"},
{"1000101010001100011001001101100010010111010111110n01n1n1"},
{"100u1010111001101100011110010001100000000100n00000110101"},
{"1n111010100011001101110010000111011011111111111011110101"},
{"100k10101011110111000000111111000000000000000b1000010101"},
{"1000101010000100111111000000011111111111111b111110110101"},
{"10s0101n101111000n0u10011b11111k010000000000100010010101"},
{"100010000000011111111011001kkk11010011111111101001n1n1n1"},
{"1000100000000n0000b0001k0k1kkk00000000000n00n0n100000001"},
{"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("*");
}
else if(temp == 'h')
{
setColor(cyan, black);
printf("!");
}
else if(temp == 'r')
{
setColor(green, green);
printf("*");
}
}
printf("\n");
}
setColor(white, black);
}
void gLoop(int mapCode)
{
int x, y;
int key = 0;
int bom = 0;
int rac = 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, &rac);
switch(keyControl())
{
case UP:
{
move(&x, &y, 0, -1, &key, &playing, &bom, &rac);
break;
}
case DOWN:
{
move(&x, &y, 0, 1, &key, &playing, &bom, &rac);
break;
}
case RIGHT:
{
move(&x, &y, 1, 0, &key, &playing, &bom, &rac);
break;
}
case LEFT:
{
move(&x, &y, -1, 0, &key, &playing, &bom, &rac);
break;
}
case SUBMIT:
{
playing = 0;
}
}
}
}
void move(int* x, int* y, int _x, int _y, int* key, int* playing, int* bom, int* rac)
{
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 == 'h')
{
*rac += 1;
tempMap[*y + _y][*x + _x] = '0';
wasd(*x + _x, *y + _y);
printf(" ");
}
else if(mapObject == 'r')
{
if(*rac > 0)
{
*rac -= 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, int* rac)
{
setColor(white, black);
wasd(3, 29);
printf("위치 : %02d, %02d", *x, *y);
setColor(yellow, black);
wasd(34, 27 );
printf("열쇠 : %d개 ", *key);
wasd(34, 29);
printf("폭탄 : %d개", *bom);
wasd(34, 31);
printf("락픽 : %d개", *rac);
}
*/
//자료구조 : 자료 : data (정수, 실수, 문자... )를 어떻게 하면 효율적으로 관리 할 수 있는지?
// 자료를 어떤 구조로 사용하면 더 효율적으로 코딩 할 수 있을지??
//스택 큐 정렬 이진탐색 그래프( dfs/bfs) -> 자료구조 A 레벨 끝
//-> 유니티 수업을 들을 수 있는 자격이 생겨!!!
/*
#include <stdio.h>
int stack[50]={}; // 스택 생성
int top = -1; // top : 마지막 데이터의 위치 ( 스택이 비어있다 -> top==-1 )
void view()
{
if(top==-1) printf("stack is empty.\n");
// stack 내용 전부 보기
for(int i=0;i<=top;i++)
printf("%d ",stack[i]);
printf("top = %d \n",top);
}
void push(int x)
{
top++;
stack[top] = x;
}
int pop()
{
if(top==-1) return -1; //// 스택이 비었는지 확인하고, 비어있다면 top을 감소하지 않도록!!!!!
return stack[top--];
}
int main()
{
// stack에 3 값을 push
push(3);
view();
// stack 5 값을 push
push(5);
view();
////스택에 있는 모든 값을 빼고싶어!!! 전부 pop 하고싶어 없애고싶어
while(top != -1)
{
pop();
}
// stack에서 데이터 pop
top--;
view();
// stack에서 데이터를 pop하고, 그 데이터를 보여줘라
printf("pop data is %d\n",stack[top]);
top--;
view();
// stack pop 함수
printf("%d\n",pop());
view();
return 0;
}
*/
#include <stdio.h>
int stack[1001]={};
int top =-1;
void (int a)
{
top++;
stack[top]=a;
}
int pop()
{
if(top==-1)
{
return -1;
}
return stack[top--];
}
int main()
{
int s, i;
scanf("%d", &s);
for(i=1; i<=s; i++)
{
scanf("%d", &stack[i]);
}
push(i)
printf("%d", pop()):
return 0;
}