게임 개발 도중 이유를 못찾겠어요
비
질문 제목 :3가지 질문1.별이 생성은 되나 소수 몇개가 되지 않음
2.아군 대포알과 적군 대포알이 충돌시 두 구조체를 멈추게할방법
3.별이 일정 시간 지나면 사라지도록(이부분은 그냥 부탁입니다)
안보이시는분 드래그 해주세요
질문 내용 :
#include stdio.h
#include stdlib.h
#include windows.h
#include conio.h
#include time.h
#include dos.h
///////////////////////////////////////
#define wally 37//아군의 대포가 나오는 y좌표
#define enbulmax 20//적의 대포수 제한
#define enbulmax2 20
#define enbulmax3 30
#define arbulmax 10//아군의 대포수 여러개 못쏘개 제한
//////////////////////////////////////
void table(void);
void ingame(void);
void startmenu(void);
void dos_size(void); ;
struct enbul1//적의 대포알
{
int x,wait,y;
};
typedef struct enbul1 enbul;//적의 대포알 타입변경(포인터 지정을 위해)
struct arbul1//아군 대포알
{
int x,y,wait;
};
typedef struct arbul1 arbul;
void gotoxy(int x, int y)//좌표갑지정함수 정의
{
coord pos={x-1, y-1};
setconsolecursorposition(getstdhandle(std_output_handle), pos);
}
void spawn_enbul(enbul *en){
int pos;
pos=rand()%6;
if(pos==0) en-x=3;
else if(pos==1) en-x=7;
else if(pos==2) en-x=11;
else if(pos==3) en-x=15;
else if(pos==4) en-x=19;
else if(pos==5) en-x=23;
en-y=2;
}//적의 대포알 스폰 장소void enbul_wait(enbul *en)
{
en-wait=rand()%20;
}
int main()
{
int levels;//레벨
int arbp;
int tx;//엔터 받는용
int j;
int i; //무한함수용 변수
int loop=0;//게임 시작선언 변수
int hp=10;//체력
int speed;//게임 스피드
int score;//점수
int am;
enbul enb[enbulmax];
arbul arb[10000];
char *levelname[velname[4]={eazy,normal,hard ,hell};
/////////////////////////
levels=1;//레벨지정
speed=100-levels*30;//속도지정
score=0;//첫스코어
am=0;
/////////////////////////지정변수들
dos_size();
srand(time(null));
startmenu();
tx=getch();
if(tx==13)//enter를 누르면 loop를 1로변경및 화면 지움
{
loop=1;
system(cls);
}
else startmenu();
ingame();
for(i=0;ienbulmax;++i)//적대포탄생
{
spawn_enbul(&enb[i]);
} while(loop)//게임시작
{
sleep(speed);
for(i=0;ienbulmax;i++)//아군 대포알과 적군 대포알 충돌검사
{
for(j=0;jam;j++)
{
if(enb[i].x==arb[j].x && enb[i].y==arb[j].y)
{
gotoxy(arb[j].x,arb[j].y);
printf(★);
gotoxy(enb[i].x,enb[i].y);
printf(★);
enb[i].x=30;
enb[i].y=41;
arb[j].x=30;
arb[j].y=1;
}
}
} for (i=0;ienbulmax;++i) // 적대포 이동
{
if (enb[i].wait0)
enb[i].wait--;
else
{
if (enb[i].ywally)
{
gotoxy(enb[i].x,enb[i].y);
printf( );
enb[i].y+=1;
gotoxy(enb[i].x,enb[i].y);
printf(●);
}
else
{
gotoxy(enb[i].x,enb[i].y);
printf( );
spawn_enbul(&enb[i]);
enbul_wait(&enb[i]);
gotoxy(enb[i].x,enb[i].y);
}
}
}
if(kbhit())
{
arbp=getch();
switch(arbp)
{
case 49:
arb[am].x=3;
arb[am].y=wally;
am++;
break;
case 50:
arb[am].x=7;
arb[am].y=wally;
am++;
break;
case 51:
arb[am].x=11;
arb[am].y=wally;
am++;
break;
case 52:
arb[am].x=15;
arb[am].y=wally;
am++;
break;
case 53:
arb[am].x=19;
arb[am].y=wally;
am++;
break;
case 54:
arb[am].x=23;
arb[am].y=wally;
am++;
default:
break;
}
}
for(j=0;jam;j++)
{
if(arb[j].y2)
{
gotoxy(arb[j].x,arb[j].y);
printf( );
arb[j].y-=1;
gotoxy(arb[j].x,arb[j].y);
printf(○);
}
else
{
gotoxy(arb[j].x,arb[j].y);
printf( );
}
}}//while(loop)끝
system(pausenull);
}//main끝
void ingame(void)//맵생성
{
iint i,j;
int ary[40][15] = {
{9,9,9,9,9,9,9,9,9,9,9,9,9},
{9,0,9,0,9,0,9,0,9,0,9,0,9},
{9,0,9,0,9,0,9,0,9,0,9,0,9},
{9,0,9,0,9,0,9,0,9,0,9,0,9},
{9,0,9,0,9,0,9,0,9,0,9,0,9},
{9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printf(▦);
}
else
{
printf( );
}
}
printf(\n);
}
}
void dos_size(void)
{
system(mode con: cols=45 lines=41);
}
void startmenu(void)
{
int a=0;
gotoxy(4,15); printf(┌─────────┐\n);
gotoxy(4,16); printf(│ │\n);
gotoxy(4,17); printf(│ 조종법 : 키패드│\n);
gotoxy(4,18); printf(│ │\n);
gotoxy(4,19); printf(│ enter를 누르면 │\n);
gotoxy(4,20); printf(│게임이 시작됩니다. │\n);
gotoxy(4,21); printf(││\n);
gotoxy(4,22); printf(│ │\n);
gotoxy(4,23); printf(│ │\n);
gotoxy(4,24); printf(└─────────┘\n);
gotoxy(80,24);
}
질문시작:
main함수가 시작되 얼마 안되 부분에서 인데요
arb가 아군 대포알을 뜻하고 즉,키보드 누르면 나오는 구조체..
enb가 적군 대포알에 속합니다 랜덤으로생성되어 출력되는
while문 시작후에 바로 둘이 부딪쳤을때 별이 표시되도록해놨는데요;;
그런데 실행해보니 부딪치면 별이 대다수가 출력되긴 된다만 안되는 것도있더군요.
이 부분에 대해자세한 설명좀 해주세요...
그리고 아군 대포알 과 적군 대포알 이 두 구조첵의 부딪쳤을때 진행을 멈추게할 방법 없을까요?
저런 식으로 해놓으면 쉽게 오류가 유발될거 같아서요
그리고 별이일정시간 지나면 사라지게할 방법 같은거 있으면 알려주세요 ㅎㅎ;
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |