Exemplo n.º 1
0
 def ActivateState(self):
     self.status_text = sprites.Text(
         '{} chooses another location for the bandits!'.format(
             self.player.name), 'Comic Sans MS', 30)
     if self.rolled_seven:
         self.status_text = sprites.Text(
             '{} rolled a 7 and chooses another location for the bandits!'.
             format(self.player.name), 'Comic Sans MS', 30)
     self.status_text.color = self.player.color
     (self.status_text.x, self.status_text.y) = (230, 3)
     self.gameview.all_texts.append(self.status_text)
Exemplo n.º 2
0
 def ActivateState(self):
     self.status_text = sprites.Text(
         '{} chooses a player to steal a card from.'.format(
             self.player.name), 'Comic Sans MS', 30)
     self.status_text.color = self.player.color
     (self.status_text.x, self.status_text.y) = (230, 3)
     self.gameview.all_texts.append(self.status_text)
Exemplo n.º 3
0
    def ActivateState(self):
        self.pointer = sprites.SPointer()
        self.gameview.AddSprite(self.pointer, self.z_front)

        self.status_text = sprites.Text(
            '{} please place a town'.format(self.player.name), 'Comic Sans MS',
            30)
        self.status_text.color = self.player.color
        (self.status_text.x, self.status_text.y) = (230, 3)
        self.gameview.all_texts.append(self.status_text)
Exemplo n.º 4
0
 def on_click():
     if btn.alive():
         nonlocal clicked, txt
         if len(self._chosen_tiles) != 1:
             # txt = u'请出一张牌'
             txt.kill()
             txt = sprites.Text(u'请出一张牌', [self._graphics._width / 2 - 60, self._graphics._height / 2 - 15])
             self._graphics.add_sprite(txt)
             return
         btn.kill()
         clicked = True
         txt.kill()
Exemplo n.º 5
0
    def ActivateState(self):
        self.pointer = sprites.SPointer()
        self.gameview.AddSprite(self.pointer, self.z_front)

        self.optional_town = self.preceding_town_state.placed_town if self.preceding_town_state else None

        self.status_text = sprites.Text(
            '{} please place a road'.format(self.player.name), 'Comic Sans MS',
            30)
        self.status_text.color = self.player.color
        (self.status_text.x, self.status_text.y) = (230, 3)
        self.gameview.all_texts.append(self.status_text)
Exemplo n.º 6
0
    def step(self, draw=True):
        if len(self._all_tiles) == 0:
            self._graphic_mgr.show_text(u'游戏结束')
            pygame.display.update()
            self._clock.tick(0.5)
            self.reset()
            return

        if self._players[self._current_turn].respond_chow(self._last_tile):
            return self.step(False)

        if draw:
            self._players[self._current_turn].add(self._all_tiles.pop(0))
            self._players[self._current_turn].refresh()
            if self._players[self._current_turn].respond_complete():
                self.reset()
                self._graphic_mgr.show_text(u'游戏结束')
                pygame.display.update()
                self._clock.tick(0.5)
                return

        self._last_tile = self._players[self._current_turn].respond_normal()

        # self._last_tile = self._players[self._current_turn].remove(self._players[self._current_turn]._tiles[0])

        self._graphic_mgr.add_player_sprite_by_type(
            self._players[self._current_turn],
            self._last_tile, (self._graphic_mgr._width // 2,
                              self._graphic_mgr._height // 8 * 6),
            draw=True)
        if self._cache_text and self._cache_text.alive():
            self._cache_text.kill()
        self._cache_text = sprites.Text(
            u'%s 出了牌' % self._players[self._current_turn]._name, [
                self._graphic_mgr._width / 2 - 60,
                self._graphic_mgr._height / 2 - 75
            ])
        self._graphic_mgr.add_sprite(self._cache_text)
        for i in range(self._current_turn + 1, self._current_turn + 4):
            if self._players[i % 4].respond_complete(self._last_tile):
                self.reset()
                self._graphic_mgr.show_text(u'游戏结束')
                pygame.display.update()
                self._clock.tick(0.5)
                return
        for i in range(self._current_turn + 1, self._current_turn + 4):
            if self._players[i % 4].respond_pung(self._last_tile):
                self._current_turn = i % 4
                self._last_tile = TILE_TYPE.NONE
                return self.step(False)

        self._current_turn = (self._current_turn + 1) % 4
Exemplo n.º 7
0
    def ActivateState(self):
        if self.status_text:
            self.status_text.removed = False
        else:
            self.status_text = sprites.Text(
                '{}'
                's turn! Spacebar = roll dice, b = use a knight card and move bandits.'
                .format(self.player.name), 'Comic Sans MS', 20)
            self.status_text.color = self.player.color
            self.gameview.all_texts.append(self.status_text)

        (self.status_text.x, self.status_text.y) = (30, 30)
        self.meta_state.current_hand_text.color = self.player.color
        self.PrintPlayerHand()
Exemplo n.º 8
0
    def respond_pung(self, tile):
        can_pung = self.can_pung(tile)

        if can_pung:
            print(tile)
            print(self._tiles)
            print(self._cnt)
            clicked = False
            btn = sprites.Button((255, 0, 0), 100, 30)
            btn.rect.x = 300
            btn.rect.y = 600

            txt = sprites.Text(u'要碰吗', [self._graphics._width / 2 - 60, self._graphics._height / 2 - 15])

            def on_click():
                if btn.alive():

                    nonlocal clicked, txt
                    if len(self._chosen_tiles) == 0:
                        btn.kill()
                        txt.kill()
                        clicked = True
                        return
                    if len(self._chosen_tiles) == 2 and int(self._chosen_tiles[0]) == int(self._chosen_tiles[1]) == int(tile):
                        btn.kill()
                        txt.kill()
                        clicked = True
                        return

                    txt.kill()
                    txt = sprites.Text(u'出牌不符合规定', [self._graphics._width / 2 - 60, self._graphics._height / 2 - 15])
                    self._graphics.add_sprite(txt)

            self._graphics.add_sprite(btn)
            self._graphics.add_sprite(txt)

            btn.on_click = on_click
            while not clicked:
                self._graphics.clear()
                self._graphics.draw_all()
                pygame.display.update()
                self._graphics.handle(pygame.event.get())
                self._graphics.clock.tick(30)
            if len(self._chosen_tiles) > 0:
                self.remove(self._chosen_tiles)
                self._chosen_tiles.clear()
                self.refresh()
                return True
        return False
Exemplo n.º 9
0
    def respond_complete(self, tile=TILE_TYPE.NONE):
        can_complete = self.can_complete(tile)
        if can_complete:
            clicked = False
            btn_yes = sprites.Button((0, 255, 0), 100, 30)
            btn_yes.rect.x = 300
            btn_yes.rect.y = 600

            btn_no = sprites.Button((255, 0, 0), 100, 30)
            btn_no.rect.x = 500
            btn_no.rect.y = 600

            txt = sprites.Text(u'要胡吗', [self._graphics._width / 2 - 60, self._graphics._height / 2 - 15])
            response = False

            def on_click_yes():
                if btn_yes.alive():
                    nonlocal response, clicked
                    btn_yes.kill()
                    clicked = True
                    txt.kill()
                    response = True

            def on_click_no():
                if btn_no.alive():
                    nonlocal response, clicked
                    btn_no.kill()
                    txt.kill()
                    clicked = True
                    response = False

            self._graphics.add_sprite(btn_yes)
            self._graphics.add_sprite(btn_no)
            self._graphics.add_sprite(txt)

            btn_yes.on_click = on_click_yes
            btn_no.on_click = on_click_no
            while not clicked:
                self._graphics.clear()
                self._graphics.draw_all()
                pygame.display.update()
                self._graphics.handle(pygame.event.get())
                self._graphics.clock.tick(30)

            self._graphics.clear()
            self._graphics.draw_all()
            return response
        else:
            return False
Exemplo n.º 10
0
    def respond_chow(self, tile):
        can_chow, sols = self.can_chow(tile)
        if can_chow:
            clicked = False
            btn = sprites.Button((255, 0, 0), 100, 30)
            btn.rect.x = 300
            btn.rect.y = 600

            # txt = u'要吃吗'
            txt = sprites.Text(u'要吃吗', [self._graphics._width / 2 - 60, self._graphics._height / 2 - 15])

            def on_click():
                if btn.alive():

                    nonlocal clicked, txt, sols
                    if len(self._chosen_tiles) == 0:
                        btn.kill()
                        txt.kill()
                        clicked = True
                        return
                    for sol in sols:
                        if sorted(self._chosen_tiles, key=lambda x: int(x)) == sorted(sol, key=lambda x: int(x)):
                            btn.kill()
                            txt.kill()
                            clicked = True
                            return
                    txt.kill()
                    txt = sprites.Text(u'出牌不符合规定', [self._graphics._width / 2 - 60, self._graphics._height / 2 - 15])
                    self._graphics.add_sprite(txt)
                    # txt = u'出牌不符合规定'

            self._graphics.add_sprite(btn)
            self._graphics.add_sprite(txt)

            btn.on_click = on_click
            while not clicked:
                self._graphics.clear()
                self._graphics.draw_all()
                # self._graphics.show_text(txt)
                pygame.display.update()
                self._graphics.handle(pygame.event.get())
                self._graphics.clock.tick(30)
            if len(self._chosen_tiles) > 0:
                self.remove(self._chosen_tiles)
                self._chosen_tiles.clear()
                self.refresh()
                return True
        return False
Exemplo n.º 11
0
            def on_click():
                if btn.alive():

                    nonlocal clicked, txt
                    if len(self._chosen_tiles) == 0:
                        btn.kill()
                        txt.kill()
                        clicked = True
                        return
                    if len(self._chosen_tiles) == 2 and int(self._chosen_tiles[0]) == int(self._chosen_tiles[1]) == int(tile):
                        btn.kill()
                        txt.kill()
                        clicked = True
                        return

                    txt.kill()
                    txt = sprites.Text(u'出牌不符合规定', [self._graphics._width / 2 - 60, self._graphics._height / 2 - 15])
                    self._graphics.add_sprite(txt)
Exemplo n.º 12
0
            def on_click():
                if btn.alive():

                    nonlocal clicked, txt, sols
                    if len(self._chosen_tiles) == 0:
                        btn.kill()
                        txt.kill()
                        clicked = True
                        return
                    for sol in sols:
                        if sorted(self._chosen_tiles, key=lambda x: int(x)) == sorted(sol, key=lambda x: int(x)):
                            btn.kill()
                            txt.kill()
                            clicked = True
                            return
                    txt.kill()
                    txt = sprites.Text(u'出牌不符合规定', [self._graphics._width / 2 - 60, self._graphics._height / 2 - 15])
                    self._graphics.add_sprite(txt)
Exemplo n.º 13
0
    def __init__(self, gameview, players, board_stiles):
        super().__init__(gameview)
        self.players = players
        self.board_stiles = board_stiles
        self.rolled_dice = None
        self.triggered_action_state = None

        self.current_player = 0
        self.current_hand_text = sprites.Text('current hand', 'Comic Sans MS',
                                              20)
        (self.current_hand_text.x, self.current_hand_text.y) = (36, 600)
        self.gameview.all_texts.append(self.current_hand_text)
        cancel_action_key = sprites.KeyCancelActionEvent()
        self.gameview.keys.append(cancel_action_key)

        self.main_phases = list(
            map(
                lambda player: gamestates.PlayerMainPhaseState(
                    board_stiles, gameview, self, player, self.gameview.
                    main_phase_key_events, cancel_action_key), self.players))
Exemplo n.º 14
0
    def respond_normal(self):
        clicked = False
        btn = sprites.Button((255, 0, 0), 100, 30)
        btn.rect.x = 300
        btn.rect.y = 600

        txt = sprites.Text(u'请出牌', [self._graphics._width / 2 - 60, self._graphics._height / 2 - 15])

        def on_click():
            if btn.alive():
                nonlocal clicked, txt
                if len(self._chosen_tiles) != 1:
                    # txt = u'请出一张牌'
                    txt.kill()
                    txt = sprites.Text(u'请出一张牌', [self._graphics._width / 2 - 60, self._graphics._height / 2 - 15])
                    self._graphics.add_sprite(txt)
                    return
                btn.kill()
                clicked = True
                txt.kill()

        self._graphics.add_sprite(btn)
        self._graphics.add_sprite(txt)

        btn.on_click = on_click
        while not clicked:
            self._graphics.clear()
            self._graphics.draw_all()
            # self._graphics.show_text(txt)
            pygame.display.update()
            self._graphics.handle(pygame.event.get())
            self._graphics.clock.tick(30)
        tile = self._chosen_tiles[0]
        self.remove(tile)
        self._chosen_tiles.clear()
        self.refresh()
        return tile