# program.py from graphics import * from die import * from button import * from dieView import * from time import sleep def main(): w = GraphWin("Playing with two dice",800,600) m = Image(Point(400,100),"two-red-dice.gif") m.draw(w) # Text message for the user T = Text(Point(400,270),"Let's play with rolling two dice\n\ When you are ready press the roll button") T.setStyle("italic") T.setTextColor("blue") T.draw(w) # roll dice button rollButton = Button(w,Point(400,515),70,30,"ROLL!") # Exit button exitButton = Button(w,Point(735,565),70,30) # creating instnces of two dice die1 = MSDie(6) # creating an object of class MSDie die2 = MSDie(6) # creating another object of class MSDie # loading up images into the list of images d1 = dieView(w,Point(400-55,400)) d2 = dieView(w,Point(400+55,400)) # initially both dice have face 1, let's draw them d1.show() d2.show() answer = "continue" while answer != "exit": p = w.getMouse() # getting coordinates of the mouse click if exitButton.clicked(p): # if EXIT is clicked exitButton.activate() answer = "exit" elif rollButton.clicked(p): # if ROLL! is clicked rollButton.activate() die1.roll() # rolling the first die i = die1.getValue() # getting the roll's value print("first die: ",i) d1.setValue(i) die2.roll() # rolling the second die j = die2.getValue() # getting the roll's value print("second die: ",j) d2.setValue(j) else: exitButton.deactivate() rollButton.deactivate() pass w.close() main()