Exemplo n.º 1
0
class GameOver(GameView):
    """Class to display the when game is over"""
    def setup_theme(self):
        self.theme = Theme()
        self.theme_2 = Theme()
        self.theme.set_font(24, arcade.color.BLACK)
        self.set_button_textures()

    def on_show(self):
        self.setup_theme()
        arcade.set_background_color(arcade.color.AMETHYST)
        self.play_button = PlayButton(self.WIDTH / 2 - 100,
                                      self.HEIGHT / 2 - 200,
                                      150,
                                      100,
                                      theme=self.theme,
                                      text='restart')
        self.exit_button = ExitButton(self.WIDTH / 2 + 100,
                                      self.HEIGHT / 2 - 200,
                                      150,
                                      100,
                                      theme=self.theme_2,
                                      text='exit')
        self.button_list.append(self.play_button)
        self.button_list.append(self.exit_button)

    def set_button_textures(self):
        #Play button
        normal = "img/buttons/green.png"
        hover = "img/buttons/pink.png"
        clicked = "img/buttons/red.png"
        locked = "img/buttons/blue.png"
        self.theme.add_button_textures(normal, hover, clicked, locked)

        #Exit button
        normal2 = "img/buttons/red.png"
        hover2 = "img/buttons/blue.png"
        clicked2 = "img/buttons/pink.png"
        locked2 = "img/buttons/green.png"
        self.theme_2.add_button_textures(normal2, hover2, clicked2, locked2)

    def on_draw(self):
        super().on_draw()

        if self.play_button.pressed:
            self.view.restart_game()

        if self.exit_button.pressed:
            arcade.close_window()
Exemplo n.º 2
0
def test_theme_button_texture():
    theme = Theme()
    assert theme.button_textures == {
        "normal": "",
        "hover": "",
        "clicked": "",
        "locked": ""
    }

    theme.add_button_textures(
        ":resources:gui_themes/Fantasy/Buttons/Normal.png",
        ":resources:gui_themes/Fantasy/Buttons/Hover.png",
        ":resources:gui_themes/Fantasy/Buttons/Clicked.png",
        ":resources:gui_themes/Fantasy/Buttons/Locked.png")

    for button_texture in theme.button_textures.values():
        assert isinstance(button_texture, arcade.Texture)

    theme.add_button_textures(
        ":resources:gui_themes/Fantasy/Buttons/Normal.png")
    assert isinstance(theme.button_textures["normal"], arcade.Texture)
    assert theme.button_textures["normal"] is theme.button_textures["hover"]
    assert theme.button_textures["normal"] is theme.button_textures["clicked"]
    assert theme.button_textures["normal"] is theme.button_textures["locked"]
Exemplo n.º 3
0
class StartView(arcade.View):
    """Class to display the starting View for the game"""
    def __init__(self, game, WIDTH, HEIGHT):
        super().__init__()
        self.game = game
        self.WIDTH = WIDTH
        self.HEIGHT = HEIGHT
        self.start_game = False

    def setup_theme(self):
        self.theme = Theme()
        self.theme_2 = Theme()
        self.theme.set_font(24, arcade.color.BLACK)
        self.set_button_textures()

    def on_show(self):
        self.setup_theme()
        arcade.set_background_color(arcade.color.AMETHYST)
        self.play_button = PlayButton(550,
                                      100,
                                      80,
                                      80,
                                      theme=self.theme,
                                      text='play')
        self.exit_button = ExitButton(650,
                                      100,
                                      80,
                                      80,
                                      theme=self.theme_2,
                                      text='exit')
        self.button_list.append(self.play_button)
        self.button_list.append(self.exit_button)

    def set_button_textures(self):
        #Play button
        normal = "img/buttons/green.png"
        hover = "img/buttons/pink.png"
        clicked = "img/buttons/red.png"
        locked = "img/buttons/blue.png"

        #Exit button
        self.theme.add_button_textures(normal, hover, clicked, locked)
        normal2 = "img/buttons/red.png"
        hover2 = "img/buttons/blue.png"
        clicked2 = "img/buttons/pink.png"
        locked2 = "img/buttons/green.png"
        self.theme_2.add_button_textures(normal2, hover2, clicked2, locked2)

    def on_draw(self):
        arcade.start_render()
        start_x = self.WIDTH / 2
        start_y = self.HEIGHT / 2
        arcade.draw_text(
            "Welcome to Black Jack! \n You start off with 100 chips.\n Try to make it to 250 chips by beating the dealer\'s cards.\n Would you like to play?",
            start_x,
            start_y,
            arcade.color.BLACK,
            font_size=30,
            anchor_x="center",
            anchor_y="center",
            align='center')
        super().on_draw()
        self.play_button.draw()
        self.exit_button.draw()
        if self.play_button.pressed:
            game_view = GameViewBid(self.WIDTH, self.HEIGHT)
            self.game.window.show_view(game_view)
        if self.exit_button.pressed:
            arcade.close_window()
Exemplo n.º 4
0
class BetView(GameView):
    """Class to display the game view for the "Make a Bid" screen"""
    def __init__(self, view, WIDTH, HEIGHT):
        super().__init__(view, WIDTH, HEIGHT)
        self.c_x = WIDTH / 6
        self.c_y = HEIGHT / 2
        self.bet = 1
        self.user_bank = self.game.user.get_bank()
        # place the deck image to the left of the screen
        self.deck_back = arcade.Sprite('img/bees.png',
                                       scale=0.2,
                                       center_x=self.c_x,
                                       center_y=self.c_y)

        # place 2 dealer's closed cards to the top of the screen
        self.dealer_card_back1 = arcade.Sprite('img/bees.png',
                                               scale=0.2,
                                               center_x=self.c_x + WIDTH / 3,
                                               center_y=self.c_y + HEIGHT / 4 +
                                               30)
        self.dealer_card_back2 = arcade.Sprite(
            'img/bees.png',
            scale=0.2,
            center_x=self.c_x + WIDTH / 3 + 70,
            center_y=self.c_y + HEIGHT / 4 + 30)

        # # place 2 player's closed cards to the bottom of the screen
        self.player_card_back1 = arcade.Sprite('img/bees.png',
                                               scale=0.2,
                                               center_x=self.c_x + WIDTH / 3,
                                               center_y=self.c_y - HEIGHT / 4 -
                                               30)
        self.player_card_back2 = arcade.Sprite(
            'img/bees.png',
            scale=0.2,
            center_x=self.c_x + WIDTH / 3 + 70,
            center_y=self.c_y - HEIGHT / 4 - 30)

    def setup_theme(self):
        self.theme = Theme()
        self.theme_2 = Theme()
        self.theme_3 = Theme()
        self.theme_4 = Theme()
        self.theme.set_font(24, arcade.color.BLACK)
        self.set_button_textures()

    def on_show(self):
        self.setup_theme()
        arcade.set_background_color(arcade.color.AMAZON)

        increase1_button = ValueButton(1,
                                       950,
                                       450,
                                       70,
                                       70,
                                       '1',
                                       theme=self.theme)
        decrease1_button = ValueButton(-1,
                                       1050,
                                       450,
                                       70,
                                       70,
                                       '-1',
                                       theme=self.theme)
        self.button_list.append(increase1_button)
        self.button_list.append(decrease1_button)
        increase5_button = ValueButton(5,
                                       950,
                                       375,
                                       70,
                                       70,
                                       '5',
                                       theme=self.theme_2)
        decrease5_button = ValueButton(-5,
                                       1050,
                                       375,
                                       70,
                                       70,
                                       '-5',
                                       theme=self.theme_2)
        self.button_list.append(increase5_button)
        self.button_list.append(decrease5_button)
        increase10_button = ValueButton(10,
                                        950,
                                        300,
                                        70,
                                        70,
                                        '10',
                                        theme=self.theme_3)
        decrease10_button = ValueButton(-10,
                                        1050,
                                        300,
                                        70,
                                        70,
                                        '-10',
                                        theme=self.theme_3)
        self.button_list.append(increase10_button)
        self.button_list.append(decrease10_button)
        increase25_button = ValueButton(25,
                                        950,
                                        225,
                                        70,
                                        70,
                                        '25',
                                        theme=self.theme_4)
        decrease25_button = ValueButton(-25,
                                        1050,
                                        225,
                                        70,
                                        70,
                                        '-25',
                                        theme=self.theme_4)
        self.button_list.append(increase25_button)
        self.button_list.append(decrease25_button)

        quit_button = ExitButton(100, 650, 90, 40, text="Quit")
        self.button_list.append(quit_button)

        submit_button = SubmitButton(1000, 150, 110, 40, text="Place Bet")
        self.button_list.append(submit_button)

    def set_button_textures(self):
        #Bet 1 or -1
        normal = "img/red-chip.png"
        hover = "img/red-chip.png"
        clicked = "img/red-chip.png"
        locked = "img/red-chip.png"
        self.theme.add_button_textures(normal, hover, clicked, locked)

        #Bet 5 or -5
        normal2 = "img/lightblue-chip.png"
        hover2 = "img/lightblue-chip.png"
        clicked2 = "img/lightblue-chip.png"
        locked2 = "img/lightblue-chip.png"
        self.theme_2.add_button_textures(normal2, hover2, clicked2, locked2)

        #Bet 10 or -10
        normal2 = "img/lightgreen-ship.png"
        hover2 = "img/lightgreen-ship.png"
        clicked2 = "img/lightgreen-ship.png"
        locked2 = "img/lightgreen-ship.png"
        self.theme_3.add_button_textures(normal2, hover2, clicked2, locked2)

        #Bet 25 or -25
        normal2 = "img/black-chip.png"
        hover2 = "img/black-chip.png"
        clicked2 = "img/black-chip.png"
        locked2 = "img/black-chip.png"
        self.theme_4.add_button_textures(normal2, hover2, clicked2, locked2)

    def on_draw(self):
        super().on_draw()
        arcade.draw_text(f"Your bank is {self.bank - self.bet}", 100, 100,
                         arcade.color.BLACK, 24)

        self.deck_back.draw()
        self.dealer_card_back1.draw()
        self.dealer_card_back2.draw()
        self.player_card_back1.draw()
        self.player_card_back2.draw()

        arcade.draw_text(f"Place your bid:\n Your bet is {self.bet}",
                         self.WIDTH / 2,
                         self.HEIGHT / 2,
                         arcade.color.BLACK,
                         24,
                         anchor_x="center")

        for button in self.button_list:

            # if player made input
            if isinstance(button, ValueButton) and button.on_release():
                if self.bet + button.get_value() < 1:
                    self.bet = 1
                    continue

                if self.bet == 1 and button.get_value() > 1:
                    self.bet -= 1

                if self.bet + button.get_value() >= self.user_bank:
                    self.bet = self.user_bank
                    continue

                self.bet += button.get_value()

            if isinstance(button, SubmitButton) and button.pressed:
                self.game.place_user_bet(self.bet)
                self.view.set_view(
                    RoundView(self.view, self.WIDTH, self.HEIGHT))

            if isinstance(button, ExitButton) and button.pressed:
                arcade.close_window()