def main():

    #Creates a greeting window using a image taken from the internet to allow the player to choose to: Play or Quit
    gameImage = Image(Point(180, 180), "parchessi.png")
    window = GraphWin("Parcheesi", 360, 360)
    gameImage.draw(window)

    #Creates the Buttons for Play or Quit using the Class Button
    playButton = Button(window, Point(180.0, 200), 80, 30, "Play")
    quitButton = Button(window, Point(180.0, 240), 80, 30, "QUIT")
    playButton.activate()
    quitButton.activate()

    pt = window.getMouse()  #Gets the users click on which button

    if not quitButton.clicked(
            pt):  #if the Play button is clicked, the game begins
        window.close(
        )  #closes the previous window so that the game window in the only one remaining
        win = GraphWin("Parcheesi", 820,
                       620)  #We declare and define our window
        field = inheritanceBoard(
        )  #we make an object from the inheritanceBoard class so that the user may customize the board game (colors) if desired
        game = Game()  #creates the object from Game class

        field.board(win)  #draws the board
        game.playGame(win)  #starts the game
예제 #2
0
    def playGame(self, win): #main function that runs the game

        #creates buttons for roll dice and quit
        rollButton = Button(win, Point(720.0, 45), 80, 30, "Roll Dice") 
        quitButton = Button(win, Point(720.0, 510), 80, 30, "QUIT")
        rollButton.activate()
        quitButton.activate()

        pt = win.getMouse()#Gets the users click on which button
        turn = 0 #variable used to create turns for each player
        counter = 0 #variable used to keep count of the times the user gets a double die 

        while not quitButton.clicked(pt): #while the player doesn't click Quit the game continues

            if turn == 0: #starts player red's turn
                if rollButton.clicked(pt): #checks if the player clicks roll dice, if true then their turn proceeds
                    self.board.playerTurn("Red", win) #calls the function that draws in the menu who's player's turn it is
                    dice1, dice2 = self.rollDice(win) #calls the function to roll the dice and returns the values for each one
                    if self.players[0].returnChips() > 0:#calls the function returnChips() to determine available chips in the player's home, if true then proceeds
                        checkMove, dice = self.startHome(dice1, dice2, "red", win) #calls function startHome to check if the player rolled a 5 on either dice and returns the value of the other
                        if checkMove:#true if the player rolled a 5 on either die
                            self.players[0].MovePiece(self.players[0].player, dice, dice1, dice2, "red", #calls function that moves the player's piece according to the dice value returned after rolling 5
                                                      self.players[0].returnSteps(), win)
                            self.eatPlayer("red", win) #calls function that checks if the player ate another player

                    elif self.players[0].returnChips() == 0: #calls function that checks the players available chips, if true then proceeds
                        dice = dice1 + dice2 #sums both die values 
                        self.players[0].MovePiece(self.players[0].player, dice, dice1, dice2, "red", # calls function that moves the player's piece according to the sum of both die
                                                  self.players[0].returnSteps(), win)
                        self.eatPlayer("red", win) #calls function that checks if the player ate another player

                    if self.doubleTurn(dice1, dice2): #calls funciton to check both die values, if true then proceeds to create another turn
                        counter += 1 #adds one to counter to keep track of doubles
                        turn = 0 #sets turn = 0 so that its player Red's turn again
                        #prints a text in the menu letting the player know its their turn again
                        turnAgain = Text(Point(720.0, 300), "Your turn again") 
                        turnAgain.setStyle("bold")
                        turnAgain.setSize(16)
                        turnAgain.draw(win)
                        win.getMouse()
                        turnAgain.undraw()

                        if counter == 2: #once counter hits 2, the player's turn is skipped
                            turn += 1 #adds one to turn to continue to next player
                            counter = 0 #resets counter = 0
                            skip = Text(Point(720.0, 300), "Next player's turn") #prints in the menu that it's the next player's turn
                            skip.setStyle("bold")
                            skip.setSize(16)
                            skip.draw(win)
                            win.getMouse()
                            skip.undraw()
                    else: #if no double was rolled then proceeds
                        turn += 1 #adds one to turn to continue to next player
                        counter = 0 #resets counter = 0
                        skip = Text(Point(720.0, 300), "Next player's turn")#prints in the menu that it's the next player's turn
                        skip.setStyle("bold")
                        skip.setSize(16)
                        skip.draw(win)
                        win.getMouse()
                        skip.undraw()

                    if self.players[0].playerWon(self.players[0].piecesInHome(), win): #calls function that checks if the player won
                        win.getMouse()
                        win.close() #closes the window if player won

                    pt = win.getMouse() #resets the click for the next player

            elif turn == 1: #blue player's turn, everything works as mentioned above

                if rollButton.clicked(pt):
                    self.board.playerTurn("Blue", win)
                    dice1, dice2 = self.rollDice(win)
                    if self.players[1].returnChips() > 0:
                        checkMove, dice = self.startHome(dice1, dice2, "blue", win)
                        if checkMove:
                            self.players[1].MovePiece(self.players[1].player, dice, dice1, dice2, "blue",
                                                      self.players[1].returnSteps(), win)
                            self.eatPlayer("blue", win)

                    elif self.players[1].returnChips() == 0:
                        self.players[1].MovePiece(self.players[1].player, dice, dice1, dice2, "blue",
                                                  self.players[1].returnSteps(), win)
                        self.eatPlayer("blue", win)

                    if self.doubleTurn(dice1, dice2):
                        counter += 1
                        turn = 1
                        turnAgain = Text(Point(720.0, 300), "Your turn again")
                        turnAgain.setStyle("bold")
                        turnAgain.setSize(16)
                        turnAgain.draw(win)
                        win.getMouse()
                        turnAgain.undraw()
                        if counter == 2:
                            turn += 1
                            counter = 0
                            skip = Text(Point(720.0, 300), "Next player's turn")
                            skip.setStyle("bold")
                            skip.setSize(16)
                            skip.draw(win)
                            win.getMouse()
                            skip.undraw()

                    else:
                        turn += 1
                        counter = 0
                        skip = Text(Point(720.0, 300), "Next player's turn")
                        skip.setStyle("bold")
                        skip.setSize(16)
                        skip.draw(win)
                        win.getMouse()
                        skip.undraw()

                    if self.players[1].playerWon(self.players[1].piecesInHome(), win):
                        win.getMouse()
                        win.close()

                    pt = win.getMouse()



            elif turn == 2: #green player's turn, everything works as mentioned above

                if rollButton.clicked(pt):
                    self.board.playerTurn("Green", win)
                    dice1, dice2 = self.rollDice(win)
                    if self.players[2].returnChips() > 0:
                        checkMove, dice = self.startHome(dice1, dice2, "green", win)
                        if checkMove:
                            self.players[2].MovePiece(self.players[2].player, dice, dice1, dice2, "green",
                                                      self.players[2].returnSteps(), win)
                            self.eatPlayer("green", win)

                    elif self.players[2].returnChips() == 0:
                        dice = dice1 + dice2
                        self.players[2].MovePiece(self.players[2].player, dice, dice1, dice2, "green",
                                                  self.players[2].returnSteps(), win)
                        self.eatPlayer("green", win)

                    if self.doubleTurn(dice1, dice2):
                        counter += 1
                        turn = 2
                        turnAgain = Text(Point(720.0, 300), "Your turn again")
                        turnAgain.setStyle("bold")
                        turnAgain.setSize(16)
                        turnAgain.draw(win)
                        win.getMouse()
                        turnAgain.undraw()
                        if counter == 2:
                            turn += 1
                            counter = 0
                            skip = Text(Point(720.0, 300), "Next player's turn")
                            skip.setStyle("bold")
                            skip.setSize(16)
                            skip.draw(win)
                            win.getMouse()
                            skip.undraw()

                    else:
                        turn += 1
                        counter = 0
                        skip = Text(Point(720.0, 300), "Next player's turn")
                        skip.setStyle("bold")
                        skip.setSize(16)
                        skip.draw(win)
                        win.getMouse()
                        skip.undraw()

                    if self.players[2].playerWon(self.players[2].piecesInHome(), win):
                        win.getMouse()
                        win.close()

                    pt = win.getMouse()



            elif turn == 3: #yellow player's turn, everything works as mentioned above

                if rollButton.clicked(pt):
                    self.board.playerTurn("Yellow", win)
                    dice1, dice2 = self.rollDice(win)
                    if self.players[3].returnChips() > 0:
                        checkMove, dice = self.startHome(dice1, dice2, "yellow", win)
                        if checkMove:
                            self.players[3].MovePiece(self.players[3].player, dice, dice1, dice2, "yellow",
                                                      self.players[3].returnSteps(), win)
                            self.eatPlayer("yellow", win)

                    elif self.players[3].returnChips() == 0:
                        self.players[3].MovePiece(self.players[3].player, dice, dice1, dice2, "yellow",
                                                  self.players[3].returnSteps(), win)
                        self.eatPlayer("yellow", win)

                    if self.doubleTurn(dice1, dice2):
                        counter += 1
                        turn = 3
                        turnAgain = Text(Point(720.0, 300), "Your turn again")
                        turnAgain.setStyle("bold")
                        turnAgain.setSize(16)
                        turnAgain.draw(win)
                        win.getMouse()
                        turnAgain.undraw()
                        if counter == 2:
                            turn += 1
                            counter = 0
                            skip = Text(Point(720.0, 300), "Next player's turn")
                            skip.setStyle("bold")
                            skip.setSize(16)
                            skip.draw(win)
                            win.getMouse()
                            skip.undraw()

                    else:
                        turn += 1
                        counter = 0
                        skip = Text(Point(720.0, 300), "Next player's turn")
                        skip.setStyle("bold")
                        skip.setSize(16)
                        skip.draw(win)
                        win.getMouse()
                        skip.undraw()

                    if self.players[3].playerWon(self.players[3].piecesInHome(), win):
                        win.getMouse()
                        win.close()

                    pt = win.getMouse()


            elif turn == 4: #keeps the loop going starting back at the first player's turn
                turn = 0

                pt = win.getMouse() #resets click