static void add_mazes(void) { short i, j; short start; short maze_percent; if (cur_level > 1) { start = get_rand(0, (MAXROOMS-1)); maze_percent = (cur_level * 5) / 4; if (cur_level > 15) { maze_percent += cur_level; } for (i = 0; i < MAXROOMS; i++) { j = ((start + i) % MAXROOMS); if (rooms[j].is_room & R_NOTHING) { if (rand_percent(maze_percent)) { rooms[j].is_room = R_MAZE; make_maze(get_rand(rooms[j].top_row+1, rooms[j].bottom_row-1), get_rand(rooms[j].left_col+1, rooms[j].right_col-1), rooms[j].top_row, rooms[j].bottom_row, rooms[j].left_col, rooms[j].right_col); hide_boxed_passage(rooms[j].top_row, rooms[j].left_col, rooms[j].bottom_row, rooms[j].right_col, get_rand(0, 2)); } } } } }
/* * prepare_maze_level * DESCRIPTION: Prepare for a maze of a given level. Fills the game_info * structure, creates a maze, and initializes the display. * INPUTS: level -- level to be used for selecting parameter values * OUTPUTS: none * RETURN VALUE: 0 on success, -1 on failure * SIDE EFFECTS: writes entire game_info structure; changes maze; * initializes display */ static int prepare_maze_level (int level) { int i; /* loop index for drawing display */ /* * Record level in game_info; other calculations use offset from * level 1. */ game_info.number = level--; /* Set per-level parameter values. */ if ((game_info.maze_x_dim = MAZE_MIN_X_DIM + 2 * level) > MAZE_MAX_X_DIM) game_info.maze_x_dim = MAZE_MAX_X_DIM; if ((game_info.maze_y_dim = MAZE_MIN_Y_DIM + 2 * level) > MAZE_MAX_Y_DIM) game_info.maze_y_dim = MAZE_MAX_Y_DIM; if ((game_info.initial_fruit_count = 1 + level / 2) > 6) game_info.initial_fruit_count = 6; if ((game_info.time_to_first_fruit = 300 - 30 * level) < 120) game_info.time_to_first_fruit = 120; if ((game_info.time_between_fruits = 300 - 60 * level) < 60) game_info.time_between_fruits = 60; if ((game_info.tick_usec = 20000 - 1750 * level) < 5000) game_info.tick_usec = 5000; /* Initialize dynamic values. */ game_info.map_x = game_info.map_y = SHOW_MIN; /* Create a maze. */ if (make_maze (game_info.maze_x_dim, game_info.maze_y_dim, game_info.initial_fruit_count) != 0) return -1; /* Set logical view and draw initial screen. */ set_view_window (game_info.map_x, game_info.map_y); for (i = 0; i < SCROLL_Y_DIM; i++) (void)draw_horiz_line (i); /* Return success. */ return 0; }
static void make_maze(short r, short c, short tr, short br, short lc, short rc) { char dirs[4]; short i, t; dirs[0] = UPWARD; dirs[1] = DOWN; dirs[2] = LEFT; dirs[3] = RIGHT; dungeon[r][c] = TUNNEL; if (rand_percent(20)) { for (i = 0; i < 10; i++) { short t1, t2; t1 = get_rand(0, 3); t2 = get_rand(0, 3); SWAP(dirs[t1], dirs[t2]); } } for (i = 0; i < 4; i++) { switch(dirs[i]) { case UPWARD: if (((r-1) >= tr) && (dungeon[r-1][c] != TUNNEL) && (dungeon[r-1][c-1] != TUNNEL) && (dungeon[r-1][c+1] != TUNNEL) && (dungeon[r-2][c] != TUNNEL)) { make_maze((r-1), c, tr, br, lc, rc); } break; case DOWN: if (((r+1) <= br) && (dungeon[r+1][c] != TUNNEL) && (dungeon[r+1][c-1] != TUNNEL) && (dungeon[r+1][c+1] != TUNNEL) && (dungeon[r+2][c] != TUNNEL)) { make_maze((r+1), c, tr, br, lc, rc); } break; case LEFT: if (((c-1) >= lc) && (dungeon[r][c-1] != TUNNEL) && (dungeon[r-1][c-1] != TUNNEL) && (dungeon[r+1][c-1] != TUNNEL) && (dungeon[r][c-2] != TUNNEL)) { make_maze(r, (c-1), tr, br, lc, rc); } break; case RIGHT: if (((c+1) <= rc) && (dungeon[r][c+1] != TUNNEL) && (dungeon[r-1][c+1] != TUNNEL) && (dungeon[r+1][c+1] != TUNNEL) && (dungeon[r][c+2] != TUNNEL)) { make_maze(r, (c+1), tr, br, lc, rc); } break; } } }