本文整理汇总了Python中dice.Dice.rollAll方法的典型用法代码示例。如果您正苦于以下问题:Python Dice.rollAll方法的具体用法?Python Dice.rollAll怎么用?Python Dice.rollAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dice.Dice
的用法示例。
在下文中一共展示了Dice.rollAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from dice import Dice [as 别名]
# 或者: from dice.Dice import rollAll [as 别名]
class PokerApp:
def __init__(self, interface):
self.dice = Dice()
self.money = 100
self.interface = interface
def run(self):
while self.money >= 10 and self.interface.wantToPlay():
self.playRound()
self.interface.close()
def playRound(self):
self.money = self.money - 10
self.interface.setMoney(self.money)
self.doRolls()
result, score = self.dice.score()
self.interface.showResult(result, score)
self.money = self.money + score
self.interface.setMoney(self.money)
def doRolls(self):
self.dice.rollAll()
roll = 1
self.interface.setDice(self.dice.values())
toRoll = self.interface.chooseDice()
while roll < 3 and toRoll != []:
self.dice.roll(toRoll)
roll = roll + 1
self.interface.setDice(self.dice.values())
if roll < 3:
toRoll = self.interface.chooseDice()
示例2: __init__
# 需要导入模块: from dice import Dice [as 别名]
# 或者: from dice.Dice import rollAll [as 别名]
class PokerApp:
def __init__(self, interface):
self.dice = Dice()
self.money = 100
self.interface = interface
def processScore(self, score):
h = HighScores()
if h.isElgible(score):
nameentry = GraphWin("Name Entry", 200, 100)
entry = Entry(Point(50, 50), 10)
entry.draw(nameentry)
okbutton = Button(nameentry, Point(150, 50), 90, 50, "Save Name")
okbutton.activate()
while 1:
m = nameentry.getMouse()
if okbutton.clicked(m):
h.addToList(score, entry.getText())
nameentry.close()
return
def run(self):
while self.money >= 10:
result = self.interface.wantToPlay()
if result == "Roll Dice":
self.playRound()
elif result == "Help":
h = HelpScreen()
h.DoEvents()
elif result == "Quit":
self.processScore(self.money)
break
self.interface.close()
def playRound(self):
self.money = self.money - 10
self.interface.setMoney(self.money)
self.doRolls()
result, score = self.dice.score()
self.interface.showResult(result, score)
self.money = self.money + score
self.interface.setMoney(self.money)
def doRolls(self):
self.dice.rollAll()
roll = 1
self.interface.setDice(self.dice.values())
toRoll = self.interface.chooseDice()
while roll < 3 and toRoll != []:
self.dice.roll(toRoll)
roll = roll + 1
self.interface.setDice(self.dice.values())
if roll < 3:
toRoll = self.interface.chooseDice()
示例3: __init__
# 需要导入模块: from dice import Dice [as 别名]
# 或者: from dice.Dice import rollAll [as 别名]
class PokerApp:
def __init__(self, interface):
self.dice = Dice()
self.money = 100
self. interface = interface
def run(self):
while self.money >= 10:
choice = self.interface.wantToPlay()
if choice == "Roll Dice":
self.playRound()
elif choice == "Help":
self.interface.help()
elif choice == "Quit":
#Figure out if high score
score = self.getMoney()
if self.isHighScore():
# Change list
self.removePerson()
list = self.addPerson()
# Print info to file to save for next time
self.printToFile(list)
# close window
self.interface.close()
break
# close window
self.interface.close()
def playRound(self):
self.money = self.money - 10
self.interface.setMoney(self.money)
self.doRolls()
result, score = self.dice.score()
self.interface.showResult(result, score)
self.money = self.money + score
self.interface.setMoney(self.money)
def doRolls(self):
self.dice.rollAll()
roll = 1
self.interface.setDice(self.dice.values())
toRoll = self.interface.chooseDice()
while roll < 3 and toRoll != []:
self.dice.roll(toRoll)
roll = roll +1
self.interface.setDice(self.dice.values())
if roll < 3:
toRoll = self.interface.chooseDice()
def getMoney(self):
return self.money
def makeScoreList(self):
scoreList = []
infile = open("HighScores", 'r')
for line in infile:
name, score = line.split()
tuple = (name, score)
scoreList.append(tuple)
return scoreList
def isHighScore(self):
newScore = self.getMoney()
list = self.makeScoreList()
flag = False
if len(list) == 10:
for tuple in list:
score = int(tuple[1])
if newScore > score:
flag = True
else:
flag = True
return flag
def addPerson(self):
score = self.getMoney()
name = self.interface.inputNameHighScore()
tuple = (name, score)
list = self.removePerson()
list.append(tuple)
return list
def removePerson(self):
list = self.makeScoreList()
if len(list) == 10:
trackerNumber = 10000
trackerTuple = None
for tuple in list:
score = int(tuple[1])
if score < trackerNumber:
trackerNumber = score
trackerTuple = tuple
list.remove(trackerTuple)
return list
def printToFile(self, list):
outfile = open('HighScores', 'w')
for tuple in list:
name, score = tuple
print (name, score, file = outfile)
#.........这里部分代码省略.........