Пример #1
0
def show_human_player(game_master):
    layer = 3
    if not hasattr(show_human_player, 'asset'):
        asset = assets.text.TextAsset(50, 50, 'Player is taking turn...')
        setattr(show_human_player, 'asset', asset)
    asset = getattr(show_human_player, 'asset')
    if isinstance(game_master.current_player(), risk.player.HumonRiskPlayer):
        get_picasso().add_asset('1_text', asset)
    else:
        get_picasso().remove_asset('1_text', asset)
Пример #2
0
def show_human_player(game_master):
    layer = 3
    if not hasattr(show_human_player, 'asset'):
        asset = assets.text.TextAsset(
            50, 50, 'Player is taking turn...')
        setattr(show_human_player, 'asset', asset)
    asset = getattr(show_human_player, 'asset')
    if isinstance(game_master.current_player(), risk.player.HumonRiskPlayer):
        get_picasso().add_asset('1_text', asset)
    else:
        get_picasso().remove_asset('1_text', asset)
Пример #3
0
def attack_success_move_armies(player, game_master, origin, target):
    picasso = get_picasso()
    hint_asset = build_hint_asset(ATTACK_HINTS['success'])
    picasso.add_asset(LAYER, hint_asset)
    dialog = BlockingSliderDialogAsset(DIALOG_X, DIALOG_Y, 'Attack Move', 1,
                                       origin.armies, slider_update, [origin, target])
    dialog.add_text(16, 16, "Attack was successful!")
    dialog.add_text(16, 32, "How many armies to move?")
    disable_all_clickables()
    picasso.add_asset(DIALOG_LAYER, dialog)
    done = False
    while not done:
        number_to_move = dialog.get_result(INPUT_POLL_SLEEP)
        try:
            game_master.player_move_armies(player, origin.name, target.name,
                                           number_to_move)
            done = True
        except GameMasterError as e:
            print(e)
            dialog.reset()
        except ValueError:
            # we really shouldn't get a parsing error from numeric dialog
            raise
    enable_all_clickables()
    picasso.remove_asset(DIALOG_LAYER, dialog)
    picasso.remove_asset(LAYER, hint_asset)
Пример #4
0
def reinforce_phase(player, game_master):
    # state init vector
    datastore = Datastore()
    picasso = get_picasso()
    #reserve_count_asset = ReserveCountAsset(player)
    #picasso.add_asset(LAYER, reserve_count_asset)
    # core state machine
    disable_enemy_territories(player)
    while player.reserves > 0:
        hint_asset = build_hint_asset(REINFORCE_HINTS['initial'] % \
                     player.reserves)
        picasso.add_asset(LAYER, hint_asset)
        event = wait_for_mouse_click()
        for name, clickable in graphics.pressed_clickables(event.pos, 
                'territories'):
            if isinstance(clickable, TerritoryAsset):
                territory = clickable.territory
                # makegonow for now, fix later
                try:
                    reinforce_add_army(player, game_master, territory)
                except GameMasterError:
                    reinforce_add_army_fail(player, game_master, territory)
        picasso.remove_asset(LAYER, hint_asset)
    # exit state
    enable_all_clickables()
Пример #5
0
def attack_success_move_armies(player, game_master, origin, target):
    picasso = get_picasso()
    hint_asset = build_hint_asset(ATTACK_HINTS['success'])
    picasso.add_asset(LAYER, hint_asset)
    dialog = BlockingSliderDialogAsset(DIALOG_X, DIALOG_Y, 'Attack Move', 1, 
            origin.armies, slider_update, [origin, target])
    dialog.add_text(16, 16, "Attack was successful!")
    dialog.add_text(16, 32, "How many armies to move?")
    disable_all_clickables()
    picasso.add_asset(DIALOG_LAYER, dialog)
    done = False
    while not done:
        number_to_move = dialog.get_result(INPUT_POLL_SLEEP)
        try:
            game_master.player_move_armies(player, origin.name, target.name,
                    number_to_move)
            done = True
        except GameMasterError as e:
            print e
            dialog.reset()
        except ValueError:
            # we really shouldn't get a parsing error from numeric dialog
            raise 
    enable_all_clickables()
    picasso.remove_asset(DIALOG_LAYER, dialog)
    picasso.remove_asset(LAYER, hint_asset)
Пример #6
0
def reinforce_phase(player, game_master):
    # state init vector
    datastore = Datastore()
    picasso = get_picasso()
    # reserve_count_asset = ReserveCountAsset(player)
    # picasso.add_asset(LAYER, reserve_count_asset)
    # core state machine
    disable_enemy_territories(player)
    while player.reserves > 0:
        hint_asset = build_hint_asset(REINFORCE_HINTS['initial'] %
                                      player.reserves)
        picasso.add_asset(LAYER, hint_asset)
        event = wait_for_mouse_click()

        for name, clickable in graphics.pressed_clickables(event.pos,
                                                           'territories'):
            try:

                if isinstance(clickable, TerritoryAsset):
                    territory = clickable.territory
                    # makegonow for now, fix later
                    try:
                        reinforce_add_army(player, game_master, territory)
                    except GameMasterError:
                        reinforce_add_army_fail(
                            player, game_master, territory)

            except Exception as e:
                print('Reinforcing failed!!!', e)
                traceback.print_tb(e.__traceback__)
        picasso.remove_asset(LAYER, hint_asset)
# exit state
    enable_all_clickables()
Пример #7
0
    def drag_dialog(self):
        # pygame doesn't properly set relative position on first call for some
        # reason...
        pygame.mouse.get_rel()
        self.title.force_highlight = True
        while pygame.mouse.get_pressed()[0]:
            mouse_delta = pygame.mouse.get_rel()
            new_x = max(self.x + mouse_delta[0], 0)
            new_x = min(new_x, get_picasso().get_width() - self.width)

            new_y = max(self.y + mouse_delta[1], 0)
            new_y = min(new_y, get_picasso().get_height() - self.height)

            self.move_to(new_x, new_y)
            time.sleep(0)
            pump()
        self.title.force_highlight = False
Пример #8
0
    def drag_dialog(self):
        # pygame doesn't properly set relative position on first call for some
        # reason...
        pygame.mouse.get_rel()
        self.title.force_highlight = True
        while pygame.mouse.get_pressed()[0]:
            mouse_delta = pygame.mouse.get_rel()
            new_x = max(self.x + mouse_delta[0], 0)
            new_x = min(new_x, get_picasso().get_width() - self.width)
    
            new_y = max(self.y + mouse_delta[1], 0)
            new_y = min(new_y, get_picasso().get_height() - self.height)

            self.move_to(new_x, new_y)
            time.sleep(0)
            pump()
        self.title.force_highlight = False
Пример #9
0
def handle_user_input(game_master):
    done = False
    player = game_master.current_player()
    picasso = get_picasso()
    reserve_count_asset = ReserveCountAsset(player)
    picasso.add_asset(LAYER, reserve_count_asset)
    scan_pygame_event(player, game_master, reinforce_phase)
        # we must yield control of program for GUI, increase to milliseconds
        # if performance gets sluggish
    picasso.remove_asset(LAYER, reserve_count_asset)
    scan_pygame_event(player, game_master, attack_phase)
Пример #10
0
def fortify_failed(player, origin, target, reason):
    picasso = get_picasso()
    expected = {
        NotConnected: 'The selected territories are not connected!',
        TerritoryNotOwnedByPlayer: "You do not own %s!" % target.name,
    }
    msg = expected[reason.__class__] if reason.__class__ in list(expected.keys()) \
        else "Unkonwn reason for failure..."
    dialog = PopupDialogAsset(DIALOG_X, DIALOG_Y, "Fortify Failed!", msg)
    picasso.add_asset(POPUP_DIALOG_LAYER, dialog)
    dialog.get_confirmation()
    picasso.remove_asset(POPUP_DIALOG_LAYER, dialog)
Пример #11
0
def attacking_mode(player, game_master, origin):
    picasso = get_picasso()
    datastore = Datastore()
    feedback_asset = datastore.get_entry('attack_feedback')
    picasso.add_asset(LAYER, feedback_asset)
    target = scan_pygame_event(player, game_master, choose_target)
    try:
        game_master.player_attack(player, origin.name, target.name)
    except (GameMasterError, RiskBattleError, KeyError):
        pass
    finally:
        picasso.remove_asset(LAYER, feedback_asset)
Пример #12
0
def fortify_failed(player, origin, target, reason):
    picasso = get_picasso()
    expected = {
        NotConnected: 'The selected territories are not connected!',   
        TerritoryNotOwnedByPlayer: "You do not own %s!" % target.name,
    }
    msg = expected[reason.__class__] if reason.__class__ in expected.keys() \
            else "Unkonwn reason for failure..."
    dialog = PopupDialogAsset(DIALOG_X, DIALOG_Y, "Fortify Failed!", msg)
    picasso.add_asset(POPUP_DIALOG_LAYER, dialog)
    dialog.get_confirmation()
    picasso.remove_asset(POPUP_DIALOG_LAYER, dialog)
Пример #13
0
def show_bot_player_hint(game_master):
    datastore = Datastore()
    picasso = get_picasso()
    if not datastore.has_entry('bot_player_hint'):
        hint_asset = assets.text.CentredTextAsset(INFO_PANEL_X, INFO_PANEL_Y,
                                                  INFO_PANEL_WIDTH, INFO_PANEL_HEIGHT,
                                                  "AI TAKING TURNS...",
                                                  bold=True)
        datastore.add_entry('bot_player_hint', hint_asset)
    hint_asset = datastore.get_entry('bot_player_hint')
    if isinstance(game_master.current_player(), risk.ai.bots.BasicRiskBot):
        picasso.add_asset(UI_OVERLAY_LEVEL0, hint_asset)
    else:
        picasso.remove_asset(UI_OVERLAY_LEVEL0, hint_asset)
Пример #14
0
def show_bot_player_hint(game_master):
    datastore = Datastore()
    picasso = get_picasso()
    if not datastore.has_entry('bot_player_hint'):
        hint_asset = assets.text.CentredTextAsset(INFO_PANEL_X, INFO_PANEL_Y, 
                    INFO_PANEL_WIDTH, INFO_PANEL_HEIGHT, 
                    "AI TAKING TURNS...",
                    bold=True)
        datastore.add_entry('bot_player_hint', hint_asset)
    hint_asset = datastore.get_entry('bot_player_hint')
    if isinstance(game_master.current_player(), risk.ai.bots.BasicRiskBot):
        picasso.add_asset(UI_OVERLAY_LEVEL0, hint_asset)
    else:
        picasso.remove_asset(UI_OVERLAY_LEVEL0, hint_asset)
Пример #15
0
def fortify_choose_armies_to_move(player, game_master, origin, target):
    picasso = get_picasso()
    dialog = BlockingSliderDialogAsset(DIALOG_X, DIALOG_Y, 'Fortify', 0,
                                       origin.armies, slider_update, [origin, target])
    dialog.add_text(16, 16, "Fortifying...")
    dialog.add_text(16, 35, "Select amount of armies to move")
    disable_all_clickables()
    picasso.add_asset(DIALOG_LAYER, dialog)
    try:
        number_to_move = dialog.get_result(INPUT_POLL_SLEEP)
        if number_to_move > 0:
            game_master.player_move_armies(player, origin.name,
                                           target.name, number_to_move)
    except GameMasterError as e:
        fortify_failed(player, origin, target, e)
    enable_all_clickables()
    picasso.remove_asset(DIALOG_LAYER, dialog)
Пример #16
0
def fortify_choose_armies_to_move(player, game_master, origin, target):
    picasso = get_picasso()
    dialog = BlockingSliderDialogAsset(DIALOG_X, DIALOG_Y, 'Fortify', 0, 
            origin.armies, slider_update, [origin, target])
    dialog.add_text(16, 16, "Fortifying...")
    dialog.add_text(16, 35, "Select amount of armies to move")
    disable_all_clickables()
    picasso.add_asset(DIALOG_LAYER, dialog)
    try:
        number_to_move = dialog.get_result(INPUT_POLL_SLEEP)
        if number_to_move > 0:
            game_master.player_move_armies(player, origin.name, 
                    target.name, number_to_move)
    except GameMasterError as e:
        fortify_failed(player, origin, target, e)
    enable_all_clickables()
    picasso.remove_asset(DIALOG_LAYER, dialog)
Пример #17
0
def attack_choose_target(player, game_master, origin_asset):
    origin = origin_asset.territory
    picasso = get_picasso()
    hint_asset = build_hint_asset(ATTACK_HINTS['attacking'])
    picasso.add_asset(LAYER, hint_asset)
    disable_all_clickables()
    origin_asset.force_highlight = True
    enable_adjacent_territories(origin)
    target_asset = wait_for_territory_click(allow_fail=True)
    target = None
    picasso.remove_asset(LAYER, hint_asset)
    if target_asset:
        target = target_asset.territory
    if not target:
        pass
    else:
        attack_perform_attack(player, game_master, origin, target)
    origin_asset.force_highlight = False
    enable_all_clickables()
Пример #18
0
def attack_choose_target(player, game_master, origin_asset):
    origin = origin_asset.territory
    picasso = get_picasso()
    hint_asset = build_hint_asset(ATTACK_HINTS['attacking'])
    picasso.add_asset(LAYER, hint_asset)
    disable_all_clickables()
    origin_asset.force_highlight = True
    enable_adjacent_territories(origin)
    target_asset = wait_for_territory_click(allow_fail=True)
    target = None
    picasso.remove_asset(LAYER, hint_asset)
    if target_asset:
        target = target_asset.territory
    if not target:
        pass
    else:
        attack_perform_attack(player, game_master, origin, target)
    origin_asset.force_highlight = False
    enable_all_clickables()
Пример #19
0
def fortify_phase(player, game_master):
    picasso = get_picasso()
    hint_asset = build_hint_asset(FORTIFY_HINTS['initial'])
    done = False
    # TODO merge with attack phase block
    while not done:
        disable_enemy_territories(player)
        picasso.add_asset(LAYER, hint_asset)
        event = wait_for_mouse_click()
        for name, clickable in get_clicked_territories(event.pos):
            if isinstance(clickable, TerritoryAsset):
                if clickable.territory.owner == player:
                    picasso.remove_asset(LAYER, hint_asset)
                    fortify_choose_target(player, game_master, clickable)
        for name, clickable in get_clicked_buttons(event.pos):
            if name == 'next':
                done = True
    picasso.remove_asset(LAYER, hint_asset)
    enable_all_clickables()
Пример #20
0
def attack_phase(player, game_master):
    picasso = get_picasso()
    done = False
    hint_asset = build_hint_asset(ATTACK_HINTS['initial'])
    while not done:
        picasso.add_asset(LAYER, hint_asset)
        disable_enemy_territories(player)
        event = wait_for_mouse_click()
        for name, clickable in get_clicked_territories(event.pos):
            if isinstance(clickable, TerritoryAsset):
                if clickable.territory.owner == player:
                    picasso.remove_asset(LAYER, hint_asset)
                    attack_choose_target(player, game_master, clickable)
        for name, clickable in get_clicked_buttons(event.pos):
            if name == 'next':
                done = True

    picasso.remove_asset(LAYER, hint_asset)
    enable_all_clickables()
Пример #21
0
def fortify_phase(player, game_master):
    picasso = get_picasso()
    hint_asset = build_hint_asset(FORTIFY_HINTS['initial'])
    done = False
    # TODO merge with attack phase block
    while not done:
        disable_enemy_territories(player)
        picasso.add_asset(LAYER, hint_asset)
        event = wait_for_mouse_click()
        for name, clickable in get_clicked_territories(event.pos):
            if isinstance(clickable, TerritoryAsset):
                if clickable.territory.owner == player:
                    picasso.remove_asset(LAYER, hint_asset)
                    fortify_choose_target(player, game_master, clickable)
        for name, clickable in get_clicked_buttons(event.pos):
            if name == 'next':
                done = True
    picasso.remove_asset(LAYER, hint_asset)
    enable_all_clickables()
Пример #22
0
def attack_phase(player, game_master):
    picasso = get_picasso()
    done = False
    hint_asset = build_hint_asset(ATTACK_HINTS['initial'])
    while not done:
        picasso.add_asset(LAYER, hint_asset)
        disable_enemy_territories(player)
        event = wait_for_mouse_click()
        for name, clickable in get_clicked_territories(event.pos):
            if isinstance(clickable, TerritoryAsset):
                if clickable.territory.owner == player:
                    picasso.remove_asset(LAYER, hint_asset)
                    attack_choose_target(player, game_master, 
                            clickable)
        for name, clickable in get_clicked_buttons(event.pos):
            if name == 'next':
                done = True

    picasso.remove_asset(LAYER, hint_asset)
    enable_all_clickables()
Пример #23
0
def initialize_other_graphic_assets(picasso, game_master):
    picasso = get_picasso()
    datastore = Datastore()
    #current_player_asset = assets.text.CurrentPlayerAsset(
    #        100, 100, game_master)
    #picasso.add_asset('4_current_player', current_player_asset)
    #datastore.add_entry('current_player', current_player_asset)
    feedback_asset = assets.text.TextAsset(100, 650,
                                           'choose territory to attack')
    datastore.add_entry('attack_feedback', feedback_asset)
    game_info_asset = assets.gameplay.PlayersAsset(30, 550, game_master)
    picasso.add_asset(UI_OVERLAY_LEVEL0, game_info_asset)
    datastore.add_entry('game_info', game_info_asset)
    add_state_indicators(picasso, game_master)
    player_background_asset = assets.base.ColourBlockAsset(
        1000, 548, 123, 80, assets.base.BLACK)
    human_player_asset = assets.base.ColourBlockAsset(1002, 550, 119, 76,
                                                      assets.base.GREY)
    datastore.add_entry('player_colour', human_player_asset)
    picasso.add_asset(UI_OVERLAY_LEVEL0, player_background_asset)
    picasso.add_asset(UI_OVERLAY_LEVEL1, human_player_asset)
Пример #24
0
def initialize_other_graphic_assets(picasso, game_master):
    picasso = get_picasso()
    datastore = Datastore()
    #current_player_asset = assets.text.CurrentPlayerAsset(
    #        100, 100, game_master)
    #picasso.add_asset('4_current_player', current_player_asset)
    #datastore.add_entry('current_player', current_player_asset)
    feedback_asset = assets.text.TextAsset(100, 650, 
            'choose territory to attack')
    datastore.add_entry('attack_feedback', feedback_asset)
    game_info_asset = assets.gameplay.PlayersAsset(30, 550, game_master)
    picasso.add_asset(UI_OVERLAY_LEVEL0, game_info_asset)
    datastore.add_entry('game_info', game_info_asset)
    add_state_indicators(picasso, game_master)
    player_background_asset = assets.base.ColourBlockAsset(
        1000, 548, 123, 80, assets.base.BLACK)
    human_player_asset = assets.base.ColourBlockAsset(
        1002, 550, 119, 76, assets.base.GREY)
    datastore.add_entry('player_colour', human_player_asset)
    picasso.add_asset(UI_OVERLAY_LEVEL0, player_background_asset)
    picasso.add_asset(UI_OVERLAY_LEVEL1, human_player_asset)
Пример #25
0
def fortify_choose_target(player, game_master, origin_asset):
    picasso = get_picasso()
    hint_asset = build_hint_asset(FORTIFY_HINTS['fortifying'])
    picasso.add_asset(LAYER, hint_asset)
    origin_asset.disabled = True
    origin_asset.force_highlight = True
    origin = origin_asset.territory
    target_asset = wait_for_territory_click(allow_fail=True)
    target = None
    if target_asset:
        target = target_asset.territory
    if not target:
        # cancel
        pass
    elif target.owner == player and origin.is_connected(target):
        fortify_choose_armies_to_move(player, game_master, origin, target)
    else:
        fortify_failed(player, origin, target, 
                        TerritoryNotOwnedByPlyer(player))
    origin_asset.force_highlight = False
    origin_asset.disabled = False
    picasso.remove_asset(LAYER, hint_asset)
Пример #26
0
def fortify_choose_target(player, game_master, origin_asset):
    picasso = get_picasso()
    hint_asset = build_hint_asset(FORTIFY_HINTS['fortifying'])
    picasso.add_asset(LAYER, hint_asset)
    origin_asset.disabled = True
    origin_asset.force_highlight = True
    origin = origin_asset.territory
    target_asset = wait_for_territory_click(allow_fail=True)
    target = None
    if target_asset:
        target = target_asset.territory
    if not target:
        # cancel
        pass
    elif target.owner == player and origin.is_connected(target):
        fortify_choose_armies_to_move(player, game_master, origin, target)
    else:
        fortify_failed(player, origin, target,
                       TerritoryNotOwnedByPlyer(player))
    origin_asset.force_highlight = False
    origin_asset.disabled = False
    picasso.remove_asset(LAYER, hint_asset)
Пример #27
0
def check_picasso_liveness(game_master):
    if not get_picasso().is_alive():
        game_master.end_game()
Пример #28
0
def reinforce_add_army_fail(player, game_master, territory):
    risk.logger.debug("%s does not own %s" % (player.name, territory.name))
    dialog = PopupDialogAsset(DIALOG_X, DIALOG_Y, "Reinforce Failed!", "penis")
    get_picasso().add_asset(POPUP_DIALOG_LAYER, dialog)
    dialog.get_confirmation()
    get_picasso().remove_asset(POPUP_DIALOG_LAYER, dialog)
Пример #29
0
def attack_failed(player, game_master, origin, target):
    picasso = get_picasso()
    hint_asset = build_hint_asset(ATTACK_HINTS['failed'])
    picasso.add_asset(LAYER, hint_asset)
    picasso.remove_asset(LAYER, hint_asset)
Пример #30
0
def check_picasso_liveness(game_master):
    if not get_picasso().is_alive():
        game_master.end_game()
Пример #31
0
def reinforce_add_army_fail(player, game_master, territory):
    risk.logger.debug("%s does not own %s" % (player.name, territory.name))
    dialog = PopupDialogAsset(DIALOG_X, DIALOG_Y, "Reinforce Failed!", "penis")
    get_picasso().add_asset(POPUP_DIALOG_LAYER, dialog)
    dialog.get_confirmation()
    get_picasso().remove_asset(POPUP_DIALOG_LAYER, dialog)
Пример #32
0
def attack_failed(player, game_master, origin, target):
    picasso = get_picasso()
    hint_asset = build_hint_asset(ATTACK_HINTS['failed'])
    picasso.add_asset(LAYER, hint_asset)
    picasso.remove_asset(LAYER, hint_asset)