本文整理匯總了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