def trad_each_country_card(game, player): finished_trading = False while not finished_trading: non_used_cards = [] print(f"Checking {player.name}'s country cards") for card in player.cards: if not card.already_traded and (card.country in player.countries): non_used_cards.append(card) if len(non_used_cards) > 0: print(f"Following cards can be traded:") for num, c in enumerate(non_used_cards): print(f" {num} - {c}") card_no = helpers.prompt_int_range( f'Please choose a card to be claimed (1-{len(non_used_cards)} or 0 to skip): ', 'Wrong input!', 0, len(non_used_cards)) if card_no > 0: selected_card = non_used_cards[card_no - 1] print(f"Trading {selected_card}") game.TradeCardPosessedCountry(selected_card) else: finished_trading = True else: print(f"No individual cards to trade for armies.") break
def deployment_round(player, game): print(f"\n{player.name}'s deployment of new armies\n") print(f'Current player: {game.current_player}') armies_no = game.GetAmountArmiesPerTurn(player) p_countries = game.GetCountries(player) p_countries_no = len(p_countries) print( f'{player.name} has {p_countries_no} and thus gets {armies_no} to deploy into the map this round.' ) while armies_no > 0: print(f"{player.name}'s countries:") country = enumerate_countries_and_pick_one(p_countries) if country: armies_to_deploy = helpers.prompt_int_range( f'How many armies should be deployed? (1-{armies_no} or 0 to cancel) ', None, 0, armies_no) country.armies += armies_to_deploy armies_no -= armies_to_deploy print(f'{player.name} has placed all available armies on the map.') show_player_countries(player, game) game.AdvanceNextPlayer()
def prompt_players(game): """ Prompts for players and sets name and color. :return: A list of objects of type Player """ names_and_colors = [] min_num = 2 max_num = 6 # while not (number_players >= min_num and number_players <= max_num): # number_players = int(input('How many players will be playing ({}-{})? '.format(min_num, max_num))) number_players = helpers.prompt_int_range( 'How many players will be playing? ', None, 2, 6) print(f"\nAlright, we have {number_players} today!\n") for x in range(number_players): name = input("Please enter player {}'s name: ".format(x + 1)) p_color = colors.pop() print("Player {} is {} with color {}.\n".format(x + 1, name, p_color)) names_and_colors.append((name, p_color)) print("Because you cannot have people pick colors." "You'll have a bunch of guys fighting over who's Mr. Black.\n") game.AssignPlayers(names_and_colors) helpers.press_any_key()
def enumerate_countries_and_pick_one(countries): for (idx, c) in enumerate(countries): print(f'{idx + 1} - {c}') max_index = len(countries) country_no = helpers.prompt_int_range( f'Please select a country from the list (1-{max_index} or 0 to pass): ', None, 0, max_index) if country_no == 0: return None else: return countries[country_no - 1]
def movement_round(player, game): print(f'\nMovement round from {player.name}\n') print(f'Current player: {game.current_player}') countries_relocate = game.GetCountries(player, True) done_moving = False while not done_moving: if len(countries_relocate) > 0: cs_relocate_this_single_time = [] for c in countries_relocate: if c.armies > 1: cs_relocate_this_single_time.append(c) print( f'Countries that can move troops this round' f' (does not change if other countries have more than one army after relocating once):' ) # Determine country from which troops are moving for nr, c in enumerate(cs_relocate_this_single_time): print(f'{nr+1} - {c}') relocating_country_no = helpers.prompt_int_range( 'Please enter the number of the country to relocate troops (or 0 to pass): ', None, 0, len(cs_relocate_this_single_time)) if relocating_country_no != 0: relocating_country = cs_relocate_this_single_time[ relocating_country_no - 1] # Determine number of troops to move if relocating_country.armies == 2: print('You can only move one army from this country.') troops_no = 1 else: troops_min = 1 troops_max = relocating_country.armies - 1 troops_no = helpers.prompt_int_range( f'Please enter the number of troops you want to move ({troops_min}-{troops_max}): ', None, troops_min, troops_max) # Determine target country possible_target_countries = [] for c in relocating_country.neighbours: if c.player == player: possible_target_countries.append(c) if len(possible_target_countries) > 0: for nr, c in enumerate(possible_target_countries): print(f'{nr + 1} - {c}') target_country_no = helpers.prompt_int_range( 'Please enter the number of target the country (or 0 to pass): ', None, 0, len(possible_target_countries)) target_country = possible_target_countries[ target_country_no - 1] relocating_country.armies -= troops_no target_country.armies += troops_no print( f'\nMoved armies in following countries:\n - From: {relocating_country}\n - To: {target_country}' ) else: print(f'No possible target countries to move!') else: print(f'{player} has finished moving.') done_moving = True else: print( f'Player has no countries with more than one troop that could relocate.' ) done_moving = True game.AdvanceNextPlayer()
def attack_round(player, game): print(f'Current player: {game.current_player}') finished_attacking = False while not finished_attacking: show_player_countries_which_can_attack(player, game) player_cs = game.GetCountries(player, True) if len(player_cs) > 0: attacking_country_no = helpers.prompt_int_range( 'Which country is attacking? (Enter number or 0 to pass) ', None, 0, len(player_cs)) if attacking_country_no > 0: attacker_c = player_cs[attacking_country_no - 1] enemy_countries = [] for c in attacker_c.neighbours: if c.player != attacker_c.player: enemy_countries.append(c) if len(enemy_countries) > 0: print( f'Country {attacker_c.name} can attack these enemy countries:' ) x = 0 for n in enemy_countries: x += 1 print(f'{x} - {n}') attacked_country_no = helpers.prompt_int_range( 'Which country do you wish to attack? (Enter number) ', None, 1, len(enemy_countries)) attacked_country_no -= 1 attacked_c = enemy_countries[attacked_country_no] max_attack_troops = attacker_c.armies - 1 # You cannot attack with more than three armies no matter how many the country has. if max_attack_troops > 3: max_attack_troops = 3 if max_attack_troops == 1: print('Only one army available to attack.') troops_no = 1 else: troops_no = helpers.prompt_int_range( f'How many troops are attacking? (1 to {max_attack_troops}) ', None, 1, max_attack_troops) # game.Attack(attacker_c, attacked_c, dices_attacker, dices_defender) battle = game.CallAttack(attacker_c, attacked_c, troops_no) print(f"\nFollowing battle will take place:\n{battle}") input( f'\n{player.name}, press any key to throw {troops_no} dices...' ) battle.RollDicesAttacker() print(f'{player.name} got dices {battle.dices_attacker}') attacker_loses_before_fighting = True for dice in battle.dices_attacker: if dice > 1: attacker_loses_before_fighting = False if attacker_loses_before_fighting: print( f'Ones means that the attacker cannot win, defender does not need to throw dices.' ) battle.RollDicesDefender( ) # Because the object still needs dices to calculate else: input( f'\n{attacked_c.player.name}, press any key to throw {attacked_c.armies} dices...' ) battle.RollDicesDefender() print( f'{attacked_c.player.name} got dices {battle.dices_defender}' ) battle.Calculate() if battle.defender_lost_country: game.UpdatePlayerCountries(battle.defending_player) game.UpdatePlayerCountries(battle.attacking_player) print(f"\nBattle results:\n{battle}") print( f'\nStatus after battle:\n - Attacker {attacker_c}\n - Defender {attacked_c}' ) else: print(f'{attacker_c} has no enemy neighbour countries.') helpers.press_any_key() else: finished_attacking = True else: print( f'{player.name} has no countries with more than one army that could attack.' ) finished_attacking = True helpers.press_any_key()