QuizWit

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ QuizWit ] in KIDS
글 쓴 이(By): parsec ( 먼 소 류 )
날 짜 (Date): 2003년 3월 14일 금요일 오전 08시 43분 55초
제 목(Title):  


장서가 프로그램...
움직일 수 있는 곳이면 여러 칸도 움직일 수 있도록 업데이트했습니다.
사람의 움직임은 flood-fill algorithm을 이용해서 움직일 수 있는 길이
있으면 어디든 점프할 수 있도록 했습니다:

다음 함수 추가:
int isconnected(int pos_x, int pos_y, int dest_x, int dest_y);
int four_search(int pos_x, int pos_y, int dest_x, int dest_y);

---

int four_search(int pos_x, int pos_y, int dest_x, int dest_y)
{
        if(pos_x == dest_x && pos_y == dest_y) return 1;
        if(pos_x < 1 || pos_x > ROOM_WIDTH ||
                pos_y < 1 || pos_y > ROOM_HEIGHT)
                return 0;
        if(path[pos_x-1][pos_y-1] == 0) {
                path[pos_x-1][pos_y-1] = 1;
                if(four_search(pos_x, pos_y+1, dest_x, dest_y)==1) return 1;
                if(four_search(pos_x, pos_y-1, dest_x, dest_y)==1) return 1;
                if(four_search(pos_x+1, pos_y, dest_x, dest_y)==1) return 1;
                if(four_search(pos_x-1, pos_y, dest_x, dest_y)==1) return 1;
        }
        return 0;
}

int isconnected(int pos_x, int pos_y, int dest_x, int dest_y)
{
        int i, j;
        for(i=0; i<ROOM_WIDTH; i++)for(j=0; j<ROOM_HEIGHT; j++)
                path[i][j] = (room[i][j]==0)? 0 : 2;
        path[pos_x-1][pos_y-1] = 0;
        if(four_search(pos_x, pos_y, dest_x, dest_y)==1) return 1;
        else return 0;
}

void move_case(int pos_x, int pos_y, int dest_x, int dest_y)
{
        int dx, dy, i;
        t_bookcase * bcp;
        if(pos_x<1 || pos_x>ROOM_WIDTH  ||
           pos_y<1 || pos_y>ROOM_HEIGHT ||
           dest_x<1|| dest_x>ROOM_WIDTH ||
           dest_y<1|| dest_y>ROOM_HEIGHT) return;
        dx = dest_x - pos_x;
        dy = dest_y - pos_y;
        bcp = get_casep(get_caseid(pos_x, pos_y));
        if(
                (bcp != NULL && room[dest_x-1][dest_y-1] == 0) &&
                ( ((bcp->dir==HOR && bcp->y==dest_y) ||
                   (bcp->dir==VER && bcp->x==dest_x)) ||
                bcp->dir == ANY) )
        {
                if(bcp->dir == HOR) for(i=1; i<=abs(dx); i++)
                        if(room[pos_x+((dx>0)?i:-i)-1][pos_y-1] != 0) return;
                if(bcp->dir == VER) for(i=1; i<=abs(dy); i++)
                        if(room[pos_x-1][pos_y+((dy>0)?i:-i)-1] != 0) return;
                if(bcp->dir == ANY)
                        if(isconnected(pos_x, pos_y, dest_x, dest_y)==0)
                                return;
                room[pos_x-1][pos_y-1] = 0;
                room[dest_x-1][dest_y-1] = bcp->id;
                bcp->x = dest_x;
                bcp->y = dest_y;
        }
        else
                printf("illegal move.\n");
}


                                            ... May the source be with you!
[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.