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


Python Player.options方法代码示例

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


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

示例1: __init__

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import options [as 别名]
class Game:
    rooms = None
    is_running = False
    coordinate_map = None
    current_coordinate = (0, 0)
    events = None

    def __init__(self, rooms, direction_strategy=_choose_random_direction):  # TODO: Test this
        # Requires: an iterable object containing Room objects, a strategy for assigning rooms
        # Ensures:
        # assignment of instance variables(events, rooms,coordinate_map,is_running)
        # creation of coordinate_ map by calling make_map method
        # instantiation of Player and sets its location instance variable to coordinate 0,0
        # assignment to receiver list for player events (per Observer pattern)
        self.events = []
        self.rooms = rooms
        for room in rooms:
            room.add_receiver(self)
        self.coordinate_map = {(0, 0): rooms[0]}  # prevents self-connection of first room
        self._make_map(direction_strategy)
        self.player = Player(rooms[0])
        self.player.add_receiver(self)
        self.player.options()
        self.is_running = True

    def receive(self, event):
        # Requires: an instance of an Event object
        # Ensures: events instance variable iterable object contains the passed Event object
        self.events.append(event)

    def get_status(self):  # TODO: test this
        # Requires: N/A
        # Ensures: returns a blank-line separated string of event messages from
        #          events instance variable.
        status = ""
        for event in self.events:
            status += event.message + "\n"
        self.events = []
        return status

    def respond_to_user_input(self, user_input):  # TODO: test this
        # Requires: a string containing desired action
        # Ensures:
        # proper selection and calls move, look, map or exit action
        # OR
        # prints feedback to user that desired action is unavailable
        # TODO: get rid of print call here and return instead.
        user_input = user_input.capitalize()
        if user_input in DIRECTIONS:
            if user_input == "N":
                user_input = "North"
            elif user_input == "S":
                user_input = "South"
            elif user_input == "E":
                user_input = "East"
            elif user_input == "W":
                user_input = "West"
            self.player.move(user_input)
        elif user_input in ["Look", "L"]:
            self.player.look()
        elif user_input in ["Options", "O"]:
            self.player.options()
        elif user_input in ["Map", "M"]:
            self.print_map()
        elif user_input in ["Quit", "Q"]:
            self._stop()
        else:
            print("sorry, there is no such action")

    def print_map(self):  # TODO: make this return instead?
        # Requires: make_map must have already been called.
        # Ensures:
        # creates a printed map to the command line.
        # resulting map shows only those rooms which have been discovered by the player
        top_line = ["|" + ("_" * 20) + ""]
        empty_line = ["|" + (" " * 20) + ""]
        room_map = []
        for y in reversed(range(-6, 7)):
            row = []
            for x in range(-6, 7):
                room = self.coordinate_map.get((x, y), Room("weird thing"))
                if room.is_discovered:
                    row.append(room.name_string)
                else:
                    row.append("|" + (" " * 20) + "")
            room_map.append(row)
        for row in room_map:
            print("".join(top_line * len(room_map)))
            print("".join(empty_line * len(room_map)))
            print("".join(row))

    def _make_map(self, direction_strategy):
        # Requires: a direction strategy to use in assigning room directions and exits
        # Ensures:
        # assignment of coordinates to corresponding room objects in coordinates_map:
        # rooms are assigned per logical directions.
        # connection of rooms via room's exits instance variable
        # rooms are connected logically
        # i.e. if a user goes N, W, S, the first room & final rooms are connected by E/W

#.........这里部分代码省略.........
开发者ID:moshi-kibu,项目名称:Candle,代码行数:103,代码来源:game.py


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