수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

지렁이게임 만들다가 자꾸 이유모를 버그가

츠키

2025.11.10


질문 제목 : 질문 내용 :

#include stdio.h
#include stdlib.h
#include windows.h
#include string.h
#include time.h
#define map_width 96
#define map_height 40
#define left 75
#define right 77
#define up 72
#define down 80
typedef struct jirung2{
int x;
int y;
}jirung2;
void gotoxy(int x, int y);
void drawmap();
void gamestart();
void jirungremove();
void printjirung(int direction,jirung2 food);
void jirungmove(int direction);
void changedirection(int *direction);
int crashcheck();
void putfood(jirung2 *food);
void extendslength();
int checkeatfood(jirung2 food);
jirung2 jirung[15];
int length;
int main(int argc, char *argv[])
{
system(mode con: cols=120 lines=40);
gotoxy(0,0);

gamestart();
getch();
return 0;
}
void gotoxy(int x, int y)
{
coord pos = {x, y};
setconsolecursorposition(getstdhandle(std_output_handle), pos);
}
void drawmap(){
int i;
gotoxy(0,0);
printf(┌);
for(i=1; imap_width/2; i++){
gotoxy(i*2,0);
printf(─);
}
gotoxy(map_width,0);
printf(┐);

for(i=1; imap_height-1; i++){
gotoxy(0,i);
printf(│);
gotoxy(map_width,i);
printf(│);
}

gotoxy(0,map_height-1);
printf(└);
for(i=1; imap_width/2; i++){
gotoxy(i*2,map_height);
printf(─);
}
gotoxy(map_width,map_height-1);
printf(┘);
}
void gamestart(){

int direction=1;
int i;
jirung2 food;
length=4;
jirung[0].x=5;
jirung[0].y=3;
jirung[1].x=4;
jirung[1].y=3;
jirung[2].x=3;
jirung[2].y=3;
jirung[3].x=2;
jirung[3].y=3;
drawmap();
putfood(&food);
printjirurintjirung(direction,food);
getch();
for(i=0; ;i++){
if(i%10==0){
jirungremove();
jirungmove(direction);
if(crashcheck()){
gotoxy(100,20);
printf(crashed!!);
}
i=0;
}
if(kbhit()) changedirection(&direction);
if(checkeatfood(food)){
extendslength();
putfood(&food);
}
sleep(10);
}
}
void printjirung(int direction,jirung2 food){
int i;
char shape[4];
gotoxy(food.x*2,food.y);
printf(★);
switch(direction){
case 0 : strcpy(shape,▲);
break;
case 1 :strcpy(shape,▶);
break;
case 2 : strcpy(shape,▼);
break;
case 3 : strcpy(shape,◀);
break;
}
for(i=0;ilength; i++){
gotoxy(jirung[i].x*2,jirung[i].y);
if(i==0) printf(%s,shape);
else printf(■);
}
}
void jirungmove(int direction){
int i;
for(i=length-1; i0; i--){
jirung[i]=jirung[i-1];
}
gotoxy(jirung[0].x*2,jirung[0].y);
printf(■);
switch(direction){
case 0 :
jirung[0].y--;
gotoxy(jirung[0].x*2,jirung[0].y);
printf(▲);
break;
case 1 : jirung[0].x++;
gotoxy(jirung[0].x*2,jirung[0].y);
printf(▶);
break;
case 2 : jirung[0].y++;
gotoxy(jirung[0].x*2,jirung[0].y);
printf(▼);
break;
case 3 : jirung[0].x--;
gotoxy(jirung[0].x*2,jirung[0].y);
printf(◀);
break;
}
}
void jirungremove(){
if(jirung[length-1].x==jirung[length-2].x && jirung[length-1].y==jirung[length-2].y) return ;
gotoxy(jirung[length-1].x*2,jirung[length-1].y);
p; printf( );
}
void changedirection(int *direction){
char ch;
ch=getch();
switch(ch){
case up : *direction=0;
break;
case right : *direction=1;
break;
case down : *direction=2;
break;
case left : *direction=3;
break;
}

}
int crashcheck(){
int i;
for(i=1; ilength; i++){
if(jirung[0].x==jirung[i].x && jirung[0].y==jirung[i].y) return 1;
}
if(jirung[0].x*22 || jirung[0].x*2=map_width || jirung[0].y1 || jirung[0].y=map_height-1) return 1;

return 0;
}
void putfood(jirung2 *food){
srand(time(null));
int i;
(*food).x=rand()%(map_width/2-2)+2;
(*food).y=rand()%(map_height-2)+1;
while(1){
for(i=0; ilength; i++){
if(jirung[i].x==(*food).x && jirung[i].y==(*food).y){
break;
}
if(i==length-1){
gotoxy((*food).x*2,(*food).y);
printf(★);
return ;
}
}
}
}
int checkeatfood(jirung2 food){
int i;
for(i=0; ilength; i++){
if(jirung[i].x==food.x && jirung[i].y==food.y) return 1;
}
return 0;
}
void extendslength(){
length++;
jirung[length-2]=jirung[length-1];
}지렁이게임 만드는데 먹이를 먹으면 자꾸왼쪽 위에 저부분이 지워지고 먹이를 먹은부분이 저렇게 뭔가 남네요 ㅠㅠ

도저히 이유를 모르겠는데 학교과제라 그냥 무시할수도없고 아 제발 도와주세요

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2752142 더블 포인터 관련 최대최소값 구하기 (2) 풀잎 2026-10-21
2752115 c언어 이상한질문 (4) 모드니 2026-10-21
2752085 문자열을 랜덤하게 출력해서 대체,삽입,삭제 횟수를 각가 표시하고 그걸 표 형태로 출력 슬아s 2026-10-20
2752056 포인터 && 배열 질문요~ (2) 해찬나래 2026-10-20
2752031 x^n 구하는 코드 짜봤는데 값이 틀려요 ㅠㅠ 세실 2026-10-20
2752000 나 정말 미치겠어요..ㅠㅜ (4) 다이 2026-10-20
2751978 문자열 질문이요.. 초시계 2026-10-19
2751945 숫자 맞추는 프로그램이요 ㅠㅠ (1) 동은 2026-10-19
2751917 C언어 이중 연결 관련 질문합니다. 유우 2026-10-19
2751888 return의 정확한 의미좀 알려주세요 (3) 올해1살 2026-10-19
2751857 포인터 배열 (2) 터큰 2026-10-18
2751831 연산자? 질문입니다 (2) 진주 2026-10-18
2751800 C언어 기초질문입니다.. (3) 핫블랙 2026-10-18
2751739 파일 출력을 구조체로 받을 때, 파일의 끝을 판별하는 방법을 알려주세요. (2) 얼 2026-10-17
2751715 unresolved external symbol 에러... 이룩 2026-10-17
2751686 변수 설정에 관한 질문입니다. 꽃달 2026-10-17
2751655 자료구조 연습문제 한무릎 2026-10-17
2751631 gets 함수 질문이요. (4) 해늘 2026-10-16
2751553 퀵정렬 소스인데 주석좀 달아주세요 (1) 싴흐한세여니 2026-10-16
2751528 저기 이거하는법좀 질문.. (2) 가람슬기 2026-10-15
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com