안녕하세요! ☃ jh설인☃ 입니다!
오늘은 프로그램언어를 통해 간단한 게임을 만들어보았는데요 (버그가 있을 수 있어요)
제가 아직 못 찾은 버그가 있을지 모르겠네요.
찾아주셔서 알려주시면 감사하겠습니다.
만든 프로그램과 소스를 공유하겠습니다.
■소스■
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#define start 3
#define Width 60
#define Height 30
typedef struct modaa
{
int x;
int y;
}
moda;
void modf(moda *plays, moda *modb, int a);
void play(moda * plays, moda *modb);
void xyz(int x, int y);
void bba(int a);
void end(int a);
void gstart();
void panel();
void hlpe();
int crash(moda *plays, int a);
int agth = start;
int direction = 2;
int speed = 200;
int i;
int main(void)
{
xyz(20,12);
printf("아무키나 누르면 시작합니다..");
getch();
system("cls");
xyz(20,14);
printf("세상에서 가장 큰 뱀을 만들자!");
getch();
system("cls");
gstart();
system("modae con cols=90 lines=40");
xyz(20,13);
}
void gstart()
{
moda *plays = (moda *)malloc(sizeof(moda) * start);
moda modb;
srand(time(NULL));
play(plays, &modb);
while(1)
{
char key;
key = getch();
switch(key)
{
case 72:
if (direction != 1) direction = 0;
break;
case 80:
if (direction != 0) direction = 1;
break;
case 75:
if (direction != 3) direction = 2;
break;
case 77:
if (direction != 2) direction = 3;
break;
}
while(!kbhit())
{
if (!(plays[agth-1].x == plays[agth-2].x && plays[agth-1].y == plays[agth-2].y))
{
xyz( plays[agth-1].x, plays[agth-1].y); printf(" ");
}
for (i = agth - 1 ; i > 0 ; i--)
{
plays[i] = plays[i-1];
}
switch(direction)
{
case 0:
plays[0].y -= 1;
break;
case 1:
plays[0].y += 1;
break;
case 2:
plays[0].x -= 2;
break;
case 3:
plays[0].x += 2;
break;
}
xyz(plays[0].x,plays[0].y);
printf("◇");
if( modb.x == plays[0].x && modb.y == plays[0].y)
{
agth++;
plays = (moda *) realloc(plays,sizeof(moda) * agth);
plays[agth-1] = plays[agth-2];
modf(plays,&modb,agth);
bba(agth);
if(agth %5 == 0)
speed -= 20;
}
Sleep(speed);
if(crash(plays,agth))
goto END;
}
}
END:
end(agth);
free(plays);
}
void play(moda * plays, moda *modb)
{
panel();
for(i = 0; i < start; i++)
{
plays[i].x = 20+2*i;
plays[i].y = 8;
xyz(plays[i].x,plays[i].y);
printf("◆");
}
modf(plays,modb,start);
bba(start);
hlpe();
}
void xyz(int x, int y)
{
COORD Pos = {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Pos);
}
void modf(moda *plays, moda *modb, int a)
{
srand(time(NULL));
do{
modb->x = rand()%28 * 2+2;
modb->y = rand()%28+1;
for (i = 0 ; i < a ; i++)
{
if(modb->x == plays[i].x && modb->y == plays[i].y)
{
break;
}
if(i == a-1)
{
xyz(modb->x, modb->y);
printf("☆");
return;
}
}
}while(1);
}
void panel()
{
for (i = 0 ; i < Width/2 ; i++)
{
printf("□");
}
for (i = 0 ; i < Height ; i++)
{
xyz(0,i);
printf("□");
}
for (i = 0 ; i < Height ; i++)
{
xyz(Width,i);
printf("□");
}
xyz(0,Height-1);
for (i = 0 ; i < Width/2 ; i++)
{
printf("□");
}
}
int crash(moda *plays, int a)
{
if(plays[0].x < 2 || plays[0].x > 58 || plays[0].y < 1 || plays[0].y > 28)
{
return 1;
}
for (i = 1 ; i < a ; i++)
{
if (plays[0].x == plays[i].x && plays[0].y == plays [i].y)
return 1;
}
return 0;
}
void bba(int a)
{
xyz(61,1);
printf("현재 크기:%dM",a);
}
void hlpe()
{
xyz(61,10);
printf("추억의 뱀꼬리 게임");
xyz(61,15);
printf("자제작");
xyz(61,18);
printf("jhSnowman");
xyz(61,22);
printf("ver:0.a.1");
xyz(61,26);
printf("버그제보");
xyz(61,28);
printf("i177@hanmail.net");
}
void end(int a)
{
system("cls");
xyz(20,13);
printf("최종 크기 점수: %dM",a);
xyz(20,14);
system("pause");
}
■ 구동 이미지■
과연 몇 점까지 클리어할 수 있을지 궁금하네요 추후 코볼로도 게임을 만들 예정입니다!