async def play_summon(game_state, summon: Supply) -> None: """ Function used to control of play of any summon card. :param game_state: GameState object with all game data inside :param summon: Supply enum with played card """ shelter = game_state.active_player arrives = 1 if summon == Supply.FLARE_GUN: arrives = 2 shelter.print(f'One of survivors used {summon.value}!') if is_loud(summon): shelter.print( f'The sounds of the {summon.value} could be heard from miles away!' ) for _ in range(arrives): if len(game_state.city_deck ) > 0 and game_state.city_deck[0].top == ZombieType.SURVIVOR: card = game_state.get_city_card() shelter.print( f'New survivor has arrived to "{shelter.name}" shelter!') shelter.survivors.append(card) elif summon == Supply.RADIO: shelter.print( f'Survivors cannot use {summon.value} when zombies roam all over the city!' ) return else: shelter.print('Nobody else arrived...') break put_supplies_on_graveyard(game_state, summon)
def play_card_for_noise(self) -> None: """Helper method used to play cards which are loud.""" tmp = copy(self.supplies) if Supply.MEGAPHONE in self.supplies: tmp.pop(tmp.index(Supply.MEGAPHONE)) tmp.append(Supply.MEGAPHONE) if Supply.FLARE_GUN in self.supplies: tmp.pop(tmp.index(Supply.FLARE_GUN)) tmp.append(Supply.FLARE_GUN) tmp_loud = [common.is_loud(supply) for supply in tmp] obj = tmp[tmp_loud.index(True)] if obj not in [Supply.SWAP, Supply.CHAINSAW]: index = self.supplies.index(obj) self.planned_moves = [str(index)] elif obj == Supply.SWAP: self.use_swap() else: self.use_chainsaw()
def kill_zombie(game_state, supply: Supply, zombie_card, destroyed: bool) -> None: """ Helper function used to control process of killing zombie :param game_state: GameState object with all game data inside :param supply: Supply enum with played card, used to kill zombie :param zombie_card: CityCard object with zombie on top :param destroyed: bool flag indicator if supply will be destroyed after current use """ shelter = game_state.active_player zombie = zombie_card.top shelter.print( f'One of survivors killed {zombie.value} with {supply.value}!') put_zombie_on_graveyard(game_state, zombie_card) if is_loud(supply): shelter.print( 'The sounds of the struggle could be heard from miles away!') if destroyed: put_supplies_on_graveyard(game_state, supply)
async def play_round(self) -> None: """ Method used to control of play of one player round and all actions related with it. """ shelter = self.active_player shelter.card_used_or_discarded = False opening_supplies = len(shelter.supplies) shelter.print(f'{shelter.name} will play round now...') for zombie in shelter.zombies: zombie.active = True turn_end = False discarded = False while len(shelter.supplies) > 0 and not turn_end: shelter.gui(self) self.clean_up_table() if discarded: turn_end = await self.discard_supplies_move(turn_end) continue action, possible_actions = await self.ask_player_what_move() if action in possible_actions[:-1]: loud = common.is_loud(shelter.supplies[int(action)]) await play_supplies[shelter.supplies[int(action)]](self) if loud: self.zombie_show_up() elif action == possible_actions[ -1] and not shelter.card_used_or_discarded: discarded = True turn_end = await self.discard_supplies_move(turn_end) else: turn_end = True if opening_supplies > len(shelter.supplies): shelter.card_used_or_discarded = True if len(shelter.survivors) == 0 or len( self.players_still_in_game) < 2: turn_end = True await self.end_active_player_turn()
async def ask_player_what_move(self) -> tuple[int, list[str]]: """ Method used to get chosen action from active player. :return: tuple with int with chosen action and list of string of all possible actions """ shelter = self.active_player possible_actions = [ str(number) for number in range(len(shelter.supplies) + 1) ] question = 'What do you want to do?\n' for index, supply in enumerate(shelter.supplies): loud = '' if common.is_loud(supply): loud = '(loud instantly)' elif common.loud_obstacle(supply): loud = '(loud after use in defence phase)' question += f'[{index}] Use {supply.value} {loud}\n' if not shelter.card_used_or_discarded: question += f'[{len(shelter.supplies)}] Discard some supplies\n' else: question += f'[{len(shelter.supplies)}] End my turn\n' action = await common.get_action(self, question + '> ', possible_actions) return action, possible_actions
def supplies_loud(self) -> list: """:return: list with bool value if particular supply is loud""" return [common.is_loud(supply) for supply in self.supplies]