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()
def pressed_clickables(mouse_pos, storage='buttons'): datastore = Datastore() storage = datastore.get_storage(storage) clicked = [] for name, button in storage.iteritems(): if button.mouse_hovering(mouse_pos): if button.confirmed_click(): clicked.append((name, button)) return clicked
def add_buttons(picasso): datastore = Datastore() #next_button = assets.clickable.ClickableAsset( # 1000, 635, 120, 65, 'NEXT') next_button = assets.clickable.ImageButtonAsset( 1000, 635, 'assets/art/gui/button_next_up.png', 'assets/art/gui/button_next_down.png') datastore.add_entry('next', next_button, 'buttons') for button in datastore.get_storage('buttons').values(): picasso.add_asset('1_buttons', button)
def slider_update(dialog, origin, target): datastore = Datastore() if not hasattr(dialog, 'show_origin_armies'): dialog.show_origin_armies = dialog.add_text(40, 70, 'origin') if not hasattr(dialog, 'show_target_armies'): dialog.show_target_armies = dialog.add_text(240, 70, 'target') dialog.show_origin_armies.render_text("origin: %s" % (origin.armies - dialog.current)) dialog.show_target_armies.render_text("target: %s" % dialog.current)
def show_current_human_player(game_master): datastore = Datastore() asset = datastore.get_entry('player_colour') player = game_master.current_player() if isinstance(player, risk.player.HumonRiskPlayer): try: asset.set_colour(TerritoryAsset.mapping[player]) except KeyError: error("couldn't find key entry for player: %s" % player.name) asset.set_colour(assets.base.BLACK) else: asset.set_colour(assets.base.GREY)
def add_state_indicators(picasso, game_master): datastore = Datastore() pos_x = 867 state_indicators = { 'reinforce': (pos_x, 548), 'attack': (pos_x, 600), 'fortify': (pos_x, 652), } for state, coordinate in state_indicators.items(): asset = assets.image.ToggleImageAsset(coordinate[0], coordinate[1], "assets/art/gui/button_%s_highlight.png" % state) datastore.add_entry(state, asset, 'states') picasso.add_asset(UI_OVERLAY_LEVEL0, asset)
def initialize_territories(picasso, game_master): datastore = Datastore() for continent, territories in game_master.board.continents.iteritems(): for territory_name, territory in territories.iteritems(): coordinate = territory_coordinates[continent][territory_name] graphic_asset = build_territory_asset(continent, territory, coordinate[0], coordinate[1]) army_count_asset = assets.territory.ArmyCountAsset(graphic_asset) picasso.add_asset('3_territories', graphic_asset) picasso.add_asset('4_army_count', army_count_asset) datastore.add_entry(territory_name, graphic_asset, 'territories') risk.logger.debug("assigning player colours") build_player_colour_mapping(game_master.players)
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)
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)
def update_current_phase(game_master, previous, current): for state, asset in Datastore().get_storage('states').iteritems(): asset.set_state(state == current)
def update_game_info_panel(*args): Datastore().get_entry('game_info').update()
def add_overlay(picasso): datastore = Datastore() overlay = assets.image.ImageAsset(0, 0, DEFAULT_OVERLAY) datastore.add_entry('overlay', overlay) picasso.add_asset('0_overlay', overlay)
def enable_adjacent_territories(origin): datastore = Datastore() assets = datastore.get_storage('territories') assets[origin.name].disabled = False for neighbour in origin.neighbours.values(): assets[neighbour.name].disabled = False
def disable_enemy_territories(player): datastore = Datastore() for asset in datastore.get_storage('territories').values(): if asset.territory.owner != player: asset.disabled = True
def get_all_clickables(): datastore = Datastore() return list(datastore.get_storage('buttons').values()) + \ list(datastore.get_storage('territories').values())