수다닷컴

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

랜덤 미로 생성 커서움직임...

은새

2026.06.14


질문 제목 : 랜덤 미로 생성 커서움직임...제가 커서를 움직이면 화면에 생성된 맵이 지워지고
맵크기랑 커서가 움직일수 있느 범위가 다른데 왜그런지 모르겠어서 여쭤봅니다질문 내용 : #include stdio.h
#include time.h
#include string.h
#include stdlib.h
#include ctype.h
#include windows.h
#include conio.h
#define width 20
#define height 20
#define n 1
#define e 4
#define s 2
#define w 8
#define left 75
#define right 77
#define up 72
#define down 80
#define point_x 3 //보드시작좌표x
#define point_y 4 //보드시작좌표y
#define delay 100
#define exit 50
//enum {n=1,e=4,s=2,w=8};
int dx[9];
int dy[9];
int opposite[9];
int directions[4] = {n, e, s, w};
int dx, dy, nx, ny;

int grid[width][height];
int carve_passage_from(int cx, int cy, int *grid[]);
void shuffle_array(int *array, int size);
void setcursor(int x,int y);
coord getcursor(void) ;
void removecursor(void) ;
void showcharacter(void);
void beginmagearrive(void){
int begin;
int arrive;
begin = grid[4][4];
printf(★,begin);
arrive = grid[20][20];
}
int carve_passage(int cx, int cy, int *grid[width][height]) {
int i;

shuffle_array(directions, 4);
for(i = 0; i 4; i++) {
dx = dx[directions[i]];
dy = dy[directions[i]];
// printf(길 찾기1=x:y - %d=%d:%d\n, directions[i], dx, dy);//유효한 셀 검사

nx = cx + dx;
ny = cy + dy;
if ( ((nx width) & (nx = 0)) & ((ny height) & (ny = 0)) ) {
//방문하지 않은 셀
if (grid[nx][ny] == 0) {
removecursor(); //커서 깜박이 지우기
//setcursor((int)grid[nx], (int)grid[ny]); //보드 시작좌표
//printf(유효한 셀 x,y %d:%d\n, nx, ny);
grid[cx][cy] = (int)((int)grid[cx][cy] | (int)directions[i]);
grid[nx][ny] = (int)((int)grid[nx][ny] | (int)opposite[directions[i]]);
if (grid[nx][ny] == 1){
// printf(유효하지 않은 셀 x,y %d:%d\n, nx, ny);
}
carve_passage(nx, ny, grid);
}
}
}
}
void setcursor(int x,int y)
{
coord pos;
pos.x=x;
pos.y=y;
setconsolecursorposition(getstdhandle(std_output_handle),pos);
}
coord getcursor(void)
{
coord curpoint;
console_screen_buffer_info pos;
getconsolescreenbufferinfo(getstdhandle(std_output_handle),&pos);
curpoint.x=pos.dwcursorposition.x;
curpoint.y=pos.dwcursorposition.y;
return curpoint;
}
void removecursor(void)
{
console_cursor_info cur;
getconsolecursorinfo(getstdhandle(std_output_handle),&cur);
cur.bvisible=0;
setconsolecursorinfo(getstdhandle(std_output_handle),&cur);
}
void showcharacter(void)

{
coord cur=getcursor();
printf(9);
setcursor(cur.x, cur.y);
}
int detect(int x,int y)
{
int x1=directions[x];
int y1=directions[y];
// 커서 위치 얻기
coord cur=getcursor();
// 미로내에서의 위치 계산.
x1=cur.x+x;
y1=cur.y+y;
x1=x1/2-2;
y1=y1-2;

// 미로 밖에 있는지 검사
if(!((x1 =0 && x1 width) && (y1 =0 && y1 height)))
{
setcursor(cur.x+x, cur.y+y);
}

//배열을 넘어가지 않는이유?
if(grid[nx][ny]==1)
printf(_);
//미션성공
else if(grid[nx][ny]==0)
printf(|);

else
return 0;
}
void removecharacter_set(int x, int y)
{
int value=detect(x,y);
if(value==0)
{
coord cur=getcursor();

printf( );
setcursor(cur.x+x, cur.y+y);
}
else if(value==1)
{
coord cur=getcursor();
printf(_);
setcursor(cur.x+x, cur.y+y);
}
else if(value==exit)
{
setcursor(10,15);
printf(성공);
system(pause);
exit(1);
}
}
void character_static(void)
{
int kb;
setcursor(2,2); //케릭터시작위치
while(1)
{
while(!_kbhit())
{
showcharacter();
sleep(delay);
}
kb=_getch();
switch(kb)
{
case up:
removecharacter_set(0,-1);
break ;
case down:
removecharacter_set(0,1);
break ;
case right:
removecharacter_set(2,0);
break ;
case left:
removecharacter_set(-2,0);
break ;
}
}
}
void shuffle_array(int *array, int size) {
int i;
for( i=0; i(size - 1); i++) {
int r = i + (rand() % (size - i));
int temp = array[i];
array[i] = array[r];
array[r] = temp;
}
}

int main(void) {
int x,y;

coord cur=getcursor();
opposite[n] = s;
opposite[e] = w;
opposite[s] = n;
opposite[w] = e;
dx[n] = 0;
dx[e] = 1;
dx[s] = 0;
dx[w] = -1;
dy[n] = -1;
dy[e] = 0;
dy[s] = 1;
dy[w] = 0;
/** seed the random generator **/
srand((unsigned int)time((time_t *)null));
memset(&grid[0], 0, sizeof(grid));
carve_passage(0, 0, (int)grid);
////////////////////////////////
/** display the grid **/

printf(☆);//맵의 시작 맨처음
for(x = 0; x (width); x++) {
printf(☆);//맵의 맨윗줄
}
printf(\n);//개행해서 그 다음 줄 부터 출력

for(y = 0; y height; y++) {
printf(|);//맵의 세로 테두리
for(x = 0; x width; x++) {
printf( ((grid[x][y] & s) != 0)? /*맵의통로*/:_/*맵의길*/);
if((grid[x][y] & e) != 0){
printf((( (grid[x][y] | grid[x + 1][y]) & s) != 0) ? /*맵의통로*/:_/*맵의길*/);
} else {
printf(|);//맵의 가로 테두리
}
}
printf(\n);
}
character_static();
}

신청하기





COMMENT

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

번호 제 목 글쓴이 날짜
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
2751445 도저히 풀 수가 없네요.... (2) 신당 2026-10-15
2751412 어제부터 계속 해도.........안되는.... (1) 족장 2026-10-14
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

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