12.3. CASESTUDY: DICEPOKER 215
def setMoney(self,amt):
print "Youcurrently have $%d." % (amt)
def setDice(self,values):
print "Dice:",values
def wantToPlay(self):
ans = raw_input("Do you wish to try your luck? ")
return ans[0]in "yY"
def close(self):
print "\nThanksfor playing!"
def showResult(self,msg, score):
print "%s.You win $%d." % (msg, score)
def chooseDice(self):
return input("Enterlist of which to change ([] to stop)")
Usingthisinterface,wecantestoutourPokerAppprogramtoseeif wehave implementeda correct
model.Hereis a completeprogrammakinguseofthemodulesthatwehave developed:
textpoker.py -- videodice poker using a text-based interface.
from pokerapp importPokerApp
from textinter importTextInterface
inter = TextInterface()
app = PokerApp(inter)
app.run()
Basically, allthisprogramdoesis createa text-basedinterfaceandthenbuildaPokerAppusingthisinter-
faceandstartit running.
Runningthisprogram,wegeta roughbutuseableinteraction.
Welcome to video poker.
Do you wish to try yourluck? y
You currently have$90.
Dice: [6, 4, 4, 2, 4]
Enter list of whichto change ([] to stop) [0,4]
Dice: [1, 4, 4, 2, 2]
Enter list of whichto change ([] to stop) [0]
Dice: [2, 4, 4, 2, 2]
Full House. You win $12.
You currently have$102.
Do you wish to try yourluck? y
You currently have$92.
Dice: [5, 6, 4, 4, 5]
Enter list of whichto change ([] to stop) [1]
Dice: [5, 5, 4, 4, 5]
Enter list of whichto change ([] to stop) []
Full House. You win $12.
You currently have$104.
Do you wish to try yourluck? y
You currently have$94.