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


Python Dice.valuelist方法代码示例

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


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

示例1: CommandlinePlayer

# 需要导入模块: from dice import Dice [as 别名]
# 或者: from dice.Dice import valuelist [as 别名]
class CommandlinePlayer(Player):

    def __init__(self, game, uid=1, max_turns=3, point_config='STD_CONFIG'):
        super(CommandlinePlayer, self).__init__(game, uid=uid, point_config=point_config, max_turns=max_turns)
        self.commands = {
            'd': self.roll_dice,
            's': self.save_dice,
            'save': self.save_dice,
            'help': print_help,
            'p': self.show_points,
            'p_all': self.show_all_points
        }

        self.point_commands = [
            'one', 'two', 'three', 'four', 'five', 'six', 'threesome', 'foursome', 'onepair', 'twopair',
            'smallstreet', 'bigstreet', 'kniffel', 'fullhouse', 'chance'
        ]

    def play(self):
        self.dice = Dice()
        while True:
            try:
                self.command_prompt()
            except WrongCommandException:
                print_message('wrongcommand')
            except TurnEndException:
                break

        self.turn = 0

    def roll_dice(self):
        super(CommandlinePlayer, self).roll_dice()
        print_dice(self.dice)

    def show_points(self):
        print_points(self)

    def print_points(self):
        print_points(self.points)

    def command_prompt(self):
        value = prompt('playerprompt', self.id)
        try:
            if value.split(' ')[0] is 's':
                for pos in value.split(' ')[1].split(','):
                    try:
                        self.save_dice([int(pos)])
                    except ValueError:
                        print_message('unknown_param', pos)
                print_dice(self.dice)
            elif value in self.commands:
                try:
                    self.commands[value]()
                except NoTurnsLeftException:
                    print_message('noturnsleft')
            elif value.split(' ')[0] in self.point_commands:
                try:
                    try:
                        column = value.split(' ')[1]
                        self.entry_points(value, column, self.dice.valuelist())
                        raise TurnEndException()
                    except IndexError:
                        print_message('specify_column')
                except FieldAlreadyAssignedException:
                    print_message('fieldblocked')
            else:
                raise WrongCommandException()
        except IndexError:
            print_dice(self.dice)

    def show_all_points(self):
        print_points(self.game.players)
开发者ID:l0rn,项目名称:todesknobel,代码行数:74,代码来源:player.py


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