def __move_sprite(x, y):
     board = GameState.get_board()
     turntracker = GameState.get_turntracker()
     selected_x = board.get_selected_x()
     selected_y = board.get_selected_y()
     player = board.get_sprite(selected_x, selected_y)
     
     if isinstance(player, CreatureSprite):
         player.move(selected_x, selected_y,
                     x, y, board, SpriteSwapper(turntracker))
     SpriteSelector.__reset_selection()
    def __handle_player_is_selected(x, y):
        board = GameState.get_board()
        turntracker = GameState.get_turntracker()
        selected_x = board.get_selected_x()
        selected_y = board.get_selected_y()
        player = board.get_sprite(selected_x, selected_y)

        if player in turntracker.get_players_to_move():
            SpriteSelector.__move_sprite(x, y)
        elif player in turntracker.get_players_to_attack():
            SpriteSelector.__attack_sprite(x, y)
 def __attack_sprite(x, y):
     board = GameState.get_board()
     turntracker = GameState.get_turntracker()
     selected_x = board.get_selected_x()
     selected_y = board.get_selected_y()
     first_sprite = board.get_sprite(selected_x, selected_y)
     second_sprite = board.get_sprite(x, y)
     
     if isinstance(first_sprite, CreatureSprite) and isinstance(second_sprite, CreatureSprite):
         first_sprite.attack(second_sprite, board, turntracker)
         
     SpriteSelector.__reset_selection()
 def select_player_sprite(x, y):
     turntracker = GameState.get_turntracker()
     sprite = GameState.get_board().get_sprite(x, y)
     
     # if it is not the players turn don't do anything
     if not turntracker.is_player_turn():
         return
     
     if isinstance(sprite, PlayerSprite):
         SpriteSelector.__update_player_selection(x, y)
     elif SpriteSelector.__player_is_selected(sprite):
         SpriteSelector.__handle_player_is_selected(x, y)
     else:
         SpriteSelector.__reset_selection()
 def select_monster_sprite(x, y):
     board = GameState.get_board()
     turntracker = GameState.get_turntracker()
     selected_x = board.get_selected_x()
     selected_y = board.get_selected_y()
     
     # if it is not the momsters turn don't do anything
     if turntracker.is_player_turn():
         return
     
     if selected_x >= 0 and selected_y >= 0:
         SpriteSelector.__move_sprite(x, y)
     else:
         # capture this selection
         board.set_selected_x(x)
         board.set_selected_y(y)
 def __update_player_selection(x, y):
     board = GameState.get_board()
     turntracker = GameState.get_turntracker()
     selected_x = board.get_selected_x()
     selected_y = board.get_selected_y()
     player = board.get_sprite(x, y)
     target = board.get_sprite(selected_x, selected_y)
     
     if target == player:
         SpriteSelector.__reset_selection()
         if player in turntracker.get_players_to_move():
             turntracker.track_player_move(player, x, y)
         elif player in turntracker.get_players_to_attack():
             turntracker.track_player_attack(player)
     elif (player in turntracker.get_players_to_move() or
        player in turntracker.get_players_to_attack()):
         # already selected
         if selected_x == x and selected_y == y:
             SpriteSelector.__reset_selection()
         else:
             # capture this selection
             board.set_selected_x(x)
             board.set_selected_y(y)
 def print_board(canvas):
     ''' print out the board to the given canvas '''
     
     # get the game board
     game_board = GameState.get_board()
     
     # print out everything
     for i in range(game_board.get_width()):
         for j in range(game_board.get_height()):
             colour =  game_board.get_sprite(i,j).get_default_colour()
             
             # print this sprite
             canvas.create_rectangle(i      * Constants.DEFAULT_SPRITE_WIDTH(),
                                     j      * Constants.DEFAULT_SPRITE_HEIGHT(),
                                    (i + 1) * Constants.DEFAULT_SPRITE_WIDTH(),
                                    (j + 1) * Constants.DEFAULT_SPRITE_HEIGHT(),
                                     fill=colour)
 def __reset_selection():
     GameState.get_board().reset_selected_item()
 def __player_is_selected(sprite):
     board = GameState.get_board()
     x = board.get_selected_x()
     y = board.get_selected_y()
     
     return isinstance(board.get_sprite(x, y), PlayerSprite) or x < 0 or y < 0
    def print_turn_menu(canvas):
        turntracker = GameState.get_turntracker()
        players_to_move = turntracker.get_players_to_move()
        monsters_to_move = turntracker.get_monsters_to_move()
        players_to_attack = turntracker.get_players_to_attack()
        monsters_to_attack = turntracker.get_monsters_to_attack()

        separator_x = Constants.DEFAULT_SPRITE_WIDTH() + Constants.DEFAULT_FRAME_WIDTH() + 5
        # separator line between players and monsters
        canvas.create_line(separator_x, 0, separator_x, Constants.DEFAULT_FRAME_HEIGHT())

        # labels
        canvas.create_text(Constants.DEFAULT_FRAME_WIDTH() + 25, 15, text="Players")
        canvas.create_text(separator_x + 30, 15, text="Monsters")

        players = []
        monsters = []
        for player in players_to_move:
            if player not in players:
                players.append(player)

        for player in players_to_attack:
            if player not in players:
                players.append(player)

        for monster in monsters_to_move:
            if monster not in monsters:
                monsters.append(monster)

        for monster in monsters_to_attack:
            if monster not in monsters:
                monsters.append(monster)

        turn_menu_distance = Constants.DEFAULT_TURN_MENU_DISTANCE()
        position_down = 0
        x_starting = Constants.DEFAULT_FRAME_WIDTH()
        for player in players:
            TurnMenuPrinter.__print_small_box(
                canvas, x_starting, position_down * turn_menu_distance + 20, player.get_default_colour()
            )

            player_info = turntracker.get_player_info(player)

            canvas.create_text(x_starting + 25, position_down * turn_menu_distance + 65, text=player.get_type())

            canvas.create_text(
                x_starting + 25,
                position_down * turn_menu_distance + 85,
                text="(" + str(player_info[0]) + "," + str(player_info[1]) + ")",
            )

            canvas.create_text(x_starting + 25, position_down * turn_menu_distance + 105, text=player.get_hp_string())
            position_down = position_down + 1

        position_down = 0
        x_starting = Constants.DEFAULT_FRAME_WIDTH() + 50
        for monster in monsters:
            TurnMenuPrinter.__print_small_box(
                canvas, x_starting, position_down * turn_menu_distance + 20, monster.get_default_colour()
            )

            monster_info = turntracker.get_monster_info(monster)

            canvas.create_text(x_starting + 35, position_down * turn_menu_distance + 65, text=monster.get_type())

            canvas.create_text(
                x_starting + 25,
                position_down * turn_menu_distance + 85,
                text="(" + str(monster_info[0]) + "," + str(monster_info[1]) + ")",
            )

            canvas.create_text(x_starting + 25, position_down * turn_menu_distance + 105, text=monster.get_hp_string())
            position_down = position_down + 1
 def do_action(self):
     if not GameState.get_turntracker().is_player_turn():
         if len(GameState.get_turntracker().get_monsters_to_move()) == 0:
             GameState.get_turntracker().refresh_players_and_monsters()
         elif self.__selection == None:
             monster = GameState.get_turntracker().get_monsters_to_move()[0]
             movement_range = monster.get_movement_range()
             monster_info = GameState.get_turntracker().get_monster_info(monster)
             x = monster_info[0]
             y = monster_info[1]
             possible_movements = MovementHelper.get_possible_movement_spaces(movement_range, x, y)
             
             new_x = -1
             new_y = -1
             while not OnScreenHelper.is_on_screen(new_x, new_y):
                 random = randint(0, len(possible_movements) - 1)
                 self.__selection = possible_movements[random]
                 new_x = self.__selection[0]
                 new_y = self.__selection[1]
             self.__monster_info = monster_info
             SpriteSelector.select_monster_sprite(x, y)
         else:
             x = self.__selection[0]
             y = self.__selection[1]
             
             GameState.get_board().reset_selected_item()
             SpriteSelector.select_monster_sprite(self.__monster_info[0], self.__monster_info[1])
             SpriteSelector.select_monster_sprite(x, y)
             
             self.__selection = None
             self.__monster_info = None
             if len(GameState.get_turntracker().get_monsters_to_move()) == 0:
                 GameState.get_turntracker().refresh_players_and_monsters()