def init(): screen = pygame.display.set_mode((1600, 900), pygame.DOUBLEBUF) board = GameBoard.GameBoard(screen, (8, 8)) game_objects.menu = Menu.Menu(["Player vs Player", "Player vs Computer", "Quit"], screen) game_objects.board = board game_objects.overlay = Overlay.Overlay(screen, game_objects.board, False) game_objects.state = BoardState.BoardState(board, game_objects.overlay) for i in range(3): for j in range(8): if (i % 2) == 0: if not (j % 2) == 1: add_checker(Teams.black(), (j, i + 5)) continue if not (i % 2) == 0: if (j % 2) == 1: add_checker(Teams.black(), (j, i + 5)) continue add_checker(Teams.red(), (j, i)) game_objects.game = Game.Game(game_objects.state, game_objects.board) game_objects.game.new_game(GameMode.player_v_player()) run()
def __init__(self, state, board): self.mode = None self._state = state self._board_ui = board self.current_clicks = [] self.current_team = Teams.black()
def _draw_current_team(self): size = None text = None if self.current_team == Teams.black(): size = self._size_black_turn text = self._turn_black_text else: size = self._size_red_turn text = self._turn_red_text padding = self._board.get_padding()[1] x = (self._screen.get_size()[0] - size[0]) / 2 y = self._board.get_dimentions()[1] + padding + (size[1] - padding) / 2 self._screen.blit(text, (x, y))
def __init__(self, screen, board, timer_in_use): self._screen = screen # Stats are in the form men, king, score self._black_stats = [0, 0, 0] self._red_stats = [0, 0, 0] @property def current_team(self): return self.current_team self.current_team = Teams.black() self._timer_in_use = timer_in_use self._timer_black = None self._timer_red = None self._board = board self._init_font()
def set_stats(self, team, stats): if Teams.black() == team: self._black_stats = stats else: self._red_stats = stats
def render(self): self._draw_current_team() self._draw_team_sidebar(Teams.red()) self._draw_team_sidebar(Teams.black())
def update_stats(self): self.overlay.set_stats(Teams.red(), [self.red_checkers, self.red_kings, self.max_checkers_per_side - self.black_checkers]) self.overlay.set_stats(Teams.black(), [self.black_checkers, self.black_kings, self.max_checkers_per_side - self.red_checkers])
def team(self, team): if team != Teams.red() and team != Teams.black(): raise ValueError('Team must be provided') self.team = team
def _is_human_player(self): if self.current_team == Teams.black(): return True # Previous condition => the team is red -> only human if in PvP return self.mode == GameMode.player_v_player()
def new_game(self, mode): self.mode = mode self.current_team = Teams.black()