Exemple #1
0
    def test_cannot_move_through_None_door(self):
        room_a = maze.Room("A")
        player = maze.Player(room_a)

        player.move_through(room_a.north_door)

        self.assertEqual(player.current_room, room_a)
Exemple #2
0
    def test_on_enter_adds_key(self):
        room = maze.Room("A", "blue")
        player = maze.Player()

        room.on_enter(player)

        self.assertIn("blue", player.keyring.keys)
Exemple #3
0
    def test_can_move_through_unlocked_door(self):
        room_a = maze.Room("A")
        room_b = maze.Room("B")
        room_a.add_north_door(room_b)
        player = maze.Player(room_a)

        player.move_through(room_a.north_door)

        self.assertEqual(player.current_room, room_b)
Exemple #4
0
    def test_cannot_move_through_locked_door_without_key(self):
        room_a = maze.Room("A")
        room_b = maze.Room("B")
        lock = maze.Lock()
        lock.add_fitting_key("blue")
        room_a.add_north_door(room_b, lock)
        player = maze.Player(room_a)

        player.move_through(room_a.north_door)

        self.assertEqual(player.current_room, room_a)
def initialize():
    """
    Creates the maze_layout list of rooms and the player object
    :return: maze_choice, maze_layout, player
    """

    # create all possible rooms
    rooms = [
        maze.Room([0, 0, 0, 0], 'small'),  # Closed room(0)
        maze.Room([1, 1, 1, 1], 'small'),  # Open room(1)
        maze.Room([1, 0, 1, 0], 'small'),  # NS corridor(2)
        maze.Room([0, 1, 0, 1], 'small'),  # EW corridor(3)
        maze.Room([1, 0, 0, 1], 'small'),  # NW corner(4)
        maze.Room([1, 1, 0, 0], 'small'),  # NE corner(5)
        maze.Room([0, 1, 1, 0], 'small'),  # SE corner(6)
        maze.Room([0, 0, 1, 1], 'small'),  # SW corner(7)
        maze.Room([1, 1, 0, 1], 'small'),  # EW with N tee(8)
        maze.Room([1, 1, 1, 0], 'small'),  # NS with E tee(9)
        maze.Room([0, 1, 1, 1], 'small'),  # EW with S tee(10)
        maze.Room([1, 0, 1, 1], 'small'),  # NS with W tee(11)
        maze.Room([1, 0, 0, 0], 'small'),  # N dead end(12)
        maze.Room([0, 1, 0, 0], 'small'),  # E dead end(13)
        maze.Room([0, 0, 1, 0], 'small'),  # S dead end(14)
        maze.Room([0, 0, 0, 1], 'small'),  # W dead end(15)
    ]

    # create list using room indexes (will be converted when chosen)
    maze_1 = [
        [13, 3, 10, 7, 14, 0, 0],
        [13, 3, 4, 5, 11, 0, 0],
        [6, 7, 6, 3, 8, 7, 0],
        [2, 5, 1, 3, 15, 2, 0],
        [5, 3, 8, 7, 6, 4, 0],
        [0, 0, 0, 5, 11, 0, 0],
        [0, 0, 0, 0, 5, 3, 15],
    ]

    maze_2 = [
        [13, 10, 3, 3, 7, 14, 0, 14, 0, 0, 0],
        [0, 2, 13, 3, 4, 2, 0, 2, 0, 0, 0],
        [0, 5, 10, 3, 7, 2, 0, 9, 3, 3, 7],
        [0, 13, 4, 6, 8, 4, 14, 12, 14, 0, 2],
        [0, 0, 6, 8, 3, 7, 2, 0, 5, 3, 11],
        [0, 13, 1, 3, 7, 12, 2, 6, 7, 13, 11],
        [0, 0, 2, 14, 5, 3, 8, 11, 5, 3, 4],
        [0, 0, 5, 4, 0, 13, 3, 4, 0, 0, 0],
    ]

    maze_3 = [
        [13, 3, 7, 13, 7, 0, 14],
        [14, 13, 8, 7, 2, 0, 2],
        [2, 6, 7, 5, 8, 7, 2],
        [5, 4, 5, 3, 3, 8, 4],
    ]

    maze_4 = random_maze(10)
    print('Layout for unused random maze (for demonstration/inspection):')
    vizualize_maze(maze_4)

    # create list of mazes, choose random maze for game, convert maze indexes to rooms
    mazes = [maze_1, maze_2, maze_3]  # random maze not used at this time
    maze_choice = random.choice(range(0, len(mazes)))
    maze_layout = mazes[maze_choice]
    maze_layout = index_to_rooms(maze_layout, rooms)

    # verify player name input
    player_name = ''
    while not player_name:

        player_name = input('What is your name? ')

        if not player_name:
            print('Input not recognized. Please re-enter a name.\n')

    player = maze.Player(player_name, 0, 0)

    return maze_choice, maze_layout, player