def lose_screen(wave_number):
    pygame.mixer.music.stop()
    pygame.mixer.Sound.play(lose_sound)
    display.blit(LOSE_BACKGROUND, [0, 0])
    title_text = DEATH_MESSAGE
    title = Text(display, CENTER_X, CENTER_Y - 200, title_text, TITLE, RED)
    wave_text = "You Got To Wave: " + str(wave_number)
    wave = Text(display, CENTER_X, CENTER_Y - 100, wave_text, TITLE, RED)
    x = CENTER_X - 225
    y = CENTER_Y
    start_button = Button(display, x, y, 200, 100, "MENU", TEXT, GREEN, WHITE)
    x = CENTER_X
    quit_button = Button(display, x, y, 200, 100, "QUIT", TEXT, RED, WHITE)

    pygame.mixer.music.load("menu_theme.mp3")
    pygame.mixer.music.play(-1)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

            elif event.type == pygame.MOUSEBUTTONDOWN:
                if start_button.clicked():
                    pygame.mixer.music.stop()
                    menu()
                elif quit_button.clicked():
                    pygame.quit()
                    quit()

        pygame.display.flip()
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
def menu():
    display.fill(BLACK)
    title_text = NAME
    title = Text(display, CENTER_X, CENTER_Y - 100, title_text, TITLE, RED)
    x = CENTER_X - 350
    y = CENTER_Y
    start_button = Button(display, x, y, 200, 100, "PLAY", TEXT, GREEN, WHITE)
    x = CENTER_X - 100
    start_button2 = Button(display, x, y, 200, 100, "AI", TEXT, BLUE, WHITE)
    x = CENTER_X + 150
    quit_button = Button(display, x, y, 200, 100, "QUIT", TEXT, RED, WHITE)
    y = CENTER_Y + 110
    x = CENTER_X - 250
    fullscreen_button = Button(display, x, y, 500, 100, "TOGGLE FULLSCREEN",
                               TEXT, BLACK, WHITE)

    pygame.mixer.music.load("menu_theme.mp3")
    pygame.mixer.music.play(-1)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if start_button.clicked():
                    pygame.mixer.music.stop()
                    return play()
                elif start_button2.clicked():
                    pygame.mixer.music.stop()
                    return ai_play()
                elif fullscreen_button.clicked():
                    return screen()
                elif quit_button.clicked():
                    pygame.quit()
                    quit()

        pygame.display.flip()
예제 #4
0
def menu():
    display = pygame.display.set_mode((WIDTH, HEIGHT))
    display.fill(GREY)
    display.blit(face, (180, 150))
    title_text = "Minesweeper"
    title = Text(display, int(WIDTH / 2),
                 int((HEIGHT / 2)) - 100, title_text, TITLE, (0, 0, 0))
    quit_button = Button(display,
                         int(WIDTH / 2) - 50, 300, 100, 50, "QUIT", TITLE, RED,
                         BLACK)

    easy = Button(display, 60, 200, 75, 50, "Easy", TEXT, GREEN, BLACK)
    medium = Button(display, 160, 200, 75, 50, "Medium", TEXT, ORANGE, BLACK)
    hard = Button(display, 260, 200, 75, 50, "Hard", TEXT, RED, BLACK)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if easy.clicked():
                    channel1.play(click)
                    play(0)
                elif medium.clicked():
                    channel1.play(click)
                    play(1)
                elif hard.clicked():
                    channel1.play(click)
                    play(2)
                elif quit_button.clicked():
                    channel1.play(click)
                    pygame.quit()
                    quit()

        pygame.display.flip()
예제 #5
0
def win(score):
    clear()
    display = pygame.display.set_mode((400, 400))
    display.fill(GREY)
    menu_button = Button(display, 150, 200, 75, 50, "Menu", TEXT, BLACK, GREY2)
    score_text = Text(display, 200, 125, "Score: " + str(score), TITLE, BLACK)
    title = Text(display, 200, 50, "Victory!", TITLE, BLACK)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if menu_button.clicked():
                    channel1.play(click)
                    menu()

        pygame.display.update()
예제 #6
0
def play(difficulty):
    clock = 0
    generate_grid(SIZES[difficulty])
    display.fill(GREY)
    empties.draw(display)
    menu_button = Button(display, 0, 0, 100, 0, "Menu", TEXT, BLACK, GREY2)
    time_text = Text(display, 101, 0, "Your Time: " + str(clock), TEXT, RED2)
    org_time = time.time()

    while True:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

            elif event.type == pygame.MOUSEBUTTONDOWN:
                if menu_button.clicked():
                    channel1.play(click)
                    lose()
                pos = pygame.mouse.get_pos()
                for tile in tiles:
                    if tile.rect.collidepoint(pos):
                        channel1.play(click)
                        tile.clicked()

        won = True
        for tile in tiles:
            if tile.state != 3 and tile.action == False:
                won = False
        if won == True:
            score = 0
            for _ in tiles:
                score += 1
            score = (score * 2) - clock
            win(score)

        tiles.update()
        tiles.draw(display)

        # blit here
        display.blit(bar, (0, 0))
        menu_button = Button(display, 0, 0, 100, 25, "Menu", TEXT, BLACK,
                             GREY2)
        time_text = Text(display, 112, 12, str(clock), TEXT, RED2)

        if len(lost) != 0:
            for t in tiles:
                if t.state == 3 and t.image != flag:
                    t.image = mine
            tiles.update()
            tiles.draw(display)
            pygame.display.flip()
            channel2.play(defeat)
            time.sleep(2)
            lose()

        if (time.time() - org_time) > 1:
            clock += 1
            org_time = time.time()

        pygame.display.update()
예제 #7
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