当前位置: 首页>>代码示例>>Python>>正文


Python Room.add_paths方法代码示例

本文整理汇总了Python中room.Room.add_paths方法的典型用法代码示例。如果您正苦于以下问题:Python Room.add_paths方法的具体用法?Python Room.add_paths怎么用?Python Room.add_paths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在room.Room的用法示例。


在下文中一共展示了Room.add_paths方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_room_paths

# 需要导入模块: from room import Room [as 别名]
# 或者: from room.Room import add_paths [as 别名]
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)
开发者ID:kevivforever,项目名称:pythonWorkspace,代码行数:10,代码来源:roomtests.py

示例2: test_map

# 需要导入模块: from room import Room [as 别名]
# 或者: from room.Room import add_paths [as 别名]
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)
开发者ID:kevivforever,项目名称:pythonWorkspace,代码行数:14,代码来源:roomtests.py

示例3: Room

# 需要导入模块: from room import Room [as 别名]
# 或者: from room.Room import add_paths [as 别名]
from engine import Engine
from room import Room

north = Room("North Room", """This room is to the north of the center room.
You can also reach the East and West rooms from here.""", ['kid\'s water floaties'])
south = Room("South Room", """This room is to the south of the center room.
You can also reach the East and West rooms from here.""")
center = Room("Center Room", """This room is surrounded by 4 rooms. 
To the North, South, East and West.""", ['sword', 'chocolate bar', 'helmet'])
east = Room("East Room", """This room is to the east of the center room. 
You can also reach the North and South rooms from here.""")
west = Room("""West Room", "This room is to the west of the center room.
You can also reach the North and South rooms from here.""", ['walkman', 'fanny pack'])

north.add_paths({'down': center, 'center': center, 'east': east, 'west': west})
south.add_paths({'up': center, 'center': center, 'east': east, 'west': west})
center.add_paths({'north': north, 'south': south, 'east': east, 'west': west})
east.add_paths({'center': center, 'north': north, 'south': south})
west.add_paths({'center': center, 'north': north, 'south': south})

test_engine = Engine()
test_engine.play(center)
开发者ID:jamtot,项目名称:LearnPythonTheHardWay,代码行数:24,代码来源:game.py

示例4: Room

# 需要导入模块: from room import Room [as 别名]
# 或者: from room.Room import add_paths [as 别名]
This is Ten Forward.  It is the recreational facility on the USS Enterprise,
where officers, crew, and passengers can, um... recreate.
""")
ten_forward.add_items(['riker'])
trois_quarters = Room("Troi's Quarters", """
You are in Troi's quarters.
""")
trois_quarters.add_items(['troi'])
datas_quarters = Room("Troi's Quarters", """
You are in Data's quarters.
""")
datas_quarters.add_items(['data', 'spot'])
hallway = Room("Hallway", """
You are in a hallway on board the USS Enterprise.
""")
ten_forward.add_paths({'south': hallway})
trois_quarters.add_paths({'west': hallway})
datas_quarters.add_paths({'east': hallway})
hallway.add_paths({'north': ten_forward,
                   'east': trois_quarters,
                   'west': datas_quarters})

class Game(object):
    def __init__(self):
        self.current_room = hallway
        self.inventory = ['microspanner']
        self.game_over = False

    def change_room(self, direction):
        if (direction in self.current_room.paths.keys()):
            self.current_room = self.current_room.paths[direction]
开发者ID:bm3719,项目名称:practice,代码行数:33,代码来源:game.py


注:本文中的room.Room.add_paths方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。