def junction(): t3 = "Which room would you to enter?" + "\n" print_slow(t3, 0.03) while len(junction_history) > 0: if "1" in junction_history: print("Press 1 to enter the Battle Room") if "2" in junction_history: print("Press 2 to enter the Trap Room") if "3" in junction_history: print("Press 3 to enter the Aeon Chamber") room_choice = input("->") if room_choice == "1": junction_history.pop(0) battleroom() break elif room_choice == "2": junction_history.pop(1) break # call trap room function elif room_choice == "3": junction_history.pop(2) break # call Aeon chamber function else: print("You walk into a wall and hurt yourself..." + "\n") hero.health -= 1
def _options(self, item, category, action): options_map = {1: "equip", 2: "drop", 3: "back"} while True: old_item = self.get_equipped(category) print_slow("Currently equipped: {} \n".format(old_item)) print_slow("Selected item : {} \n".format(item)) print_options(options_map) answer = options_map[input_int()] if answer == "equip": self.equip(item, category, old_item) self.view_category(action, category) break elif answer == "drop": while True: print_slow("Are you sure you want to drop item? \n") print_slow("1. Yes \n" + "2. No \n") answer = input_int() if answer == 1: self.drop(item, category) self._options(item, category, action) elif answer == 2: self._options(item, category, action) break else: print_slow("Please choose a valid option") continue
def main_game_loop(hero): print(hero.name) game_levels = ("room", "boss", "room", "room", "boss", "end") for level in range(len(game_levels)): # cause everything is zero index LEVEL = level + 1 game_level = game_levels[level] print("You are at level {}: {}".format(LEVEL, game_level)) print_slow("What would you like to do?" + "\n") choice = base_choices() while choice != "explore": if choice == "inventory": hero.view_inventory() choice = base_choices() if choice == "quit": quit("Only cowards run from glory...") room(hero, LEVEL, game_level) hero.level_up() LEVEL += 1 # proceed to junction # handle room should not proceed if inventory option chosen if hero.health <= 0: break print("Well played! Game over...")
def battle_room_success(hero, enemy): level = LEVEL t5 = "You have cleared the level" + "\n" print_slow(t5, 0.02) print(" ") input("Press any key to continue...") hero.greed += 10 print("\n" + "Greed bonus has increased! You have higher chances of finding wealth...") monster_drop(enemy,hero) # done for coins and wealth hero.print_status()
def death(self): os.system("clear") print(" = = ==== = = === = === ===") print(" ===== = = = = = = = === = =") print(" = = = = = = = = = = =") print(" = ==== ==== === = === ===") print("") print(self.name + " the " + self.hero_class) print_slow("Your greed has lead to your downfall...", 0.05) print("\n" + "Wealth = " + str(self.wealth)) print("\n" + "Coins = " + str(self.coins))
def _get_hero_info(cls): # assigning the hero class based on user input print_slow("Choose from any of the below roles for today!\n") print_options(cls._hero_options) while True: char_class = cls._hero_options.get(input_int()) if char_class: break print("Please choose from the available roles!\n") return char_class
def room(hero, level, game_level): junction_map = {1: "battle room", 2: "trap room", 3: "aeon chamber"} if game_level == "room": room_choice = 0 print_slow("Which room would you to enter?\n") while room_choice not in junction_map.keys(): print_options(junction_map) choice = input_int() room_choice = junction_map.get(choice) if room_choice == "battle room": enemy = Monster.monster_spawn(level) print_slow("You encounter some dangerous looking" " {}\n".format(enemy.name)) battle_choices(hero, enemy) junction_map.pop(choice) break elif room_choice == "trap room": junction_map.pop(choice) print("Trap room coming soon...") continue # call trap room function elif room_choice == "aeon chamber": junction_map.pop(choice) print("Aeon Chamber coming soon...") # call Aeon chamber function continue else: print("Please choose a valid input...") if game_level == "boss": print_slow("You've entered the lair of a dangerous boss!") print_slow("Boss content coming soon...")
def view_category(self, action, category): self.print_inventory(category) # Need to better understand what the point of this # function is, the current implementation is still messy # Also, this should just be a function in the hero class # Since you're making a view of a hero attribute n_invent = self.get_n_inventory(category) + 1 while True: response = input_int() if response < n_invent: item = self.inventory[category][response - 1] clear_screen() self._options(item, category, action) break elif response == n_invent: clear_screen() self.view_inventory() break else: print_slow("Choose valid option") continue
def flee(hero, enemy): t6 = "Trying to escape the room..." print_slow(t6, 0.02) flee_roll = 50 + hero.agility if roll() < flee_roll: print("You successfully escape from the " + enemy.name) junction() else: print("You can't find a way out!") enemy_hit = roll() if enemy_hit < ( enemy.hit_chance - hero.defense ): # factors if the hit is successful based on hit chance and hero defense crit_enemy = enemy.crit_check( enemy ) # should have been a common function in parent class enemy_damage = int( random.randint( int(0.8 * enemy.damage), int((enemy.damage) * crit_enemy), ) ) print( "The " + enemy.name + " attack you for " + str(enemy_damage) + " damage" ) hero.hp -= enemy_damage hero.print_status() battle_choices(hero, enemy) if hero.hp <= 0: hero.death() else: print("You dodge an incoming attack" + "\n") battle_choices(hero, enemy)
def print_inventory(self, category): inventory = self.get_inventory(category) if not inventory: print_slow(" You currently have no items for this slot \n") return for i, item in enumerate(inventory, 1): print_slow("{} : {} \n".format(i, item)) print_slow("{} : Back".format(len(inventory) + 1))
def view_inventory(self): while True: clear_screen() print("Inventory:") print_options(self._inventory_options) action = input_int() if action == 1: print_slow("You have {} Coins in your purse\n".format( self.inventory["Coins"])) break elif action > 1 and action < 7: clear_screen() print_slow("You have chosen to see {} : {} \n".format( action, self._inventory_options.get(action))) self.view_category(action, self._inventory_options.get(action)) elif action == 7: clear_screen() break else: print_slow("Choose valid option") continue
def _get_player_name(cls): print_slow("What is your ancient name?\n") return input_str()
def drop(self, item, category): self.inventory.get(category).remove(item) print_slow("Dropped:", item)
def pick_up(self, item, category): # item is the return value from each individual loot (name) self.inventory.get(category).append(item) print_slow("Picked up:".format(item))
def battleroom(): t4 = "You enter a dim cave and hear something sinister stir in the shadows..." print_slow(t4, 0.02) enemy = (Monster.monster_spawn(level)) #stored the return value (class object) of the function in a new variale to be reused in fight function print("\n" + "You encounter some dangerous looking " + enemy.name) battle_choices(hero, enemy)