예제 #1
0
    def at_landmark(self):
        """
    Handles landmark options.
    
    Arguments:
      None
      
    Returns:
      None
    """
        # Allow infinite resting.
        while not self.should_close:
            self.player.print_status()
            self.messages.print_message('landmark_options')
            options = [1, 2]
            response = io.get_input_int_protected(options)

            # Rest.
            if response == 1:
                self.rest()

            # Continue.
            elif response == 2:
                return

            # Check for end game.
            if self.player.check_for_end_game(output=False):
                self.should_close = True
예제 #2
0
    def at_fort(self):
        """
    Handles fort options.
    
    Arguments:
      None
      
    Returns:
      None
    """
        # Allow infinite resting/shopping.
        while not self.should_close:
            self.player.print_status()
            self.messages.print_message('fort_options')
            options = [1, 2, 3]
            response = io.get_input_int_protected(options)
            if response == 1:
                self.rest()
            elif response == 2:
                self.store(fort=True)
            elif response == 3:
                return

            # Check for lose conditions.
            if self.player.check_for_end_game(output=False):
                self.should_close = True
예제 #3
0
    def pick_start_date(self):
        """
    Prompts user to proceed with standard start data or change to a custom date.
    
    Arguments:
      None
    
    Returns:
      None
    """
        print(
            'Would you like to take off on {} (1) or on a different date (2)?'.
            format(self.player.current_date))
        options = [1, 2]
        response = io.get_input_int_protected(options)
        if response == 1:
            return
        print("You can choose to start between March 1 and May 1")

        # Get month.
        print('Please enter what month you would like to start. \
          \n \t March (3) \
          \n \t April (4) \
          \n \t May   (5) \
          ')
        options = [3, 4, 5]
        response = io.get_input_int_protected(options)

        # Change dates allowed per game spec and real calendar days.
        days_allowed = 31
        if response == 4:
            days_allowed = 30
        if response == 5:
            days_allowed = 1

        # Get day.
        self.player.current_date = self.player.current_date.replace(
            month=response)
        print('Please enter what day you would like to start.')
        response = io.get_input_int(low=1, high=days_allowed)
        self.player.current_date = self.player.current_date.replace(
            day=response)
예제 #4
0
    def at_river(self, location):
        """
    Handles river options.  Calls misfortunes if player fails river crossing.
    
    Arguments:
      None
      
    Returns:
      None
    """
        river_height = location.height

        # Allow infinite resting and attempts at crossing river.
        while not self.should_close:
            self.player.print_status()
            print("River Height: {} feet".format(river_height))
            self.messages.print_message('river_options')
            options = [1, 2, 3, 4]
            response = io.get_input_int_protected(options)
            # Rest.
            if response == 1:
                self.rest()

            # Ford.
            elif response == 2:
                if river_height > 3:  # Fail fording rivers higher than 3ft.
                    misfortunes.failed_river(self.player)
                else:
                    print("You successfully forded the river")
                    return

            # Chaulk and float.
            elif response == 3:
                # 65% chance of succesful floating.
                chance = 65
                n_chance = list(range(1, chance + 1))
                if random.randint(1, 100) in n_chance:
                    print("You successfully floated the river")
                    return
                else:
                    misfortunes.failed_river(self.player)

            # Ferry.
            elif response == 4:
                if self.player.can_consume('money', 5):
                    print("You took the ferry across")
                    self.player.consume('money', 5)
                    return
                else:
                    print("You do not have enough money")

            # Check for end game conditions.
            if self.player.check_for_end_game(output=False):
                self.should_close = True
예제 #5
0
def hunt(player):
    """
  Entry-point into hunting module from the engine.
  Defines animals, encounter chance, food given, and bullets required.
  
  Arguments:
    player (player.player): Used to interface with the game-state.
  
  Returns:
    int: Amount of food obtained from hunting.
  """
    food = 0

    # Generate random food given for deer, bear, moose.
    deer = random.randint(35, 60)
    bear = random.randint(100, 300)
    moose = random.randint(300, 700)

    # (Name, % chance, food given, bullets consumed)
    animals = [('rabbit', 50, 2, 10), ('fox', 25, 5, 8), ('deer', 20, deer, 5),
               ('bear', 10, bear, 10), ('moose', 5, moose, 10)]

    # Generate encountered animals
    encountered = []
    for animal in animals:
        if did_encounter(animal[1]):
            encountered.append(animal)

    # Handle no animals encountered.
    if len(encountered) == 0:
        print("You didn't encounter any animals")
        return food

    # Prompt user to hunt each animal and play hunting puzzle.
    else:
        print(create_string(encountered))
    for animal in encountered:
        print("Do you want to hunt the {}? (1) Yes (2) No".format(animal[0]))
        options = [1, 2]
        response = io.get_input_int_protected(options)
        if response == 1:
            # Only allow hunt if player has enough bullets.
            if player.get_from_inventory('bullets') >= 10:
                print("Win the guessing game to successfully hunt")
                if puzzle.did_win():
                    food += animal[2]
                    player.consume('bullets', animal[3])
                    print("Food collected: {} pounds".format(animal[2]))
                    print("Bullets remaining: {}".format(
                        player.get_from_inventory('bullets')))
            else:
                print("You need 10 or more bullets to hunt")
                return food
    return food
예제 #6
0
    def hunt(self):
        """
    Calls hunting module to hunt and handles updating amount of food.
    Allows player to adjust rations.
    
    Arguments:
      None
      
    Returns:
      None
    """
        current_food = self.player.get_from_inventory('food')

        # Hunt.
        hunted_food = hunting.hunt(self.player)
        print("You returned with {} pounds of food".format(hunted_food))

        # Adjust rations.
        self.messages.print_message('rations')
        options = [1, 2, 3]
        response = io.get_input_int_protected(options)
        if response == 1:
            self.player.rations = 2
        elif response == 2:
            self.player.rations = 3
        elif response == 3:
            self.player.rations = 5

        # Consume food.
        food_consumed = self.player.members_alive * self.player.rations
        print("You consumed {} pounds of food".format(food_consumed))
        current_food -= food_consumed

        # Handle adding food to inventory.
        if current_food + hunted_food > 1000:
            print("The wagon can only hold 1000 pounds of food")
            left_food = hunted_food + current_food - 1000
            print("You left {} pounds of food behind".format(left_food))
            self.player.update_inventory('food', 1000)
        else:
            total_food = current_food + hunted_food
            self.player.update_inventory('food', total_food)

        # Advance one day and fully heal members.
        self.player.advance_time(1)
        self.player.heal_all_to_full_if_sick()
예제 #7
0
    def take_turn(self):
        """
    Main menu for game. Allows user to pick what to do, updates mileage,
    checks for end-game scenarios, and chance for raider attack.
    
    Arguments:
      None
      
    Returns:
      None
    """
        sleep(self.sleep)
        self.player.print_status()

        # Handle turn options.
        self.messages.print_message('turn_options')
        options = [1, 2, 3, 4]
        response = io.get_input_int_protected(options)
        if response == 1:
            self.rest()
        elif response == 2:
            self.travel()
        elif response == 3:
            self.hunt()
        elif response == 4:
            self.should_close = True
            self.did_quit = True
            return

        # Update mileage, check for end game and chance for raiders.
        self.player.update_miles_to_next()
        if self.player.check_for_end_game():
            self.should_close = True
            return
        if misfortunes.randomize(self.player):
            self.should_close = True
            return
        if self.player.check_for_end_game():
            self.should_close = True
            return
        misfortunes.raider_attack(self.player)
예제 #8
0
def did_win():
    """
  Entry point into the puzzle mini-game.
  
  Arguments:
    None
    
  Returns:
    bool: True if the player wins the puzzle mini-game, False otherwise.
  """
    random.seed()

    # Initialize.
    number = random.randint(1, 10)
    guesses = 3
    guesses_remaining = guesses
    options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    print("Guess a number between 1 and 10 ({} guesses remaining)".format(
        guesses_remaining))
    for i in range(guesses):
        response = io.get_input_int_protected(options)
        guesses_remaining -= 1

        # Handle winning and give hints.
        if response == number:
            print("You win!")
            return True
        elif response > number and i < guesses - 1:
            print("Try a lower number ({} guesses remaining)".format(
                guesses_remaining))
        elif response < number and i < guesses - 1:
            print("Try a higher number ({} guesses remaining)".format(
                guesses_remaining))

    # Handle losing.
    print("Better luck next time.")
    return False
예제 #9
0
def raider_attack(player):
    """
  Entry-point from the engine.
  Random attack based on player's mileage.
  Player can fight, surrender, or run away from a raider attack with varying consequences.

  Arguments:
    player (player.player): Used to interface with the game-state.
    
  Returns:
    None
  """
    random.seed()
    mileage = player.miles_traveled

    # Generate probability based on mileage.
    chance = int(((mileage / 100 - 4)**2 + 72) /
                 ((mileage / 100 - 4)**2 + 12) - 1) + 1
    numbers = list(range(1, chance + 1))

    if random.randint(1, 100) in numbers:
        print("Raiders are attacking")
        print("Do you want to run (1), fight (2), or surrender (3)?")
        options = [1, 2, 3]
        response = get_input_int_protected(options)

        # Run.
        if response == 1:
            if player.can_consume('oxen', 1):
                player.consume('oxen', 1)
            if player.can_consume('food', 10):
                player.consume('food', 10)
            if player.can_consume('parts', 1):
                player.consume('parts', 1)
            print(
                "You managed to escape, but you left behind 1 ox, 10 pounds of food, and a spare wagon part"
            )

        # Fight.
        elif response == 2:
            print("You must win the puzzle in order to defeat the raiders")
            if puzzle.did_win():
                print(
                    "You search the raiders' gear and found 50 pounds of food and 50 bullets"
                )
                player.add_to_inventory('food', 50)
                player.add_to_inventory('bullets', 50)
            else:
                print(
                    "The raiders stole a quarter of your money and 50 bullets")
                current_money = player.get_from_inventory('money')
                stolen_money = int(current_money / 4)
                player.consume('money', stolen_money)
                if player.can_consume('bullets', 50):
                    player.consume('bullets', 50)

        # Surrender.
        elif response == 3:
            print("You surrendered to the raiders")
            print("The raiders stole a quarter of your money")
            current_money = player.get_from_inventory('money')
            stolen_money = int(current_money / 4)
            player.consume('money', stolen_money)