コード例 #1
0
    def test_can_unlock_door_no_lock(self):
        keyring = maze.Keyring()
        door = maze.Door(maze.Room(), maze.Room())

        can_unlock = keyring.can_unlock(door)

        self.assertTrue(can_unlock)
コード例 #2
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)
コード例 #3
0
    def test_add_north_door(self):
        room = maze.Room("A")
        north_room = maze.Room("B")

        room.add_north_door(north_room)

        self.assertEqual(room.north_door.other_side(room), north_room)
        self.assertEqual(north_room.south_door.other_side(north_room), room)
        self.assertIsNone(north_room.north_door)
コード例 #4
0
    def test_tracks_other_side(self):
        room_a = maze.Room("A")
        room_b = maze.Room("B")
        door = maze.Door(room_a, room_b)

        other_size_a = door.other_side(room_a)
        other_size_b = door.other_side(room_b)

        self.assertEqual(other_size_a, room_b)
        self.assertEqual(other_size_b, room_a)
コード例 #5
0
    def test_cannot_unlock_door_missing_key(self):
        keyring = maze.Keyring()
        lock = maze.Lock()
        keyring.add_key("blue")
        lock.add_fitting_key("red")
        door = maze.Door(maze.Room(), maze.Room(), lock)

        can_unlock = keyring.can_unlock(door)

        self.assertFalse(can_unlock)
コード例 #6
0
    def test_can_unlock_door_having_key(self):
        key = "blue"
        keyring = maze.Keyring()
        lock = maze.Lock()
        keyring.add_key(key)
        lock.add_fitting_key(key)
        door = maze.Door(maze.Room(), maze.Room(), lock)

        can_unlock = keyring.can_unlock(door)

        self.assertTrue(can_unlock)
コード例 #7
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)
コード例 #8
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)
コード例 #9
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)
コード例 #10
0
ファイル: createMaze.py プロジェクト: goocy/maze3d-python
def createMaze(dimensions, startPosition, passageProperties):
    # required input:
    # dimensions.room as [X Y Z]
    # dimensions.passage as [Width Height]
    # startPosition as [X Y Z]
    # roomVolume between 0 and 1 (0 introduces no empty rooms)
    # passageProperties.flatness between 0 and 1 (1 means mostly horizontal connections)
    # passageProperties.shortcutDensity between 0 and 1
    # passageProperties.shortcutStrength between 0 and 1 (0.2 allows shortcuts that shorten the way to exit by 20%)

    wallThickness = 1

    print('Creating empty grid of rooms')
    room = maze.Room(dimensions['room'])
    room = maze.createHoles(room)

    print('Carving passages')
    maze, stackSize = maze.carvePassages(room, startPosition,
                                         passageProperties['flatness'])
    print('Setting the exit point')
    maze, exitPoint = maze.createExit(maze, stackSize, startPosition)

    print('Clearing connected walls')
    maze = maze.excavation.clearConnectedWalls(
        maze, stackSize, passageProperties['shortcutDensity'],
        passageProperties['shortcutStrength'])
    #visualizeWalls(stackSize, maze)

    print('Rendering volume')
    renderedSpace = renderWalls(maze, dimensions['passage'], wallThickness)
    print('Merging intermediate passages')
    renderedSpace = mergeVerticalPassages(renderedSpace, dimensions,
                                          wallThickness)
    print('Cleaning leftover columns')
    renderedSpace = clearColumns(renderedSpace, wallThickness)
    print('Saving to PNG')
    saveToPNG(renderedSpace, './', 'medium')
コード例 #11
0
import maze
import numpy as np
from matplotlib import pyplot as plt
superMazeSize = (2,2,1)
roomSize = (21,21,1)
flatness = (5,5,0)
for superMazeElement in superMaze.flat:
	room = maze.Room(roomSize)
	# holeyRoom = maze.createHoles(room, sum(roomSize) * 0.05, 5) # 5 holes with a total volume of 5%
	if entrancePoint is None:
		entrancePoint = (25,50,0)
	else:
		entrancePoint = exitPosition
	exitWallSide = ?
	segmentMaze, exitPosition = maze.carvePassages(room, entrancePoint, flatness, exitWallSide = exitWallSide, livePlot=True)

#print m1
コード例 #12
0
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