⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maze.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
		maze[cur_sq_x][cur_sq_y] |= ( DOOR_IN_TOP >> ((newdoor+2)%4) );		/* if end square set path length and save path */		if ( maze[cur_sq_x][cur_sq_y] & END_SQUARE ) {			path_length = sqnum;			for ( i=0; i<path_length; i++) {				save_path[i].x = move_list[i].x;				save_path[i].y = move_list[i].y;				save_path[i].dir = move_list[i].dir;			}		}	} while (1);} /* end of create_maze() */choose_door() /* pick a new path */{	int candidates[3];	register int num_candidates;	num_candidates = 0;topwall:	/* top wall */	if ( maze[cur_sq_x][cur_sq_y] & DOOR_IN_TOP )		goto rightwall;	if ( maze[cur_sq_x][cur_sq_y] & DOOR_OUT_TOP )		goto rightwall;	if ( maze[cur_sq_x][cur_sq_y] & WALL_TOP )		goto rightwall;	if ( maze[cur_sq_x][cur_sq_y - 1] & DOOR_IN_ANY ) {		maze[cur_sq_x][cur_sq_y] |= WALL_TOP;		maze[cur_sq_x][cur_sq_y - 1] |= WALL_BOTTOM;		draw_wall(cur_sq_x, cur_sq_y, 0);		goto rightwall;	}	candidates[num_candidates++] = 0;rightwall:	/* right wall */	if ( maze[cur_sq_x][cur_sq_y] & DOOR_IN_RIGHT )		goto bottomwall;	if ( maze[cur_sq_x][cur_sq_y] & DOOR_OUT_RIGHT )		goto bottomwall;	if ( maze[cur_sq_x][cur_sq_y] & WALL_RIGHT )		goto bottomwall;	if ( maze[cur_sq_x + 1][cur_sq_y] & DOOR_IN_ANY ) {		maze[cur_sq_x][cur_sq_y] |= WALL_RIGHT;		maze[cur_sq_x + 1][cur_sq_y] |= WALL_LEFT;		draw_wall(cur_sq_x, cur_sq_y, 1);		goto bottomwall;	}	candidates[num_candidates++] = 1;bottomwall:	/* bottom wall */	if ( maze[cur_sq_x][cur_sq_y] & DOOR_IN_BOTTOM )		goto leftwall;	if ( maze[cur_sq_x][cur_sq_y] & DOOR_OUT_BOTTOM )		goto leftwall;	if ( maze[cur_sq_x][cur_sq_y] & WALL_BOTTOM )		goto leftwall;	if ( maze[cur_sq_x][cur_sq_y + 1] & DOOR_IN_ANY ) {		maze[cur_sq_x][cur_sq_y] |= WALL_BOTTOM;		maze[cur_sq_x][cur_sq_y + 1] |= WALL_TOP;		draw_wall(cur_sq_x, cur_sq_y, 2);		goto leftwall;	}	candidates[num_candidates++] = 2;leftwall:	/* left wall */	if ( maze[cur_sq_x][cur_sq_y] & DOOR_IN_LEFT )		goto donewall;	if ( maze[cur_sq_x][cur_sq_y] & DOOR_OUT_LEFT )		goto donewall;	if ( maze[cur_sq_x][cur_sq_y] & WALL_LEFT )		goto donewall;	if ( maze[cur_sq_x - 1][cur_sq_y] & DOOR_IN_ANY ) {		maze[cur_sq_x][cur_sq_y] |= WALL_LEFT;		maze[cur_sq_x - 1][cur_sq_y] |= WALL_RIGHT;		draw_wall(cur_sq_x, cur_sq_y, 3);		goto donewall;	}	candidates[num_candidates++] = 3;donewall:	if ( --lockcount == 0) {		lockcount = LOCK_COUNT_1;		maze_unlock(gfx->gfx_pixwin);		if (global_restart)			return;		pw_lock(gfx->gfx_pixwin, &pwrect);	}	if (num_candidates == 0)		return ( -1 );	if (num_candidates == 1)		return ( candidates[0] );	return ( candidates[ get_random(num_candidates) ] );} /* end of choose_door() */backup() /* back up a move */{	sqnum--;	cur_sq_x = move_list[sqnum].x;	cur_sq_y = move_list[sqnum].y;	return ( sqnum );} /* end of backup() */draw_maze_border() /* draw the maze outline */{	register int i, j;	pw_lock(gfx->gfx_pixwin, &pwrect);	for ( i=0; i<maze_size_x; i++) {		if ( maze[i][0] & WALL_TOP ) {			pw_vector(gfx->gfx_pixwin,				border_x + SQ_SIZE_X * i,				border_y,				border_x + SQ_SIZE_X * (i+1),				border_y,				PIX_SRC, 1);		}		if ((maze[i][maze_size_y - 1] & WALL_BOTTOM)) {			pw_vector(gfx->gfx_pixwin,				border_x + SQ_SIZE_X * i,				border_y + SQ_SIZE_Y * (maze_size_y),				border_x + SQ_SIZE_X * (i+1),				border_y + SQ_SIZE_Y * (maze_size_y),				PIX_SRC, 1);		}	}	for ( j=0; j<maze_size_y; j++) {		if ( maze[maze_size_x - 1][j] & WALL_RIGHT ) {			pw_vector(gfx->gfx_pixwin,				border_x + SQ_SIZE_X * maze_size_x,				border_y + SQ_SIZE_Y * j,				border_x + SQ_SIZE_X * maze_size_x,				border_y + SQ_SIZE_Y * (j+1),				PIX_SRC, 1);		}		if ( maze[0][j] & WALL_LEFT ) {			pw_vector(gfx->gfx_pixwin,				border_x,				border_y + SQ_SIZE_Y * j,				border_x,				border_y + SQ_SIZE_Y * (j+1),				PIX_SRC, 1);		}	}	if (logo_x != -1) {	    if (colorwindows)		pw_rop(gfx->gfx_pixwin, border_x + 3 + SQ_SIZE_X * logo_x, 			border_y + 3 + SQ_SIZE_Y * logo_y, 			64, 64, PIX_SRC | PIX_COLOR(3), &icon_mpr, 0, 0);	    else		pw_rop(gfx->gfx_pixwin, border_x + 3 + SQ_SIZE_X * logo_x, 			border_y + 3 + SQ_SIZE_Y * logo_y, 			64, 64, PIX_SRC, &icon_mpr, 0, 0);	}	maze_unlock( gfx->gfx_pixwin );	if (global_restart)		return;	if (gfx->gfx_flags & GFX_DAMAGED)		gfxsw_handlesigwinch(gfx);	draw_solid_square( start_x, start_y, start_dir, 1);	draw_solid_square( end_x, end_y, end_dir, 1);} /* end of draw_maze() */draw_wall(i, j, dir) /* draw a single wall */	int i, j, dir;{	switch (dir) {		case 0:			pw_vector(gfx->gfx_pixwin,				border_x + SQ_SIZE_X * i, 				border_y + SQ_SIZE_Y * j,				border_x + SQ_SIZE_X * (i+1), 				border_y + SQ_SIZE_Y * j,				PIX_SRC, 1);			break;		case 1:			pw_vector(gfx->gfx_pixwin,				border_x + SQ_SIZE_X * (i+1), 				border_y + SQ_SIZE_Y * j,				border_x + SQ_SIZE_X * (i+1), 				border_y + SQ_SIZE_Y * (j+1),				PIX_SRC, 1);			break;		case 2:			pw_vector(gfx->gfx_pixwin,				border_x + SQ_SIZE_X * i, 				border_y + SQ_SIZE_Y * (j+1),				border_x + SQ_SIZE_X * (i+1), 				border_y + SQ_SIZE_Y * (j+1),				PIX_SRC, 1);			break;		case 3:			pw_vector(gfx->gfx_pixwin,				border_x + SQ_SIZE_X * i, 				border_y + SQ_SIZE_Y * j,				border_x + SQ_SIZE_X * i, 				border_y + SQ_SIZE_Y * (j+1),				PIX_SRC, 1);			break;	}} /* end of draw_wall */draw_solid_square(i, j, dir, color) /* draw a solid square in a square */	register int i, j, dir, color;{	int op;	if (colorwindows || color == 0)		op = PIX_SRC | PIX_COLOR(color);	else		op = PIX_SRC | PIX_COLOR(1);	switch (dir) {		case 0: pw_rop(gfx->gfx_pixwin, 			border_x + 3 + SQ_SIZE_X * i, 			border_y - 3 + SQ_SIZE_Y * j, 			SQ_SIZE_X - 6, SQ_SIZE_Y, 			op, 0, 0, 0);			break;		case 1: pw_rop(gfx->gfx_pixwin, 			border_x + 3 + SQ_SIZE_X * i, 			border_y + 3 + SQ_SIZE_Y * j, 			SQ_SIZE_X, SQ_SIZE_Y - 6, 			op, 0, 0, 0);			break;		case 2: pw_rop(gfx->gfx_pixwin, 			border_x + 3 + SQ_SIZE_X * i, 			border_y + 3 + SQ_SIZE_Y * j, 			SQ_SIZE_X - 6, SQ_SIZE_Y, 			op, 0, 0, 0);			break;		case 3: pw_rop(gfx->gfx_pixwin, 			border_x - 3 + SQ_SIZE_X * i, 			border_y + 3 + SQ_SIZE_Y * j, 			SQ_SIZE_X, SQ_SIZE_Y - 6, 			op, 0, 0, 0);			break;	}	if ( --lockcount == 0) {		lockcount = LOCK_COUNT_2;		maze_unlock(gfx->gfx_pixwin);		if (global_restart)			return;		pw_lock(gfx->gfx_pixwin, &pwrect);	}} /* end of draw_solid_square() */solve_maze() /* solve it with graphical feedback */{	int i;	/* plug up the surrounding wall */	maze[start_x][start_y] |= (WALL_TOP >> start_dir);	maze[end_x][end_y] |= (WALL_TOP >> end_dir);	/* initialize search path */	i = 0;	path[i].x = end_x;	path[i].y = end_y;	path[i].dir = -1;	/* do it */	lockcount = LOCK_COUNT_2;	pw_lock(gfx->gfx_pixwin, &pwrect);	while (1) {		if ( ++path[i].dir >= 4 ) {			i--;			draw_solid_square( (int)(path[i].x), (int)(path[i].y), 				(int)(path[i].dir), 0);			if (global_restart)				return;		}		else if ( ! (maze[path[i].x][path[i].y] & 				(WALL_TOP >> path[i].dir))  && 				( (i == 0) || ( (path[i].dir != 				(path[i-1].dir+2)%4) ) ) ) {			enter_square(i);			i++;			if ( maze[path[i].x][path[i].y] & START_SQUARE ) {				return;			}		} 	maze_unlock(gfx->gfx_pixwin);	if (global_restart)		return;	}} /* end of solve_maze() */enter_square(n) /* move into a neighboring square */	int n;{	draw_solid_square( (int)path[n].x, (int)path[n].y, 		(int)path[n].dir, 2);	path[n+1].dir = -1;	switch (path[n].dir) {		case 0: path[n+1].x = path[n].x;			path[n+1].y = path[n].y - 1;			break;		case 1: path[n+1].x = path[n].x + 1;			path[n+1].y = path[n].y;			break;		case 2: path[n+1].x = path[n].x;			path[n+1].y = path[n].y + 1;			break;		case 3: path[n+1].x = path[n].x - 1;			path[n+1].y = path[n].y;			break;	}} /* end of enter_square() */maze_unlock(pw)	struct pixwin *pw;{        pw_unlock(pw);        if (gfx->gfx_flags & GFX_DAMAGED) {                gfxsw_handlesigwinch(gfx);		global_restart = 1;                }        if (gfx->gfx_flags & GFX_RESTART) {                gfx->gfx_flags &= ~GFX_RESTART;		global_restart = 1;                }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -