#include <stdio.h>
#include <math.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <Windows.h>
#define SIZE 10
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
int map[SIZE][SIZE];
void generateMap(int k);
void gotoxy(int x,int y);
int main()
{
char key;
int k=0;
int i, j;
int playerX, playerY;
scanf("%d", &k);
system("cls");
generateMap(k);
for(i=0; i<SIZE; i++)
{
for(j=0; j<SIZE; j++)
{
switch(map[i][j])
{
case 1: //wall
printf("#");
break;
case 9: //player
printf("+");
playerX = i;
playerY = j;
break;
case 2: //star
printf("*");
break;
case 3: //ball
printf("O");
break;
default:
printf(" ");
}
}
printf("\n");
}
for(;;)
{
gotoxy(15, 2);
printf("%d %d", playerX, playerY);
for(i=0; i<10; i++) {
for(j=0; j<10; j++) {
gotoxy(23+j, 2+i);
printf("%d", map[i][j]);
}
}
//system("cls");
key = getch();
gotoxy(playerX, playerY);
switch(key)
{
case UP:
if( map[playerX-1][playerY] != 1 )
{
if ( map[playerX-1][playerY] == 3 && map[playerX-2][playerY] == 0 )
{
printf(" ");
//playerY--;
map[playerX][playerY] = 0;
playerY--;
map[playerX][playerY] = 9;
printf("+");
map[playerX-1][playerY] = 3;
gotoxy(playerX-1, playerY);
printf("O");
}
else {
}
printf(" ");
map[playerX][playerY] = 0;
playerY--;
map[playerX][playerY] = 9;
gotoxy(playerX, playerY);
}
break;
case DOWN:
if( map[playerX+1][playerY] != 1 )
{
if ( map[playerX+1][playerY] == 3 && map[playerX+1][playerY] != 1 )
{
printf(" ");
playerY++;
gotoxy(playerX+2, playerY);
printf("O");
}
printf(" ");
map[playerX][playerY] = 0;
playerY++;
map[playerX][playerY] = 9;
gotoxy(playerX, playerY);
printf("+");
}
break;
case RIGHT:
if( map[playerX][playerY+1] != 1 )
{
if ( map[playerX][playerY+1] == 3 && map[playerX][playerY+2] != 1 )
{
printf(" ");
playerX++;
gotoxy(playerX, playerY+2);
printf("O");
}
printf(" ");
map[playerX][playerY] = 0;
playerX++;
map[playerX][playerY] = 9;
gotoxy(playerX, playerY);
printf("+");
}
break;
case LEFT:
if( map[playerX][playerY-1] != 1 )
{
if ( map[playerX][playerY-1] == 3 && map[playerX][playerY-2] != 1 )
{
printf(" ");
playerX--;
gotoxy(playerX, playerY-2);
printf("O");
}
printf(" ");
map[playerX][playerY] = 0;
playerX--;
map[playerX][playerY] = 9;
gotoxy(playerX, playerY);
printf("+");
}
break;
}
}
}
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void generateMap(int k)
{
int i, j;
// 1 = wall
// 2 = star
// 3 = ball
// 9 = player
if(k==1) // map step
{
int m[SIZE][SIZE] =
{
{1,1,1,1,1,1,1,1,1,1},
{1,9,0,0,0,3,0,0,2,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1}
};
for(i=0; i<SIZE; i++)
{
for(j=0; j<SIZE; j++)
{
map[i][j] = m[i][j];
}
}
}
else if(k==2)
{
}
}
// 특수문자 작업중 \\
/**
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <Windows.h>
#define SIZE 20
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
int map[SIZE/2][SIZE];
void generateMap(int k);
void gotoxy(int x,int y);
int main()
{
char key;
int k=0;
int i, j;
int playerX, playerY;
scanf("%d", &k);
system("cls");
generateMap(k);
for(i=0; i<SIZE; i++)
{
for(j=0; j<SIZE; j++)
{
switch(map[i][j])
{
case 1:
printf("▩");
break;
case 9:
printf("●");
playerX = i;
playerY = j;
break;
default:
printf("□");
}
}
printf("\n");
}
for(;;)
{
//system("cls");
key = getch();
gotoxy(40, 4);
printf("%d %d\n", playerX, playerY);
gotoxy(playerX, playerY);
switch(key)
{
case LEFT:
if( map[playerX-2][playerY] != 1 )
{
printf("□");
playerX-2;
gotoxy(playerX, playerY);
printf("●");
gotoxy(playerX, playerY);
}
break;
case RIGHT:
if( map[playerX+2][playerY] != 1 )
{
printf("□");
playerX+2;
gotoxy(playerX, playerY);
printf("●");
gotoxy(playerX, playerY);
}
break;
case DOWN:
if( map[playerX][playerY+2] != 1 )
{
printf("□");
playerY+=2;
gotoxy(playerX, playerY);
printf("●");
gotoxy(playerX, playerY);
}
break;
case UP:
if( map[playerX][playerY-2] != 1 )
{
printf("□");
playerY-2;
gotoxy(playerX, playerY);
printf("●");
gotoxy(playerX, playerY);
}
break;
}
}
}
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void generateMap(int k)
{
int i, j;
// 1 = wall
// 2 = star
// 3 = ball
// 9 = player
if(k==1) // map step
{
int m[SIZE/2][SIZE] =
{
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,9,0,0,0,0,0,0,0,0,0,0,0,2,0,3,0,1,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};
for(i=0; i<SIZE/2; i++)
{
for(j=0; j<SIZE; j++)
{
map[i][j] = m[i][j];
}
}
}
**/