コード例 #1
0
def play_weapon(game_state,
                weapon: Supply,
                strong: bool = False,
                destroyed: bool = True) -> None:
    """
    Function used to control of play of any weapon card.
    :param game_state: GameState object with all game data inside
    :param weapon: Supply enum with played card
    :param strong: bool flag indicator if this weapon can kill big zombie
    :param destroyed: bool flag indicator if this weapon will be destroyed after current use
    """
    shelter = game_state.active_player
    used = False
    for supply in shelter.supplies:
        if supply is weapon and not used:
            for zombie_card in shelter.zombies:
                if used:
                    break
                elif strong and zombie_card.top == ZombieType.BIG:
                    destroyed = True
                    kill_zombie(game_state, supply, zombie_card, destroyed)
                    used = True
                elif not strong and zombie_card.top != ZombieType.BIG:
                    kill_zombie(game_state, supply, zombie_card, destroyed)
                    used = True
    if not used:
        shelter.print(f'One of survivors used {weapon.value} for nothing!')
        put_supplies_on_graveyard(game_state, weapon)
コード例 #2
0
ファイル: summons.py プロジェクト: devdo-eu/zombreak
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)
コード例 #3
0
async def play_chainsaw(game_state) -> None:
    """
    Function used to control of play of CHAINSAW card.
    :param game_state: GameState object with all game data inside
    """
    shelter = game_state.active_player
    rivals = []
    choice_message = ''
    possible_actions = []
    for rival in game_state.players:
        if rival != shelter and not rival.defeated and len(
                rival.obstacles) > 0:
            rivals.append(rival)
    for index, rival in enumerate(rivals):
        choice_message += f'[{index}]: {rival.name} shelter\n'
        possible_actions.append(str(index))
    if len(rivals) > 0:
        message = f'Where survivor should use {Supply.CHAINSAW.value} to destroy fortifications?\n>' + choice_message
        action = await get_action(game_state, message, possible_actions)
        rival = rivals[int(action)]
        shelter.print(
            f'Survivor successfully destroyed all defence at {rival.name} shelter!'
        )
        for _ in range(len(rival.obstacles)):
            obstacle = rival.obstacles[0]
            rival.obstacles.remove(obstacle)
            game_state.supply_graveyard.append(obstacle)
    shelter.print(
        f'The sounds of the {Supply.CHAINSAW.value} could be heard from miles away!'
    )
    put_supplies_on_graveyard(game_state, Supply.CHAINSAW)
コード例 #4
0
async def play_drone(game_state) -> None:
    """
    Function used to control of play of DRONE card.
    :param game_state: GameState object with all game data inside
    """
    shelter = game_state.active_player
    if len(shelter.zombies) == 0:
        shelter.print(f'You cannot use {Supply.DRONE.value} for nothing...')
    else:

        async def use_drone(zombie) -> None:
            """
            Helper function used to play DRONE card and get chosen action from player.
            :param zombie: CityCard object with zombie on top.
            """
            choice_message, possible_actions, rivals = find_rivals_and_build_action_message(
                game_state)
            shelter.print(
                f'One of survivors used {Supply.DRONE.value} to lure {zombie.top.value} out...'
            )
            message = f'Where {zombie.top.value} will be lured?\n' + choice_message
            action = await get_action(game_state, message, possible_actions)
            shelter.zombies.remove(zombie)
            shelter.print(
                f'{str(zombie.top.value).capitalize()} was lured to "{rivals[int(action)].name}" shelter!'
            )
            rivals[int(action)].zombies.append(zombie)

        message = 'What survivors should do [0/1]?\n[0]: lure big zombie out of shelter\n' \
                  '[1]: lure lesser zombie out of shelter\n>'
        await count_zombies_and_execute_function(game_state, message,
                                                 use_drone)
        put_supplies_on_graveyard(game_state, Supply.DRONE)
コード例 #5
0
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)
コード例 #6
0
ファイル: defences.py プロジェクト: devdo-eu/zombreak
async def defend_with_mine_field(game_state) -> None:
    """
    Function used to control of defend phase with MINE FIELD card.
    :param game_state: GameState object with all game data inside
    """
    shelter = game_state.active_player

    async def use_mine_field(zombie) -> None:
        """
        Helper function used to play MINE FIELD card at defend phase and get chosen action from player.
        :param zombie: CityCard object with zombie on top.
        """
        shelter.print(
            f'{str(zombie.top.value).capitalize()} was wiped out in a mine explosion!'
        )
        shelter.print(
            f'The sounds of the {Supply.MINE_FILED.value} could be heard from miles away!'
        )
        put_zombie_on_graveyard(game_state, zombie)

    message = 'What survivors should do [0/1]?\n[0]: lure big zombie on mine field\n' \
              '[1]: lure lesser zombie on mine field\n>'
    for count in range(2):
        await count_zombies_and_execute_function(game_state, message,
                                                 use_mine_field, (3 - count))
    put_supplies_on_graveyard(game_state, Supply.MINE_FILED, obstacle=True)
コード例 #7
0
async def play_lure_out(game_state) -> None:
    """
    Function used to control of play of LURE OUT card.
    :param game_state: GameState object with all game data inside
    """
    shelter = game_state.active_player
    choice_message, possible_actions, rivals = find_rivals_and_build_action_message(
        game_state)
    used = False
    if len(game_state.city_deck) > 0:
        top_card = game_state.city_deck[0]
        if top_card.top != ZombieType.SURVIVOR:
            zombie_cap = str(top_card.top.value).capitalize()
            message = f'{zombie_cap} is in the city. Should the survivors lure it to rival shelter[y/n]?\n>'
            action = await get_action(game_state, message, ['y', 'n'])
            if action == 'y':
                message = 'Which shelter should the survivors lure the zombies into?\n' + choice_message
                action = await get_action(game_state, message,
                                          possible_actions)
                rival = rivals[int(action)]
                card = game_state.get_city_card()
                shelter.print(
                    f'One of survivors lure {card.top.value} from city into {rival.name} shelter!'
                )
                rival.zombies.append(card)
                used = True

    if len(shelter.zombies) > 0:
        message = 'What survivors should do [0/1]?\n[0]: lure big zombie out of shelter\n' \
                  '[1]: lure lesser zombie out of shelter\n>'

        async def lure_out(zombie_card) -> None:
            """
            Helper function used to play LURE OUT card and get chosen action from player.
            :param zombie_card: CityCard object with zombie on top.
            """
            shelter.print(
                f'One of survivors used {Supply.LURE_OUT.value} to lure {zombie_card.top.value} out...'
            )
            message = f'Where {zombie_card.top.value} will be lured?\n' + choice_message
            action = await get_action(game_state, message, possible_actions)
            rival = rivals[int(action)]
            rival.zombies.append(zombie_card)
            shelter.print(
                f'One of survivors lure {zombie_card.top.value} from our shelter into {rival.name} shelter!'
            )
            shelter.zombies.remove(zombie_card)

        await count_zombies_and_execute_function(game_state, message, lure_out)
        put_supplies_on_graveyard(game_state, Supply.LURE_OUT)
    elif used:
        put_supplies_on_graveyard(game_state, Supply.LURE_OUT)
    else:
        shelter.print(f'You cannot use {Supply.LURE_OUT.value} for nothing...')
コード例 #8
0
ファイル: defences.py プロジェクト: devdo-eu/zombreak
async def defend_with_barricades(game_state) -> None:
    """
    Function used to control of defend phase with BARRICADES card.
    :param game_state: GameState object with all game data inside
    """
    shelter = game_state.active_player
    shelter.print(f'There are {Supply.BARRICADES.value} inside shelter!')
    for zombie in shelter.zombies:
        if zombie.active:
            shelter.print(
                f'{Supply.BARRICADES.value} has stopped {zombie.top.value}')
            zombie.active = False
            put_supplies_on_graveyard(game_state,
                                      Supply.BARRICADES,
                                      obstacle=True)
            break
コード例 #9
0
ファイル: defences.py プロジェクト: devdo-eu/zombreak
async def defend_with_alarm(game_state) -> None:
    """
    Function used to control of defend phase with ALARM card.
    :param game_state: GameState object with all game data inside
    """
    shelter = game_state.active_player
    shelter.print(f'One of survivors used {Supply.ALARM.value}!')
    shelter.print(
        f'The sounds of the {Supply.ALARM.value} could be heard from miles away!'
    )
    for zombie in shelter.zombies:
        zombie.active = False
    shelter.print(
        f'Thanks to {Supply.ALARM.value} all survivors has managed to hide and are safe!'
    )
    put_supplies_on_graveyard(game_state, Supply.ALARM, obstacle=True)
コード例 #10
0
async def play_takeover(game_state) -> None:
    """
    Function used to control of play of TAKEOVER card.
    :param game_state: GameState object with all game data inside
    """
    shelter = game_state.active_player
    choice_message, possible_actions, rivals = find_rivals_and_build_action_message(
        game_state)
    message = 'From which shelter lure a survivor to join us?\n' + choice_message
    action = await get_action(game_state, message, possible_actions)
    rival = rivals[int(action)]
    survivor_card = rival.survivors[0]
    shelter.print(f'Survivor from {rival.name} shelter join to us!')
    rival.survivors.remove(survivor_card)
    if len(rival.survivors) == 0:
        shelter.print(f'No one was left in {rival.name} shelter...')
        rival.defeated = True
    shelter.survivors.append(survivor_card)
    put_supplies_on_graveyard(game_state, Supply.TAKEOVER)
コード例 #11
0
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)
コード例 #12
0
async def play_swap(game_state) -> None:
    """
    Function used to control of play of SWAP card.
    :param game_state: GameState object with all game data inside
    """
    shelter = game_state.active_player
    choice_message, possible_actions, rivals = find_rivals_and_build_action_message(
        game_state)
    message = 'Which player do you want to swap shelters with?\n' + choice_message
    action = await get_action(game_state, message, possible_actions)
    rival = rivals[int(action)]
    shelter.zombies, rival.zombies = rival.zombies, shelter.zombies
    shelter.print(
        f'Your survivors used {Supply.SWAP.value} to swap shelters with {rival.name}'
    )
    shelter.obstacles, rival.obstacles = rival.obstacles, shelter.obstacles
    shelter.print(
        f'The sounds of the {Supply.SWAP.value} could be heard from miles away!'
    )
    put_supplies_on_graveyard(game_state, Supply.SWAP)
コード例 #13
0
async def play_sacrifice(game_state) -> None:
    """
    Function used to control of play of SACRIFICE card.
    :param game_state: GameState object with all game data inside
    """
    shelter = game_state.active_player
    survivor_card = shelter.survivors[0]
    shelter.survivors.remove(survivor_card)
    game_state.city_graveyard.append(survivor_card)
    choice_message, possible_actions, rivals = find_rivals_and_build_action_message(
        game_state)

    for _ in range(len(shelter.zombies)):
        zombie_card = shelter.zombies[0]
        message = f'Where {zombie_card.top.value} will be lured?\n' + choice_message
        action = await get_action(game_state, message, possible_actions)
        shelter.zombies.remove(zombie_card)
        rivals[int(action)].zombies.append(zombie_card)
    shelter.print(
        'One of survivors in a heroic act led all the zombies out of the shelter!'
    )
    put_supplies_on_graveyard(game_state, Supply.SACRIFICE)