Пример #1
0
def main():
    #create app window
    win = GraphWin("Dice Roller")
    win.setCoords(0, 0, 10, 10)
    win.setBackground('green2')

    #draw 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 shope
    win.close()
Пример #2
0
def main():
    # create the application window
    win = GraphWin("Dice Roller")
    win.setCoords(0, 0, 10, 10)
    win.setBackground("CadetBlue1")

    # 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()
Пример #3
0
 def createDice(self, center, size):
     center.move(-3 * size, 0)
     self.dice = []
     for i in range(2):
         view = DieView(self.win, center, size)
         self.dice.append(view)
         center.move(1.5 * size, 0)
Пример #4
0
 def drawDice(self):
     self.dieOne = DieView(self.win, Point(2.9, 3), 0.5)
     self.dieTwo = DieView(self.win, Point(3.5, 3.6), 0.5)
     self.dieThree = DieView(self.win, Point(4.1, 3), 0.5)
Пример #5
0
class GraphicInterface:

    def __init__(self):
        self.win = GraphWin("CeeLo", 700, 600)
        self.win.setCoords(0,0,7,6)
        self.drawPlayers()
        self.drawMoneyDisplays()
        self.drawDice()
        self.continueButton = Button(self.win, Point(1,1), 1, 0.3, "Play Round")
        self.rollButton = Button(self.win, Point(6,1), 0.5, 0.4, "Roll!")
        self.resultDisplay = Text(Point(2, 5.5), "").draw(self.win)
        self.resultDisplay.setSize(20)
        self.winnerDisplay = Text(Point(3.5, 0.2), "").draw(self.win)
        self.winnerDisplay.setSize(20)
        

    def drawPlayers(self):
        circSpecs = [(3.5, 5), (5, 4), (5,2), (3.5, 1), (2,2), (2,4)]
        self.playerLabels = []
        self.playerCircles = []
        for i, (x, y) in enumerate(circSpecs):
            self.playerCircles.append(Circle(Point(x, y), 0.5).draw(self.win))
            self.playerLabels.append(Text(Point(x,y), "Player {0}".format(i+1)).draw(self.win))

    def drawMoneyDisplays(self):
        displaySpecs = [(3.5, 5.7), (5, 4.7), (5, 2.7), (3.5, 1.7), (2,2.7),
                              (2, 4.7)]
        self.moneyDisplays = []
        for x, y in displaySpecs:
            Rectangle(Point(x-0.4, y - 0.12), Point(x + 0.4, y + 0.12)).draw(self.win)
            self.moneyDisplays.append(Text(Point(x,y), "").draw(self.win))

    def drawDice(self):
        self.dieOne = DieView(self.win, Point(2.9, 3), 0.5)
        self.dieTwo = DieView(self.win, Point(3.5, 3.6), 0.5)
        self.dieThree = DieView(self.win, Point(4.1, 3), 0.5)
        
    def continuePlaying(self):
        self.continueButton.activate()
        
        while True:
            try:
                p = self.win.checkMouse()
                if self.continueButton.clicked(p):
                    self.continueButton.deactivate()
                    return True
            except AttributeError as error:
                pass
        
    def activePlayers(self, playerList):
        self.resultDisplay.setText("")
        self.winnerDisplay.setText("")
        for i, player in enumerate(playerList):
            if player.getMoney() >= 10:
                self.playerCircles[i].setFill("green")
                self.playerLabels[i].setStyle("bold")
                
    def currentPlayer(self, pIndex):
        self.playerCircles[pIndex].setFill("orange")

    def resetPlayerColor(self, pIndex):
        self.playerCircles[pIndex].setFill("green")

    def resetDoubleColor(self, pIndex):
        self.playerCircles[pIndex].setFill("pink")
        
    def displayMoney(self, pIndex, money):
        self.moneyDisplays[pIndex].setText("$ {0}".format(str(money)))
        
    def roll(self):
        self.rollButton.activate()

        while True:
            try:
                p = self.win.checkMouse()
                if self.rollButton.clicked(p):
                    self.rollButton.deactivate()
                    return True
            except AttributeError as error:
                pass

    def displayResult(self, pIndex, player):
        # this method has to display the DieView as well as the result/score
        # of the roll

        values = player.values()
        self.dieOne.setValue(values[0])
        self.dieTwo.setValue(values[1])
        self.dieThree.setValue(values[2])

        result, score = player.playerScore()
        self.resultDisplay.setText("{0}".format(result))

    def displayWinner(self, winner):
        self.winnerDisplay.setText("Player {0} wins!".format(str(winner + 1)))
        
    def doubleColor(self, indexList):
        for pIndex in indexList:
            self.playerCircles[pIndex].setFill("pink")

    def doubleDown(self):
        self.winnerDisplay.setText("Double Down!")
Пример #6
0
 def setValue(self, value):
     self.value = value
     DieView.setValue(self, value)