def setValue(self, value): """ Overrides DieView.setValue(), saving value locally first, then calling DieView.setValue() :param value: int -> value to set for die """ self.value = value # remember this value DieView.setValue(self, value) # call setValue from parent class
def main(): # Create the application window win = GraphWin('Dice Roller', 500, 500) win.setCoords(0, 0, 10, 10) win.setBackground(color_rgb(0, 75, 0)) # Draw the interface widgets die1 = DieView(win, Point(3, 7), 2) die2 = DieView(win, Point(7, 7), 2) rollButton = Button(win, Point(5, 4.5), 1.25, 'Roll Dice') rollButton.activate() quitButton = Button(win, Point(5, 1), 1, 'Quit') # Event loop pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): value1 = randrange(1, 7) #die1.setColor(color_rgb(randrange(255), randrange(255), randrange(255))) die1.setValue(value1) value2 = randrange(1, 7) die2.setColor( color_rgb(randrange(255), randrange(255), randrange(255))) die2.setValue(value2) quitButton.activate() pt = win.getMouse() # Exit Program win.close()
def window(): pointA = Point(125,75) pointB = Point(125,175) pointC = Point(125,275) pointD = Point(350,150) pointE = Point(500,150) pointF = Point(450,275) pointG = Point(475,50) pointX = Point(575,25) win = GraphWin("Crap Heaven",600,350) win.setBackground("purple") pt = win.getMouse() bA = Button(win,pointA,150,50,"Bet 1000!") bB = Button(win,pointB,150,50,"Bet 100!") bC = Button(win,pointC,150,50,"Bet 10!") bD = DieView(win,pointD,100) bE = DieView(win,pointE,100) bF = Button(win,pointF,200,50,"Bank Account") button2 = Button(win,pointG,150,50,"Win!") button1 = Button(win,pointX,25,25,"X") button2.activate button2.active while not button2.clicked(pt): if button2.clicked(pt): win.close() pt = win.getMouse()
def __init__(self): self.win = g.GraphWin(title="Dice Game", width=500, height=500) self.dwidget1 = DieView(self.win, center=g.Point(40, 40), size=40) self.dwidget2 = DieView(self.win, center=g.Point(90, 40), size=40) self.dwidget3 = DieView(self.win, center=g.Point(40, 100), size=40) self.dwidget4 = DieView(self.win, center=g.Point(90, 100), size=40) self.dwidget5 = DieView(self.win, center=g.Point(40, 160), size=40) # self.button = g.Rectangle(g.Point(10,200),g.Point(90,230)) # self.button.setFill('green') self.win.bind("<Button-1>", self.reroll)
def main(): # create the application window win = GraphWin("Dice Roller", WINDOW_WIDTH, WINDOW_HEIGHT) win.setBackground("black") # draw the interface widgets centerPoint = Point(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2) quit = Button(win, Point(WINDOW_WIDTH - 75, WINDOW_HEIGHT - 50), 75, 50, 'Quit') quit.activate() roll = Button(win, Point(WINDOW_WIDTH - 150, WINDOW_HEIGHT - 50), 75, 50, 'Roll') roll.activate() die1 = DieView(win, Point(WINDOW_WIDTH / 2 - 50, WINDOW_HEIGHT / 2), 50) die2 = DieView(win, Point(WINDOW_WIDTH / 2 + 50, WINDOW_HEIGHT / 2), 50) # event loop run = True while run: clickPoint = win.getMouse() if (roll.clicked(clickPoint)): die1.setValue(randrange(1, 7)) die2.setValue(randrange(1, 7)) run = not quit.clicked(clickPoint) # close the window win.close()
def main(): # Create the application window win = GraphWin('Dice Roller', 500, 500) win.setCoords(0, 0, 10, 10) win.setBackground(color_rgb(0,75,0)) # Draw the interface widgets die1 = DieView(win, Point(3,7), 2) die2 = DieView(win, Point(7,7), 2) rollButton = Button(win, Point(5,4.5), 1.25, 'Roll Dice') rollButton.activate() quitButton = Button(win, Point(5,1), 1, 'Quit') # Event loop pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): value1 = randrange(1,7) #die1.setColor(color_rgb(randrange(255), randrange(255), randrange(255))) die1.setValue(value1) value2 = randrange(1,7) die2.setColor(color_rgb(randrange(255), randrange(255), randrange(255))) die2.setValue(value2) quitButton.activate() pt = win.getMouse() # Exit Program win.close()
def main(): win = GraphWin('Dice Roller') win.setCoords(0, 0, 10, 10) win.setBackground('green2') die1 = MultiSidedDie(6) die2 = MultiSidedDie(6) dieView1 = DieView(win, Point(3, 7), 2) dieView2 = DieView(win, Point(7, 7), 2) rollButton = Button(win, Point(5, 4.5), 6, 1, 'Roll Dice') rollButton.activate() quitButton = Button(win, Point(5, 1), 2, 1, 'Quit') point = win.getMouse() while not quitButton.clicked(point): if rollButton.clicked(point): die1.roll() dieView1.drawValue(die1.getValue()) die2.roll() dieView2.drawValue(die2.getValue()) quitButton.activate() point = win.getMouse() win.close()
def main(): # create the application window win = GraphWin("Dice Roller", ) win.setCoords(0, 0, 10, 10) win.setBackground("green2") # draw the interface widgets b1 = Button(win, Point(4, 2), 3, 2, "Roll") b2 = Button(win, Point(8, 2), 3, 2, "Quit") d1 = DieView(win, Point(3, 6), 3) d2 = DieView(win, Point(7, 6), 3) # event loop while True: if b1.clicked(win.getMouse()): d1.setValue(MSdie().setValue()) d2.setValue(MSdie().setValue()) elif b2.clicked(win.getMouse()): return False # close the window win.close()
def main(): # create the application window win = GraphWin("Dice Roller") win.setCoords(0, 0, 10, 10) win.setBackground("green2") # Draw the interface widgets die1 = DieView(win, Point(3, 7), 2) die2 = DieView(win, Point(7, 7), 2) rollButton = CButton(win, Point(5, 4.5), 1.5, "Roll Dice") rollButton.activate() quitButton = CButton(win, Point(5, 1), 1, "Quit") # Event loop pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): value1 = randrange(1, 7) die1.setValue(value1) value2 = randrange(1, 7) die2.setValue(value2) quitButton.activate() pt = win.getMouse() # close up shop win.close()
def createDice(self, center, size): center.move(-3 * size, 0) self.dice = [] for i in range(5): view = DieView(self.win, center, size) self.dice.append(view) center.move(1.5 * size, 0)
def main(): # create the application window win = GraphWin("Dice Roller") win.setCoords(0, 0, 10, 10) win.setBackground("green2") # Draw the interface widgets die1 = DieView(win, Point(3,7), 2) die2 = DieView(win, Point(7,7), 2) rollButton = Button(win, Point(5,4.5), 6, 1, "Roll Dice") rollButton.activate() quitButton = Button(win, Point(5,1), 2, 1, "Quit") # Event loop pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): value1 = randrange(1,7) die1.setValue(value1) value2 = randrange(1,7) die2.setValue(value2) quitButton.activate() pt = win.getMouse() # close up shop win.close()
def main(): # create the application window win = GraphWin("Dice Poker", WINDOW_WIDTH, WINDOW_HEIGHT) win.setBackground("black") # draw the interface widgets centerPoint = Point(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2) quit = Button(win, Point(WINDOW_WIDTH - 50, WINDOW_HEIGHT - 50), 75, 50, 'Quit') quit.activate() roll = Button(win, Point(WINDOW_WIDTH - 125, WINDOW_HEIGHT - 50), 75, 50, 'Roll') roll.activate() m = (WINDOW_WIDTH / 5) + (5*25) for k in range(5): hand.append(DieView(win, Point(WINDOW_WIDTH / 2 - m, WINDOW_HEIGHT / 2), 100)) m -= 125 scoreText = Text(Point(50, 50), "Score Text Goes Here...") scoreText.setTextColor("white") scoreText.draw(win) global helpText helpText = Text(Point(WINDOW_WIDTH - 200, 75), "Help Text Goes Here...") helpText.setTextColor("white") helpText.draw(win) playHand() # event loop run = True while run: updateScore(scoreText) clickPoint = win.getMouse() if (roll.clicked(clickPoint)): playHand() run = ( (not quit.clicked(clickPoint)) and (playerAmount >= 10) ) updateScore(scoreText) # By now, player has exhausted funds if (playerAmount <= 10): helpText.setText(helpText.getText() + "\nYou've don't have enough for another roll.") roll.deactivate() while (not quit.clicked(clickPoint)): # Wait till the user clicks quit clickPoint = win.getMouse() # close the window win.close()
def main(): win = GraphWin("Dice Roller") win.setCoords(0, 0, 10, 10) win.setBackground("green2") die1 = DieView(win, Point(3, 7), 2) die2 = DieView(win, Point(7, 7), 2) rollButton = Button(win, Point(5, 4.5), 6, 1, "Roll Dice") rollButton.activate() quitButton = Button(win, Point(5, 1), 2, 1, "Quit") pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): value1 = randrange(1, 7) die1.setValue(value1) value2 = randrange(1, 7) die2.setValue(value2) quitButton.activate() pt = win.getMouse() win.close()
def main(): # create the application window win = GraphWin("Dice Roller", ) win.setCoords(0, 0, 12, 12) win.setBackground("green") roll_btn = Button(win, Point(3, 2), 3, 3, "Roll") quit_btn = Button(win, Point(7, 2), 3, 3, "Quit") d1 = DieView(win, Point(3, 6), 3) d2 = DieView(win, Point(7, 6), 3) # while True: if roll_btn.clicked(win.getMouse()): d1.setValue(MSdie(6).roll()) d2.setValue(MSdie(6).roll()) elif quit_btn.clicked(win.getMouse()): return False # close the window win.close()
def main(): # create the application window win = GraphWin( "Dice Roller" ) # Constructs a new graphics window for drawing on the screen. (title, width, height) win.setCoords( 0, 0, 10, 10 ) # Sets the coordinate system of the window in the format (xll, yll, xur, yur) # The lower-left corner is (xll, yll) and the upper-right corner is (xur, yur) win.setBackground("red2") # Sets the window background to the given color # draw the interface widgets die1 = DieView(win, Point(3, 7), 2) die2 = DieView(win, Point(7, 7), 2) rollButton = Button(win, Point(5, 4.5), 6, 1, "Roll Dice") rollButton.activate() quitButton = Button(win, Point(5, 1), 2, 1, "Quit") # Event loop pt = win.getMouse( ) # Pauses for the user to click a mouse in the window and returns where the mouse was # clicked as a Point object. while not quitButton.clicked(pt): if rollButton.clicked(pt): value1 = randrange(1, 7) die1.setValue(value1) value2 = randrange(1, 7) die2.setValue(value2) quitButton.activate() pt = win.getMouse() # close win.close() # Closes the on-screen window
def main(): win = GraphWin("Dice Roller") win.setCoords(0, 0, 10, 10) win.setBackground("green2") die1 = DieView(win, Point(3, 7), 2) die2 = DieView(win, Point(7, 7), 2) rollButton = Button(win, Point(5, 4.5), 6, 1, "Roll Dice") rollButton.activate() quitButton = Button(win, Point(5,1), 2, 1, "Quit") p = win.getMouse() while not quitButton.clickedab(p): if rollButton.clickedab(p): value1 = randrange(1, 7) die1.setValue(value1) value2 = randrange(1, 7) die2.setValue(value2) quitButton.activate() pt = win.getMouse() win.close()
def setValue(self, value): self.value = value # remember this value DieView.setValue(self, value) # call setValue from parent class
class App(): def __init__(self): self.win = g.GraphWin(title="Dice Game", width=500, height=500) self.dwidget1 = DieView(self.win, center=g.Point(40, 40), size=40) self.dwidget2 = DieView(self.win, center=g.Point(90, 40), size=40) self.dwidget3 = DieView(self.win, center=g.Point(40, 100), size=40) self.dwidget4 = DieView(self.win, center=g.Point(90, 100), size=40) self.dwidget5 = DieView(self.win, center=g.Point(40, 160), size=40) # self.button = g.Rectangle(g.Point(10,200),g.Point(90,230)) # self.button.setFill('green') self.win.bind("<Button-1>", self.reroll) def rollDice(self): self.dwidget1.setValue(random.randint(1, 6)) self.dwidget2.setValue(random.randint(1, 6)) self.dwidget3.setValue(random.randint(1, 6)) self.dwidget4.setValue(random.randint(1, 6)) self.dwidget5.setValue(random.randint(1, 6)) def reroll(self, event): self.dwidget1.setValue(random.randint(1, 6)) self.dwidget2.setValue(random.randint(1, 6)) self.dwidget3.setValue(random.randint(1, 6)) self.dwidget4.setValue(random.randint(1, 6)) self.dwidget5.setValue(random.randint(1, 6)) def run(self): self.rollDice() self.win.getMouse() print('running') self.win.close()
def setValue(self, value): self.value = value DieView.setValue(self, value)
def playoneround(win, type, numplayers, players, starter, carryover): bet = 0 last = 0 winner = 6 highlow = [Text(Point(25, 70), "High"), Text(Point(25, 70), "Low")] for i in range(2): highlow[i].setSize(20) highlow[i].setStyle("bold") highlow[0].setTextColor("red") highlow[1].setTextColor("blue") coinlabels = refreshplayers(players) for i in range(numplayers): coinlabels[i].draw(win) arbitrary = Text(Point(18, 77), "Arbitrary Number") arbitrary.setSize(15) arbitrary.setStyle("bold") arbitrary.draw(win) # sets the arbitrary number die adie = DieView(win, Point(10, 70), 8, 1) adie.build() adie.roll() if adie.getValue() > 3: top = 31 adie.recolor(2) highlow[1].draw(win) else: top = 0 adie.recolor(1) highlow[0].draw(win) ante = anteup(win, players, numplayers) pot = ante + bet + carryover potmsg = Text(Point(105, 75), "{0}".format(pot)) potmsg.setSize(20) potmsg.setTextColor("yellow") potmsg.setStyle("bold") potmsg.draw(win) # These three lines update the coin counts for the players for i in range(numplayers): coinlabels[i].undraw() coinlabels = refreshplayers(players) for i in range(numplayers): coinlabels[i].draw(win) for i in range(numplayers): if (starter + i) >= numplayers: whosgo = starter + i - numplayers else: whosgo = starter + i roll, made, folded, bet, top, last, winner = oneturn( win, players, whosgo, adie, bet, top, last, numplayers, winner ) for i in range(numplayers): coinlabels[i].undraw() coinlabels = refreshplayers(players) for i in range(numplayers): coinlabels[i].draw(win) pot = ante + bet + carryover potmsg.undraw() potmsg = Text(Point(105, 75), "{0}".format(pot)) potmsg.setSize(20) potmsg.setTextColor("yellow") potmsg.setStyle("bold") potmsg.draw(win) if winner == 6: carryover = pot winlabel = Text(Point(50, 50), "No one won this round.") winlabel.draw(win) else: players[winner].update(pot) winlabel = Text(Point(50, 50), "{0} won the round.".format(players[winner].getname())) winlabel.draw(win) win.getMouse() # for i in range(numplayers): coinlabels[i].undraw() # coinlabels = refreshplayers(players) # for i in range(numplayers): coinlabels[i].draw(win) potmsg.undraw() for i in range(2): highlow[i].undraw() for i in range(numplayers): coinlabels[i].undraw() winlabel.undraw() return carryover
def main(): # create the application window win = GraphWin("Dice Roller") win.setCoords(0,0,10,10) win.setBackground("gray") # draw the interface widgets die1 = DieView(win, Point(3,7), 2) die2 = DieView(win, Point(7,7), 2) rollButton = Button(win, Point(5,4.5), 6, 1, "Roll Dice") rollButton.activate() quitButton = Button(win, Point(5,1), 2, 1, "Quit") # event loop pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): # re-rolling value and pip color of die1 value1 = randrange(1, 7) color = color_rgb(randrange(0,256), randrange(0,256), randrange(0,256)) die1.setValue(value1) die1.setColor(color) # re-rolling value and pip color of die2 value2 = randrange(1, 7) color = color_rgb(randrange(0,256), randrange(0,256), randrange(0,256)) die2.setValue(value2) die2.setColor(color) quitButton.activate() pt = win.getMouse() # close up shop win.close()