KakaoTalk_20190606_001802318.png
  • 246x0w
Welcome
Curriculum
Install&Go
Board
실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
  • 카테고리
  • 전체 게시물
  • 내 게시물
YANNDCH
2019년 11월 16일

inThisGame

게시판: 소스 코드 제출

#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];

}

}




}



**/


댓글 0개
0
댓글
댓글 0개
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호