本文整理汇总了Python中die.Die.getValue方法的典型用法代码示例。如果您正苦于以下问题:Python Die.getValue方法的具体用法?Python Die.getValue怎么用?Python Die.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类die.Die
的用法示例。
在下文中一共展示了Die.getValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Player
# 需要导入模块: from die import Die [as 别名]
# 或者: from die.Die import getValue [as 别名]
class Player(object):
def __init__(self):
"""Has a pair of dice and an empty rolls list."""
self._die1 = Die()
self._die2 = Die()
self._rolls = []
def __str__(self):
"""Returns a string representation of the list of rolls."""
result = ""
for (v1, v2) in self._rolls:
result = result + str((v1, v2)) + " " + str(v1 + v2) + "\n"
return result
def getNumberOfRolls(self):
"""Returns the number of the rolls."""
return len(self._rolls)
def play(self):
"""Plays a game, saves the rolls for that game,
and returns True for a win and False for a loss."""
self._rolls = []
self._die1.roll()
self._die2.roll()
(v1, v2) = (self._die1.getValue(), self._die2.getValue())
self._rolls.append((v1, v2))
initialSum = v1 + v2
if initialSum in (2, 3, 12):
return False
elif initialSum in (7, 11):
return True
while True:
self._die1.roll()
self._die2.roll()
(v1, v2) = (self._die1.getValue(), self._die2.getValue())
self._rolls.append((v1, v2))
sum = v1 + v2
if sum == 7:
return False
elif sum == initialSum:
return True