async def play_sniper_rifle(game_state) -> None: """ Function used to control of play of SNIPER card. :param game_state: GameState object with all game data inside """ shelter = game_state.active_player if len(game_state.city_deck) > 0: top_card = game_state.city_deck[0] if top_card.top != ZombieType.SURVIVOR: message = f'There is {top_card.top.value} in the city. Should the survivors shoot it[y/n]?\n>' action = await get_action(game_state, message, ['y', 'n']) if action == 'y': shelter.print( f'One of survivors killed {top_card.top.value} with {Supply.SNIPER.value}!' ) shelter.print('City is safe now!') game_state.city_graveyard.append(game_state.get_city_card()) put_supplies_on_graveyard(game_state, Supply.SNIPER) return big_inside, lesser_counter = count_zombies(game_state) if big_inside and lesser_counter == 0: play_weapon(game_state, Supply.SNIPER, strong=True) elif lesser_counter >= 0 and not big_inside: play_weapon(game_state, Supply.SNIPER) else: message = 'What survivors should do[0/1]?\n[0]: kill big zombie\n[1]: kill lesser zombie\n>' action = await get_action(game_state, message, ['0', '1']) if action == '0': play_weapon(game_state, Supply.SNIPER, strong=True) else: play_weapon(game_state, Supply.SNIPER)
def use_shotgun(self) -> None: """Helper method used to play Shotgun card.""" big_zombie, lesser_count = common.count_zombies(self.game_state) self.planned_moves = [str(self.supplies.index(Supply.SHOTGUN))] if lesser_count > 1: self.planned_moves.append('1') elif big_zombie: self.planned_moves.append('0')
def defend_with_weapon(self) -> None: """Helper method used to defend cpu shelter with weapon cards.""" big_zombie, lesser_count = common.count_zombies(self.game_state) if Supply.AXE in self.supplies and lesser_count > 0: self.planned_moves = [str(self.supplies.index(Supply.AXE))] elif Supply.GUN in self.supplies and lesser_count > 0: self.planned_moves = [str(self.supplies.index(Supply.GUN))] elif Supply.SHOTGUN in self.supplies: self.use_shotgun() elif Supply.SNIPER in self.supplies: self.use_sniper(defend=True)
def use_drone(self) -> None: """Helper method used to play Drone card.""" rivals_idx = [ str(index) for index in range(len(self.game_state.players_still_in_game) - 1) ] big_zombie, lesser_count = common.count_zombies(self.game_state) if lesser_count > 0 and big_zombie: self.planned_moves = \ [str(self.supplies.index(Supply.DRONE)), choice(['0', '1']), choice(rivals_idx)] if lesser_count == 0 and big_zombie or not big_zombie and lesser_count > 0: self.planned_moves = [ str(self.supplies.index(Supply.DRONE)), choice(rivals_idx) ]
def use_lure_out(self) -> None: """Helper method used to play Lure Out card.""" rivals_idx = [ str(index) for index in range(len(self.game_state.players_still_in_game) - 1) ] big_zombie, lesser_count = common.count_zombies(self.game_state) self.planned_moves = [str(self.supplies.index(Supply.LURE_OUT))] if self.zombie_in_city: self.planned_moves.append('y') if len(rivals_idx) > 1: self.planned_moves.append(choice(rivals_idx)) if big_zombie and lesser_count > 0: self.planned_moves.append('0') if len(rivals_idx) > 1: self.planned_moves.append(choice(rivals_idx))
async def play_shotgun(game_state) -> None: """ Function used to control of play of SHOTGUN card. :param game_state: GameState object with all game data inside """ big_inside, lesser_counter = count_zombies(game_state) if big_inside and lesser_counter == 0: play_weapon(game_state, Supply.SHOTGUN, strong=True) elif lesser_counter <= 1 and not big_inside: play_weapon(game_state, Supply.SHOTGUN) elif lesser_counter > 1 and not big_inside: play_weapon(game_state, Supply.SHOTGUN, destroyed=False) play_weapon(game_state, Supply.SHOTGUN) else: message = 'What survivors should do [0/1]?\n[0]: kill big zombie\n' \ f'[1]: kill up to two lesser zombies ({lesser_counter} inside)\n>' action = await get_action(game_state, message, ['0', '1']) if action == '0': play_weapon(game_state, Supply.SHOTGUN, strong=True) elif lesser_counter == 1: play_weapon(game_state, Supply.SHOTGUN) else: play_weapon(game_state, Supply.SHOTGUN, destroyed=False) play_weapon(game_state, Supply.SHOTGUN)