Пример #1
0
 def on_drop(self, player):
     if bool_prompt(f"{player} is about to drop their light source!",
                    "Continue? (yes/no): "):
         return super().on_drop(player)
     else:
         prompt(f"Not dropping the {self}.")
         return False
Пример #2
0
 def apply_damage(self, amount):
     if amount >= self.health:
         prompt(f"{self} has suffered a mortal wound!")
         quit_game()
     else:
         prompt(f"{self} suffers {amount} points of damage!")
         self.health -= amount
Пример #3
0
def move(direction, player):
    # the first letter of the direction is all we need
    dir = direction[0]
    if dir in player.room.connections:
        player.room = player.room.connections[dir]
    else:
        printing.prompt("You cannot go that way")
Пример #4
0
    def on_take(self, player):
        uncollected = self.uncollected
        super().on_take(player)

        if uncollected:
            player.add_score('items', self.value)
            prompt(f"{self.value} points added to {player}'s item score.")
Пример #5
0
def attack(monster_name, player):
    if not player.can_see():
        printing.prompt(f"{player} cannot see well enough to fight!")
    elif player.room.has_monster(monster_name):
        player.attack(monster_name)
    else:
        printing.prompt(f"There are no {monster_name}s for {player} to attack in here.")
Пример #6
0
def inspect_item(item_name, player):
    # Check both inventory and the floor
    for location in [player, player.room]:
        if location.has_item(item_name):
            printing.item(location.get_item(item_name))
            return
    
    printing.prompt(f"No {item_name}s in {player}'s inventory or this room")
Пример #7
0
def take_item(item_name, player):
    if not player.can_see():
        printing.prompt(f"{player} cannot see well enough to take anything.")
    elif player.room.has_item(item_name):
        player.take_item(item_name)
        player.last_item = item_name
    else:
        printing.prompt(f"There are no {item_name}s here to take")
Пример #8
0
    def attack(self, monster_name):
        monster = self.room.get_monster(monster_name)
        prompt(
            f"{self} swings at the {monster} with their {self.get_weapon()}.")

        if monster.on_attack(self):
            # Remove monster from the game if we've killed it
            self.room.remove_monster(monster)
        else:
            monster.retaliate(self)
Пример #9
0
    def choose_move(self, state):
        mv = None
        # Do not return until Move is valid
        while not mv or not state.validMove(mv):
            if state._stage == 0 or state._stage == 2:
                # Prompt for pass or flip if both are options
                if state._prev_move._action != 'flip' and \
                        state._num_flips[state._player] < const.MAX_FLIPS:
                    msg = 'Flip or Pass [f or p]:'
                    mapping = {'f': 'flip', 'p': 'none'}
                # Automatically pass if only option is a none Move
                else:
                    mv = Move('none', state._player)
                    break
            # Prompt for column if in 2nd stage of turn
            elif state._stage == 1:
                msg = 'Place [1-%d]:' % (const.NUM_COLS)
                mapping = {
                    str(n): 'place'
                    for n in range(1, const.NUM_COLS + 1)
                }

            # Get key pressed by user and create a corresponding Move object
            sys.stdout.flush()
            key = prompt(msg).lower()
            if key in mapping:
                if key.isnumeric():
                    mv = Move(mapping[key], state._player, int(key) - 1)
                else:
                    mv = Move(mapping[key], state._player)

        return mv
Пример #10
0
    def choose_move(self, state):
        mv = None
        # Do not return until Move is valid
        while not mv or not state.validMove(mv):
            if state._stage == 0 or state._stage == 2:
                # Prompt for pass or flip if both are options
                if state._prev_move._action != 'flip' and \
                        state._num_flips[state._player] < const.MAX_FLIPS:
                    msg = 'Flip or Pass [f or p]:'
                    mapping = {'f':'flip', 'p':'none'}
                # Automatically pass if only option is a none Move
                else:
                    mv = Move('none', state._player)
                    break
            # Prompt for column if in 2nd stage of turn
            elif state._stage == 1:
                msg = 'Place [1-%d]:' % (const.NUM_COLS)
                mapping = {str(n) : 'place' for n in range(1, const.NUM_COLS + 1)}

            # Get key pressed by user and create a corresponding Move object
            sys.stdout.flush()
            key = prompt(msg).lower()
            if key in mapping:
                if key.isnumeric():
                    mv = Move(mapping[key], state._player, int(key)-1)
                else:
                    mv = Move(mapping[key], state._player)

        return mv
Пример #11
0
def process_command(command, player):
    tokens = [token.lower() for token in command.split(" ")]

    # Commands with no arguments
    simple_commands = {
        "n": lambda: move("n", player),
        "w": lambda: move("w", player),
        "e": lambda: move("e", player),
        "s": lambda: move("s", player),
        "q": quit_game,
        "quit": quit_game,
        "i": lambda: printing.inventory(player),
        "inventory": lambda: printing.inventory(player),
        "h": printing.help,
        "help": printing.help,
        "score": lambda: printing.score(player)
    }

    # Commands with one or more arguments
    complex_commands = {
        "move": move,
        "inspect": inspect_item,
        "get": take_item,
        "take": take_item,
        "drop": drop_item,
        "attack": attack
    }

    # Handle 'it' as a stand-in for an item
    if len(tokens) is 2 and tokens[1] == "it":
        tokens[1] = player.last_item

    if tokens[0] in simple_commands:
        simple_commands[tokens[0]]()
    elif len(tokens) > 1 and tokens[0] in complex_commands:
        # Pass along the player object to complex commands
        complex_commands[tokens[0]](tokens[1], player)
    else:
        printing.prompt("Invalid command. Enter 'help' for a list of commands.")
Пример #12
0
def promptContinue(stats, msg=''):
    p1 = stats['game']._player_pair[0]
    p2 = stats['game']._player_pair[1]
    results = stats['results']
    msg = '\n' + msg + '\n'
    msg += str(p1) + ': ' + '/'.join(map(str, results))
    msg += '\n'
    msg += str(p2) + ': ' + '/'.join(map(str, (results[1], results[0], results[2])))
    msg += '\n'
    msg += "Play again [y/N]?"

    response = None
    while response == None:
        stats['game'].drawScreen()
        key = prompt(msg).lower()
        response = True if key == 'y' else False if key =='n' else None

    return response
Пример #13
0
def promptContinue(stats, msg=''):
    p1 = stats['game']._player_pair[0]
    p2 = stats['game']._player_pair[1]
    results = stats['results']
    msg = '\n' + msg + '\n'
    msg += str(p1) + ': ' + '/'.join(map(str, results))
    msg += '\n'
    msg += str(p2) + ': ' + '/'.join(map(str, (results[1], results[0], results[2])))
    msg += '\n'
    msg += "Play again [y/N]?"

    response = None
    while response == None:
        stats['game'].drawScreen()
        key = prompt(msg).lower()
        response = True if key == 'y' else False if key =='n' else None

    return response
Пример #14
0
def quit_game():
    printing.prompt("Thanks for playing!")
    exit()
Пример #15
0
def bool_prompt(message, prompt_message):
    choice = printing.prompt(message, prompt_message)
    return choice[0].lower() == 'y'
Пример #16
0
def drop_item(item_name, player):
    if player.has_item(item_name):
        player.drop_item(item_name)
        player.last_item = item_name
    else:
        printing.prompt(f"{player} has no {item_name}s to drop")
Пример #17
0
 def on_drop(self, player):
     prompt(f"{player} drops the {self} in the {player.room}")
     return True
Пример #18
0
 def on_take(self, player):
     self.uncollected = False
     prompt(f"{player} collects the {self} from the {player.room}")
     return True