Beispiel #1
0
def main():
    win = GraphWin("Double Die Roller", 400, 200)
    win.setBackground( 'dark green' )
    dieView1 = DieView( win, Point( 50, 60 ), 80 )
    dieView2 = DieView( win, Point( 150, 60 ), 80 )
    rollButton = Button( win, Point( 100, 160), 100, 40, "Roll!" )
    
    sumCounter = [0,0,0,0]
    possibleSums = [7,8,9,10]
    currentSum = 0
    
    while True:
        mouseClick = win.getMouse()
        i = 0
        if rollButton.wasClickedIn( mouseClick ):

            dieView1.roll()
            dieView2.roll()
            
            currentSum = dieView1.getValue() + dieView2.getValue()
            Counter = SumCounterView(win, currentSum, sumCounter)
            currentSum = Counter.getSum()
            while i < 4:
                if currentSum == possibleSums[i]:
                    sumCounter[i] += 1
                i += 1
            Counter.handleRoll(sumCounter)
def main():
    win = GraphWin("Double Die Roller", 500, 300)
    win.setBackground('dark green')
    dieView1 = DieView(win, Point(60, 80), 100)
    dieView2 = DieView(win, Point(175, 80), 100)

    counter_views = {
        7: SumCounter(win, Point(375, 50), 160, 50, 7),
        8: SumCounter(win, Point(375, 115), 160, 50, 8),
        9: SumCounter(win, Point(375, 180), 160, 50, 9),
        10: SumCounter(win, Point(375, 245), 160, 50, 10)
    }

    rollButton = Button(win, Point(120, 180), 100, 40, "Roll!")

    while True:
        mouseClick = win.getMouse()
        if rollButton.wasClickedIn(mouseClick):
            dieView1.roll()
            dieView2.roll()
            sum = dieView1.getValue() + dieView2.getValue()

            if sum in counter_views:
                counter_views[sum].handleRoll()
                counter_views[sum].setText()
Beispiel #3
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)

    roll_button = Button(win, Point(5, 4.5), 6, 1, "Roll Dice")
    roll_button.activate()
    quit_button = Button(win, Point(5, 1), 2, 1, "Quit")

    # Even loop
    pt = win.getMouse()
    # print(type(pt))
    # print(pt.getX())
    while not quit_button.clicked(pt):
        if roll_button.clicked(pt):
            value1 = randrange(1, 7)
            die1.set_value(value1)
            value2 = randrange(1, 7)
            die2.set_value(value2)
            quit_button.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(): #my graph window
    win = GraphWin("Double_Die_Roller", 425, 200)
    win.setBackground( 'dark red' )
    dieview1 = DieView( win, Point( 50, 60 ), 80 )
    dieview2 = DieView( win, Point( 150, 60 ), 80 )
    
    #my sums
    counter = {10: SumCounter( win, Point( 300, 50), 10), 4: SumCounter( win, Point( 300, 75), 4), 2: SumCounter( win, Point( 300, 100), 2), 11: SumCounter( win, Point( 300, 125), 11)}
    
    rollButton = Button( win, Point( 100, 160), 100, 40, "Roll!" )
    while True:
        mouseClick = win.getMouse()
        if rollButton.wasClickedIn( mouseClick ):
            dieview1.roll()
            dieview2.roll()
            sum=dieview1.getValue() + dieview2.getValue() #adds together each dice roll
            
            if sum in counter: # if the sum of the rolls equal a number in the counter, it keeps a tally
                counter[sum].handleRoll()
                counter[sum].setText()
Beispiel #6
0
 def __init__(self, *args, **kwargs):
     super().__init__(self, *args, **kwargs)
     self.flex = 'WB'
     self._dvs = [DieView() for _ in range(5)]
     for dv in self._dvs:
         dv.onholdchange = self._handle_hold
         self.add_subview(dv)
     self._num_finished = 0
     self._enabled = True
     self.onholdchange = lambda i, v: None
     self.onrollfinished = lambda: None
Beispiel #7
0
def main():
    win = GraphWin("Double Die Roller", 400, 200)
    win.setBackground('dark green')
    dieView1 = DieView(win, Point(50, 60), 80)
    dieView2 = DieView(win, Point(150, 60), 80)
    rollButton = Button(win, Point(100, 160), 100, 40, "Roll!")

    while True:
        mouseClick = win.getMouse()
        if rollButton.wasClickedIn(mouseClick):
            dieRoll1Value = dieView1.roll()
            dieRoll2Value = dieView2.roll()
            SumCounterView(dieCountSum, win)