void ft_check_coordinates(t_room **rooms, int number_of_rooms) { int i; int j; i = 0; while (i + 1 < number_of_rooms) { j = 1; while (i + j < number_of_rooms) { if (rooms[i]->x == rooms[i + j]->x && rooms[i]->y == rooms[i + j]->y && ft_strcmp(rooms[i]->name, rooms[i + j]->name)) ft_block("You cannot have two rooms at the same place."); else if (!ft_strcmp(rooms[i]->name, rooms[i + j]->name) && (rooms[i]->x != rooms[i + j]->x || rooms[i]->y != rooms[i + j]->y || rooms[i]->is_start != rooms[i + j]->is_start || rooms[i]->is_end != rooms[i + j]->is_end)) ft_block("Two different rooms can't have the same name!"); else part_two(rooms, i, j); j++; } i++; } }
t_path *ft_build_path(t_room *room, t_path *actual_path, t_path **all) { t_path *result; t_path *tmp; int i; i = part_two(&tmp, &actual_path, &room, &result); if (i != -1) return (i == 1 ? ft_create_path(room) : NULL); while (room->links && room->links[++i] && room->links[i]->name) { if (room_does_not_appear(room->links[i], actual_path)) tmp = ft_build_path(room->links[i], actual_path, all); if ((tmp && ft_path_is_free(tmp, all)) && !(room->is_start && tmp->room->is_end && all[0])) result = ft_min_path(result, tmp); else ft_free_path(tmp); tmp = NULL; } tmp = ft_create_path(room); tmp->next = result; result = result ? tmp : NULL; free(result ? NULL : tmp); erase_last_one(actual_path); return (result); }
int main() { Sem_init(&t, 3); //part_one(); part_two(); exit(); }
int game(t_allum *allum) { int key; start_game("Allum1"); refresh(); sleep(1); loading(); clear(); while (key != 32) { start_game("Allum1"); display_map(allum); attron(COLOR_PAIR(7)); mvprintw(LINES/2 - 6, COLS/2 - 4, "Your turn"); mvprintw(LINES/2 + 6, COLS/2 - 15, "Press Enter to select | Arrow to move"); key = getch(); part_one(allum, key); if (part_two(allum) == 1) return (0); } return (1); }