コード例 #1
0
def MainMenu():

    game_run = True
    while game_run:
        gameDisplay.fill((0, 150, 0))
        pos, pressed = pygame.mouse.get_pos(), pygame.mouse.get_pressed()
        gameDisplay.blit(font_60.render("Block Tower Defense", True, (0, 0, 0)), (130, 150))

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

        pygame.draw.rect(gameDisplay, (150, 0, 0), (340, 320, 150, 75), 0)
        pygame.draw.rect(gameDisplay, (100, 0, 0), (340, 320, 150, 75), 2)
        gameDisplay.blit(font_20.render("New Game", True, (0, 0, 0)), (365, 350))
        if 340 <= pos[0] <= 490 and 320 <= pos[1] <= 395 and pressed[0] == 1:
            main.game_loop(False)

        pygame.draw.rect(gameDisplay, (150, 0, 0), (150, 320, 150, 75), 0)
        pygame.draw.rect(gameDisplay, (100, 0, 0), (150, 320, 150, 75), 2)
        gameDisplay.blit(font_20.render("Continue", True, (0, 0, 0)), (180, 350))
        if 150 <= pos[0] <= 300 and 320 <= pos[1] <= 395 and pressed[0] == 1:
            main.game_loop(True)

        pygame.draw.rect(gameDisplay, (150, 0, 0), (530, 320, 150, 75), 0)
        pygame.draw.rect(gameDisplay, (100, 0, 0), (530, 320, 150, 75), 2)
        gameDisplay.blit(font_20.render("Nothing Yet", True, (0, 0, 0)), (550, 350))
        

        pygame.display.flip()
        fpsClock.tick(fps)
コード例 #2
0
def callback(update, context):
    if update.effective_chat.type == "private":
        user_id = update.effective_user.id
        if user_id in send_return_back_to_game and len(
                send_return_back_to_game[user_id]) != 0:
            game_id = send_return_back_to_game[user_id].pop(0)
            choice = update["message"]["text"]

            if is_user_czar(game_id, user_id) and czar_round(game_id):
                user_id_choice = get_user_id_from_choice(game_id, choice)
                if user_id_choice == -1:
                    send_choice_to_czar(update, context, game_id)
                    return
                current_game = games[game_id]
                current_game["scores"][user_id_choice] += 1
                player_name_score = user_ids[user_id_choice]["info"][
                    "first_name"]

                back_card_text = get_current_black_card(game_id)['text']
                msg = format_msg(f'''
                        Czar chose..
                        *{back_card_text}*
                        {choice}

                        Player {player_name_score} gets a point!
                ''')
                send_message_to_players(update, context, game_id, msg)
                game_loop(update, context, game_id)
                return

            card_choice = check_if_choose_was_correct(game_id, user_id, choice)
            if card_choice == -1:
                send_cards_choice_to_user(update, context, game_id, user_id)

            current_game = games[game_id]
            current_game["card_choice"][user_id].append(card_choice)

            if czar_round(game_id):
                czar_possible_choices = create_cards_choice_czar_dict(game_id)
                msg = "All players have chosen their cards!\n"
                choices = list(czar_possible_choices.values())
                random.shuffle(choices)
                for c in choices:
                    msg += c + "\n"
                send_message_to_players(update, context, game_id, msg)
                send_choice_to_czar(update, context, game_id)
            else:
                how_many_cards_to_choose = get_current_black_card(
                    game_id)["pick"]
                how_many_cards_did_player_choose = len(
                    current_game["card_choice"][user_id])
                if how_many_cards_did_player_choose < how_many_cards_to_choose:
                    send_cards_choice_to_user(update, context, game_id,
                                              user_id)
コード例 #3
0
    def test_min_max_perf(self):

        white = players.BasicMinMaxPlayer(search_depth=2)
        black = players.BasicMinMaxPlayer(search_depth=2)
        # black = players.BetterMinMaxPlayer(search_depth=3)
        # black = players.HumanPlayer()

        start = time()
        main.game_loop(white, black, wait=0)
        end = time()

        process_time = end - start
        self.assertLessEqual(process_time, 30)
コード例 #4
0
def handle_czar_choice(choice, context, game_id, update):
    user_id_choice = get_user_id_from_choice(game_id, choice)
    if user_id_choice == -1:
        send_choice_to_czar(update, context, game_id)
        return
    current_game = games[game_id]
    current_game["scores"][user_id_choice] += 1
    player_name_score = user_ids[user_id_choice]["info"]["first_name"]
    back_card_text = get_current_black_card(game_id)['text']
    msg = format_msg(f'''
                        The Czar chose!
                        <b>{back_card_text}</b>

                        {point_right} {choice}

                        Human <b>{player_name_score}</b> gets a point!
                ''')
    send_message_to_players(update, context, game_id, msg)
    game_loop(update, context, game_id)
    return
コード例 #5
0
def run():
    parts = {
        "head": "O",
        "torso": "|",
        "l_arm": "-",
        "r_arm": "-",
        "l_leg": "/",
        "r_leg": "\\"
    }
    print(
        main.game_loop({
            "lives": 6,
            "word": "hangman".lower(),
            "guess": [],
            "body": {},
            "parts": parts,
            "letters": []
        }))
コード例 #6
0
def HomeScreen(pygame, gameDisplay, Fonts, clock, MusicPaused):
    global AnimationStage, Count, Images
    import main
    run = True
    screen = "Main"
    height = 20
    width = 20
    Images = []
    Images = load_images("Images", 8, 8)
    MenuBoard = gen_Board([[0] * height for _ in range(width)], height, width)
    AnimationStage = {
        "Water": [1, 0.5],
        "FishingBoat": [1, 0.5],
        "Dam": [1, 0.5]
    }
    x = 0
    y = 0

    while run:
        gameDisplay.fill((0, 100, 255))

        Count = {
            "Water": 0,
            "FishingBoat": 0,
            "Dam": 0,
            "Forest Lv4": 0,
            "Quarry Lv4": 0,
            "Super Factory": 0
        }
        for j in range(height):
            for i in range(width):
                if MenuBoard[j][i] == "Water" or MenuBoard[j][
                        i] == "FishingBoat" or MenuBoard[j][i] == "Dam":
                    Count["Water"] += 1
                if MenuBoard[j][i] == "FishingBoat":
                    Count["FishingBoat"] += 1
                if MenuBoard[j][i] == "Dam":
                    Count["Dam"] += 1
                if MenuBoard[j][i] == "Forest Lv4":
                    Count["Forest Lv4"] += 1
                if MenuBoard[j][i] == "Quarry Lv4":
                    Count["Quarry Lv4"] += 1
                if MenuBoard[j][i] == "Super Factory":
                    Count["Super Factory"] += 1

        # Drawing all the tiles plus some extra to make it loop seemlessly
        for j in range(height):
            for i in range(width):
                main.draw(i * 80 + x, j * 80 + y, "Tile", MenuBoard[j][i], 8,
                          8, Images, AnimationStage, Count)
                main.draw(i * 80 + x + 1600, j * 80 + y, "Tile",
                          MenuBoard[j][i], 8, 8, Images, AnimationStage, Count)
                main.draw(i * 80 + x, j * 80 + y + 1600, "Tile",
                          MenuBoard[j][i], 8, 8, Images, AnimationStage, Count)
                main.draw(i * 80 + x + 1600, j * 80 + y + 1600, "Tile",
                          MenuBoard[j][i], 8, 8, Images, AnimationStage, Count)

        # Moving around tiles on screen by -x & -y
        x -= 2
        y -= 2

        if y < -1600:
            y = 0
            x = 0

        pos = pygame.mouse.get_pos()
        # Event checking mainly for clicking on the buttons
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if 400 <= pos[0] <= 600 and 600 <= pos[
                        1] <= 700 and screen == "Main":
                    main.game_loop(8, 8, 0, False)
                if 825 <= pos[0] <= 925 and 800 <= pos[
                        1] <= 900 and screen == "Main":
                    screen = "Options"
                if 625 <= pos[0] <= 925 and 500 <= pos[
                        1] <= 900 and screen == "Main":
                    screen = "New Game"
                if 775 <= pos[0] <= 975 and pos[1] >= 675 and pos[
                        1] <= 775 and screen == "Options":
                    screen = "Main"
                if 175 <= pos[0] <= 375 and 600 <= pos[
                        1] <= 700 and screen == "Main":
                    main.game_loop(8, 8, 0, True)
                # Give user option to mute the background music
                if pos[0] >= 200 and pos[0] <= 400 and pos[1] >= 50 and pos[
                        1] <= 150 and screen == "Options":
                    if MusicPaused == False:
                        MusicPaused = True
                        pygame.mixer.music.pause()
                    else:
                        MusicPaused = False
                        pygame.mixer.music.unpause()

        # Shows Main screen text and buttons
        if screen == "Main":
            text_surface, rect = Fonts[2].render("Grand Command",
                                                 (242, 43, 35))
            gameDisplay.blit(text_surface, (220, 50))
            # mouse hover & un-hover location
            if 600 <= pos[0] <= 830 and 620 <= pos[1] <= 840:
                # box location not-hover
                pygame.draw.rect(gameDisplay, (150, 0, 0),
                                 (580, 800, 200, 100), 0)
            else:
                # box location on-hover
                pygame.draw.rect(gameDisplay, (255, 0, 0),
                                 (580, 800, 200, 100), 0)

            text_surface, rect = Fonts[1].render("New Game", (0, 0, 0))
            gameDisplay.blit(text_surface, (600, 830))

            # mouse clickable to options -> menu for mute sound atm
            if 825 <= pos[0] <= 925 and 850 <= pos[1] <= 900:
                # box location not-hover
                pygame.draw.rect(gameDisplay, (150, 0, 0),
                                 (840, 800, 200, 100), 0)
            else:
                # box location on-hover
                pygame.draw.rect(gameDisplay, (255, 0, 0),
                                 (840, 800, 200, 100), 0)

            text_surface, rect = Fonts[1].render("Options", (0, 0, 0))
            gameDisplay.blit(text_surface, (880, 830))

            # Shows the options menu
        if screen == "Options":
            if pos[0] >= 775 and pos[0] <= 975 and pos[1] >= 675 and pos[
                    1] <= 775:
                pygame.draw.rect(gameDisplay, (150, 0, 0),
                                 (775, 675, 200, 100), 0)
            else:
                pygame.draw.rect(gameDisplay, (255, 0, 0),
                                 (775, 675, 200, 100), 0)

            text_surface, rect = Fonts[1].render("Back", (0, 0, 0))
            gameDisplay.blit(text_surface, (835, 705))

            if 200 <= pos[0] <= 400 and 50 <= pos[1] <= 150:
                pygame.draw.rect(gameDisplay, (150, 0, 0), (200, 50, 200, 100),
                                 0)
            else:
                pygame.draw.rect(gameDisplay, (255, 0, 0), (200, 50, 200, 100),
                                 0)

            if MusicPaused == False:
                text_surface, rect = Fonts[1].render("Mute Music", (0, 0, 0))
                gameDisplay.blit(text_surface, (210, 80))
            else:
                text_surface, rect = Fonts[0].render("Unmute Music", (0, 0, 0))
                gameDisplay.blit(text_surface, (210, 86))

        pygame.display.flip()
        clock.tick(120)
コード例 #7
0
import pygame

from main import game_loop, PlayMode

if __name__ == "__main__":
    pygame.init()
    pygame.display.set_caption("PANG")
    game_loop(play_mode=PlayMode.REPLAY,
              online=False,
              replay_file="data/recording.json",
              center_msg="Enjoy your last play!")
    pygame.quit()
コード例 #8
0
ファイル: MainMenu.py プロジェクト: twoutlook/Merge-Blocks
def HomeScreen():
    game_run = True
    Colors = [(255,0,0),(255,128,0),(255,255,0),(128,255,0),(0,255,128),(0,255,255),
              (0,128,255),(0,0,255),(127,0,255),(255,0,255),(255,0,127), (0,0,0)]
    Buttons = [Button(100,525,200,100,"New Game"),Button(400,525,200,100,"Continue"),Button(100,650,200,100,"Credits"),Button(400,650,200,100,"Options")]
    ExtraButtons = [Button(400,650,200,100,"Exit")]
    screen = "Main"

    while game_run == True:

        pos = pygame.mouse.get_pos()

        #Drawing Background and title screen
        gameDisplay.fill((0,200,200))

        if screen == "Main":
            text_surface, rect = font_75.render(("Merge Blocks"), (0, 0, 0))
            gameDisplay.blit(text_surface, (130, 100))
            for button in Buttons:
                button.draw()
        elif screen == "Credits":
            ExtraButtons[0].draw()
            text_surface, rect = font_50.render(("Programmer: 8BitToaster"), (0, 0, 0))
            gameDisplay.blit(text_surface, (170, 100))
            text_surface, rect = font_50.render(("Helper: INNERBOOST"), (0, 0, 0))
            gameDisplay.blit(text_surface, (200, 150))
            text_surface, rect = font_50.render(("Go Check out these channels:"), (0, 0, 0))
            gameDisplay.blit(text_surface, (150, 300))
            text_surface, rect = font_50.render(("The8BitToaster - The Main Programmer"), (0, 0, 0))
            gameDisplay.blit(text_surface, (75, 350))
            text_surface, rect = font_50.render(("ZJ Sketches - A Good Friend"), (0, 0, 0))
            gameDisplay.blit(text_surface, (170, 400))
        elif screen == "Options":
            ExtraButtons[0].draw()
            text_surface, rect = font_50.render(("Coming Soon"), (0, 0, 0))
            gameDisplay.blit(text_surface, (250, 300))
    
    

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if screen == "Main":
                    for button in Buttons:
                        if button.x <= pos[0] <= button.x + button.width and button.y <= pos[1] <= button.y + button.height:
                            if button.text == "New Game":
                                main.game_loop("New")
                            if button.text == "Continue":
                                main.game_loop("Continue")
                            if button.text == "Credits":
                                screen = "Credits"
                            if button.text == "Options":
                                screen = "Options"
                elif screen == "Credits" or screen == "Options":
                    for button in ExtraButtons:
                        if button.x <= pos[0] <= button.x + button.width and button.y <= pos[1] <= button.y + button.height:
                            screen = "Main"


        pygame.display.flip()
        clock.tick(60)
コード例 #9
0
    window.blit(bg, (0, 0))
    #window.blit(dim_screen, (0, 0))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            menu = False
        if menu:
            play_btn.draw(window, False)
            quit_btn.draw(window, False)
        pos = pygame.mouse.get_pos()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if play_btn.is_over(pos):
                pick_background.pick_background(window)
                if pick_background.exit_game:
                    menu = False
                else:
                    main.game_loop()
                if main.game_quit:
                    menu = False
            if quit_btn.is_over(pos):
                menu = False

        if event.type == pygame.MOUSEMOTION:
            if play_btn.is_over(pos):
                if play_1:
                    hover_btn.play()
                    play_1 = False
                play_btn.image = play_btn_toggle_img
            elif not play_btn.is_over(pos):
                play_1 = True
                play_btn.image = play_btn_img
            if quit_btn.is_over(pos):
コード例 #10
0
def HomeScreen(score=0):
    game_run = True
    Buttons = [
        Button(275, 600, 200, 100, "Play"),
        Button(525, 600, 200, 100, "Change Color")
    ]
    CcButtons = [
        Button(750, 650, 200, 100, "Exit"),
        Button(150, 250, 50, 50, ""),
        Button(800, 250, 50, 50, "")
    ]
    screen = "Main"
    Colors = [(0, 250, 0), (250, 0, 0), (0, 0, 250), (255, 255, 0),
              (0, 255, 255)]
    SubColors = [(0, 150, 0), (150, 0, 0), (0, 0, 150), (150, 150, 0),
                 (0, 150, 150)]
    ColorSelection = 0
    Images = load_images("Images")

    while game_run == True:

        gameDisplay.fill((210, 140, 42))
        #gameDisplay.blit(pygame.transform.scale(Images["Bg"],(DisplayWidth,DisplayHeight)),(0,0))
        pos = pygame.mouse.get_pos()
        if screen == "Main":
            text_surface, rect = font_100.render(("Fruit Slasher"), (0, 0, 0))
            gameDisplay.blit(text_surface, (220, 100))

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if screen == "Main":
                    for i, button in enumerate(Buttons):
                        if button.x <= pos[
                                0] <= button.x + button.width and button.y <= pos[
                                    1] <= button.y + button.height:
                            if i == 0:
                                main.game_loop([
                                    Colors[ColorSelection],
                                    SubColors[ColorSelection]
                                ])
                            if i == 1:
                                screen = "Change Color"
                if screen == "Change Color":
                    for i, button in enumerate(CcButtons):
                        if button.x <= pos[
                                0] <= button.x + button.width and button.y <= pos[
                                    1] <= button.y + button.height:
                            if i == 0:
                                screen = "Main"
                            if i == 1:
                                ColorSelection += 1
                                ColorSelection %= (len(Colors))
                            if i == 2:
                                ColorSelection -= 1
                                if ColorSelection < 0:
                                    ColorSelection = len(Colors) - 1

        if screen == "Main":
            if score != 0:
                text_surface, rect = font_75.render(
                    ("Score: " + shorten(score)), (0, 0, 0))
                gameDisplay.blit(
                    text_surface,
                    (440 - SizeCheck_75.size(shorten(score))[0], 300))

            #Updating the buttons
            for button in Buttons:
                button.draw()

        if screen == "Change Color":
            for button in CcButtons:
                button.draw()
            pygame.draw.rect(gameDisplay, Colors[ColorSelection],
                             (350, 200, 300, 150), 0)
            pygame.draw.rect(gameDisplay, SubColors[ColorSelection],
                             (350, 200, 300, 150), 5)
            pygame.draw.polygon(gameDisplay, (150, 150, 150), [(808, 259),
                                                               (808, 289),
                                                               (838, 274)], 0)
            pygame.draw.polygon(gameDisplay, (150, 150, 150), [(192, 259),
                                                               (192, 289),
                                                               (162, 274)], 0)

        pygame.display.flip()
        clock.tick(60)
コード例 #11
0
ファイル: mainMenu.py プロジェクト: xchsp/Block-Tower-Defense
def MainMenu():

    Images = load_images("Images")
    game_run = True
    screen = "Main"
    step = 0
    cooldown = False
    Names = [["Classic", "Twisty Towers"]]
    SaveNames = ["Default", "Twisty"]
    Diff = ["Easy", "Medium", "Hard"]
    file = open("SaveFile/saveFile.txt", "r")
    data = file.readline().split("#")
    if len(data) != 4:
        data = ["0", "Medium", "0", "Medium"]
    
    while game_run:
        gameDisplay.fill((0, 150, 0))
        pos, pressed = pygame.mouse.get_pos(), pygame.mouse.get_pressed()

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

        if screen == "Main":
            gameDisplay.blit(font_60.render("Block Tower Defense", True, (0, 0, 0)), (130, 150))

            pygame.draw.rect(gameDisplay, (150, 0, 0), (340, 320, 150, 75), 0)
            pygame.draw.rect(gameDisplay, (100, 0, 0), (340, 320, 150, 75), 2)
            gameDisplay.blit(font_20.render("Play", True, (0, 0, 0)), (395, 340))
            if 340 <= pos[0] <= 490 and 320 <= pos[1] <= 395 and pressed[0] == 1:
                screen = "Map Select"
                cooldown = True


        elif screen == "Map Select":

            if step == 0:
                gameDisplay.blit(pygame.transform.scale(Images["Meadows"], (200, 150)), (100, 100))
                gameDisplay.blit(pygame.transform.scale(Images["TwistyTowers"], (200, 150)), (350, 100))
                if 100 <= pos[0] <= 300 and 100 <= pos[1] <= 250 and pressed[0] == 1 and not cooldown:
                    screen = "Dif Select"
                    Map = "Classic"
                    MapName = "Default"
                if 350 <= pos[0] <= 550 and 100 <= pos[1] <= 250 and pressed[0] == 1 and not cooldown:
                    screen = "Dif Select"
                    Map = "Twisty Towers"
                    MapName = "Twisty"
                    
 
            for i in range(2):
                pygame.draw.rect(gameDisplay, (100, 100, 100), (100+250*i, 100, 200, 150), 2)
                gameDisplay.blit(font_20.render(Names[step][i], True, (0, 0, 0)), (200+250*i-int(font_20.size(Names[step][i])[0]/2), 70))
                
            if pressed[0] == 0:
                cooldown = False


            pygame.draw.rect(gameDisplay, (100, 0, 0), (10, 10, 100, 75), 0)
            pygame.draw.rect(gameDisplay, (200, 0, 0), (10, 10, 100, 75), 3)
            gameDisplay.blit(font_30.render("Back", True, (0, 0, 0)), (25, 20))
            if 10 <= pos[0] <= 110 and 10 <= pos[1] <= 85 and pressed[0] == 1 and not cooldown:
                screen = "Main"
                cooldown = True
        elif screen == "Dif Select":
            gameDisplay.blit(font_60.render(Map, True, (0, 0, 0)), (400-int(font_60.size(Map)[0]/2), 20))


            #Different Difficulty Buttons
            for i in range(3):
                pygame.draw.rect(gameDisplay, (0, 100, 0), (50+250*i, 400, 200, 150), 0)
                pygame.draw.rect(gameDisplay, (0, 200, 0), (50+250*i, 400, 200, 150), 3)
                gameDisplay.blit(font_30.render(Diff[i], True, (0, 0, 0)), (150+250*i-int(font_30.size(Diff[i])[0]/2), 440))

                if 50+250*i <= pos[0] <= 50+250*i+200 and 400 <= pos[1] <= 550 and pressed[0] == 1 and not cooldown:
                    main.game_loop(False, MapName, Diff[i])

            #The Continue Button
            pygame.draw.rect(gameDisplay, (0, 100, 0), (50, 290, 120, 95), 0)
            pygame.draw.rect(gameDisplay, (0, 200, 0), (50, 290, 120, 95), 3)
            gameDisplay.blit(font_20.render("Continue", True, (0, 0, 0)), (60, 330))


            #Displays wave and difficulty of your continue
            gameDisplay.blit(font_20.render("Wave: " + str(data[SaveNames.index(MapName)*2]), True, (0, 0, 0)), (60, 310))
            if data[SaveNames.index(MapName)*2+1] != "0":
                gameDisplay.blit(font_20.render(str(data[SaveNames.index(MapName)*2+1]), True, (0, 0, 0)), (60, 290))
            else:
                gameDisplay.blit(font_20.render("Medium", True, (0, 0, 0)), (60, 290))

            if 50 <= pos[0] <= 170 and 290 <= pos[1] <= 385 and pressed[0] == 1 and not cooldown:
                main.game_loop(True, MapName)
            
            #The Back Button
            pygame.draw.rect(gameDisplay, (100, 0, 0), (10, 10, 100, 75), 0)
            pygame.draw.rect(gameDisplay, (200, 0, 0), (10, 10, 100, 75), 3)
            gameDisplay.blit(font_30.render("Back", True, (0, 0, 0)), (25, 20))

            if 10 <= pos[0] <= 110 and 10 <= pos[1] <= 85 and pressed[0] == 1 and not cooldown:
                screen = "Map Select"
                cooldown = True

            if pressed[0] == 0:
                cooldown = False

        pygame.display.flip()
        fpsClock.tick(fps)