Beispiel #1
0
def test_room_paths():
   center = Room("Center", "Test room in the center.")
   north = Room("North", "Test room in the north.")
   south = Room("South", "Test room in the south.")

   center.add_paths({'north': north, 'south': south})
   assert_equal(center.go('north'), north)
   assert_equal(center.go('south'), south)
 def __init__(self, player):
     Room.__init__(self, "Treasure Room", "The castle's treasure room.  There's a chest"
                                          "in the corner of the room.")
     self.player = player
 def __init__(self, player):
     Room.__init__(self, "Dining Room", "A large dining room fit for a king."
                                        "An enormous table sits in the center.")
     self.player = player
Beispiel #4
0
#coding=utf-8
from map import Room
#class ForestRoom(Room):
forest_plane = Room("Forest Plane","""Behind the little heal, there is a broomy forest.
                    There are lots of beautiful flowers and big trees. 
                    They wave there hands in the wind. In a hug tree, 
                    you find a tree room hiding in leaves.
                    There is a ladder you can climbing to the tree room.""")
forest_plane.actions=["climb on the ladder","leave away","fire the ladder"]

squirrel_room = Room("Squirrel Room","""When you are climbing, a creaking voice goes to you ears.
                        "Wow, it is amazing!" You find a squirrel living in the hole in the tree.
                        You try your best to find the squirrel in the hole, but it is too dark in it.
                        You have to find a way.
                        
                        That is great, you bring the pine nuts out of your bag which you peek on the way coming.
                        And you sing a song to catch the attention of the squirrel. 
                        
                        The squirrel comes out, take the pine nuts,and make frinds with you. 
                        He tells you there is a mysterious thing in the tree room. 
                        You continue to climb with the squirrel.
                           """)
squirrel_room.actions=["ignore the squirrel","give pine nuts to the squirrel","bite the squirrel"]

tree_room=Room("Tree Room","""Open the door. A wondrous world comes in your eyes. 
                You gradually walk into the room with a hot-bloooded heart. 
                There is a little bed  decorated with flowers and leaves, layed on the window.
                A desk and four bamboo stools stand in the middle of the room. Four little cups 
                lay on the desk. You walk in the room around and around. Oh, you find a wood box on the 
                desk behind the window. It needs a key to open it.""")
tree_room.actions=["find the key","ignore the box","open the box with hammer"]
Beispiel #5
0
def test_map():
   start = Room("Start", "You can go west and down a hole.")
   west = Room("Trees", "There are trees here, you can go east.")
   down = Room("Dungeon", "It's dark down here, you can go up.")

   start.add_paths({'west': west, 'down': down})
   west.add_paths({'east': start})
   down.add_paths({'up': start})

   assert_equal(start.go('west'), west)
   assert_equal(start.go('west').go('east'), start)
   assert_equal(start.go('down').go('up'), start)
Beispiel #6
0
    def generate_map(self):

        # Reset the SDA. Otherwise it will generate the wrong bits.
        if self.method == "SDA":
            self.gen.reset()

        # Initialize the rooms. Note that the Map object is not created until the end.
        rooms = [0]*num_room_attempts
        rooms[0] = Room(-2,2,-2,2) # Initial room.
        num_rooms = 1

        # Attempt to add rooms. num_room_attempts is only the theoretical maximum number of rooms that will result.
        for i in range(num_room_attempts):
            # Step 1 in Part B.
            base_room = self.get_num(8) % num_rooms

            # Step 2 in Part B
            # [0,0] is left, [1,0] is right, [0,1] is down, [1,1] is up
            next_direction = self.get_bits(2)

            # Step 3 in Part B
            is_corridor = (self.get_num(3) == 0)

            # Step 4 in Part B
            dims = [0,0] # [Horizontal, Vertical]
            if (is_corridor and not next_direction[1]):
                dims = [max(4,self.get_num(4)),1]
            if (is_corridor and next_direction[1]):
                dims = [1,max(4,self.get_num(4))]
            if (not is_corridor):
                dims = [max(2,1+self.get_num(2)),max(2,1+self.get_num(2))]

            # Step 5: Offset
            # I don't see this described in the paper.
            offset_num = self.get_num(4)
            if (not next_direction[1]):
                offset_min, offset_max = 1-dims[1], rooms[base_room].border[3]-rooms[base_room].border[2]
            if (next_direction[1]):
                offset_min, offset_max = 1-dims[0], rooms[base_room].border[1]-rooms[base_room].border[0]
            offset = offset_num % (offset_max-offset_min) + offset_min

            # With all the parameters set, figure out the location of the new room.
            next_border = [0,0,0,0]
            if (not next_direction[1]):
                next_border[2] = rooms[base_room].border[2]+offset
                next_border[3] = next_border[2] + dims[1]
                if (not next_direction[0]):
                    next_border[1] = rooms[base_room].border[0]
                    next_border[0] = next_border[1]-dims[0]
                else:
                    next_border[0] = rooms[base_room].border[1]
                    next_border[1] = next_border[0]+dims[0]
            if (next_direction[1]):
                next_border[0] = rooms[base_room].border[0]+offset
                next_border[1] = next_border[0] + dims[0]
                if (not next_direction[0]):
                    next_border[3] = rooms[base_room].border[2]
                    next_border[2] = next_border[3]-dims[1]
                else:
                    next_border[2] = rooms[base_room].border[3]
                    next_border[3] = next_border[2]+dims[1]
            new_room = Room(next_border[0], next_border[1], next_border[2], next_border[3])

            # Check if there is a conflict with previous rooms
            is_overlap = False
            for j in range(num_rooms):
                if not rooms[j].check_conflict(new_room):
                    is_overlap = True

            # Add the new room only if there is no conflict.
            if not is_overlap:
                rooms[num_rooms] = new_room
                num_rooms += 1
        return Map(rooms[:num_rooms])
 def __init__(self, player):
     Room.__init__(self, "Barracks", "The castle's barracks.  It has some beds"
                                     "laid out in rows.")
     self.player = player
Beispiel #8
0
#!/usr/bin/env python
# coding=utf-8
from map import Room

central_corridor = Room(
    'Central Corridor', ''' 
The Gothons of Planet Percal #25 have invaded your ship and destroyed
your entire crew. You are the last surviving member and your last
mission is to get the neutron destruct bomb from the Weapons Armory,
put it in the bridge, and blow the ship up after getting into an
escape pod.
You're running down the central corridor to the Weapons Armory when
a Gothon jumps out, red scaly skin, dark grimy teeth, and evil clown costume
flowing around his hate filled body. He's blocking the door to the
Armory and about to pull a weapon to blast you.''')

generic_death = Room('death', 'You died, next life to survive')

central_corridor.add_paths({
    'shoot': generic_death,
    'dodge': generic_death,
    'tell a joke': generic_death
})

START = central_corridor
 def __init__(self, player):
     Room.__init__(self, "Death Scene", "You have died.  This is hell.")
     self.player = player
Beispiel #10
0
#coding=utf-8
from map import Room
#class SurviveRoom(Room):
# ========================================各房间详情================================================
central_corridor = Room(
    "Central Corridor", """
                            The Gothons of Planet Percal #25 have invaded your ship and destroyed
                            your entire crew. You are the last surviving member and your last
                            mission is to get the neutron destruct bomb from the Weapons Armory,
                            put it in the bridge, and blow the ship up after getting into an 
                            escape pod.

                            You're running down the central corridor to the Weapons Armory when 
                            a Gothon jumps out, red scaly skin, dark grimy teeth, and evil clown costume
                            flowing around his hate filled body. He's blocking the door to the 
                            Armory and about to pull a weapon to blast you.
                            """)
central_corridor.actions = ["tell a joke", "bite him", "run away"]

laser_weapon_armory = Room(
    "Laser Weapon Armory", """
                               Lucky for you they made you learn Gothon insults in the academy.
                               You tell the one Gothon joke you know:
                               Lbhe zbgure vf fb sng, jura fur fvgf nebhaq gur ubhfr, fur fvgf nebhaq gur ubhfr.
                               The Gothon stops, tries not to laugh, then busts out laughing and can't move.
                               While he's laughing you run up and shoot him square in the head
                               putting him down, the jump through the Weapon Armory door.

                               You do a dive roll into the Weapon Armory, crouch and scan the room
                               for more Gothons that might be hiding. It's dead quiet, too quiet.
                               You stand up and run to the far side of the room and find the