def load_game():
    response = prompt_usr("Select (N)ew game or (C)ontinue: \t",
                          "string").upper()
    if (response == "C"):
        try:
            hero = load("saveGame.txt")
            hero.stats()
            #print("File Loaded")
        except FileNotFoundError:
            print("SaveGame not found")
            create_character()
        #hero = Hero("bill", "warrior")
        return hero
    elif (response == "N"):
        hero = restart()
        print(
            "\nThree months ago, you set out from your village looking for glory and riches."
        )
        print(
            "After a long journey into the mountains, you came across a cave.")
        print("You hear horrible noises coming from inside.")
        response = prompt_usr("Do you want to (E)enter or (L)leave? \t",
                              "string").upper()
        if (response == "E"):
            return hero
        else:
            print("You Left")
            return
    else:
        print("Not an option, Sorry")
        print("Terminating")
def create_character():
    name = prompt_usr("Enter your hero's name: \t", "string")
    char_class = prompt_usr(
        "What class shall they be, a mighty (W)warrior or cunning (T)thief? \t",
        "string")
    hero = Hero(name, char_class)
    return hero
def choice():
    # prompt user
    print("\nThe room is now safe")
    response = ""
    while (not response == "E"):
        response = prompt_usr(
            "Do you want to (R)est to recover stamina and health, check your(S)status, open your (I)inventory, "
            +
            " \n(E)enter the next room, Enter the s(H)op, or save and (Q)uit the game. \t",
            "string").upper()
        # resting
        if (response == "R"):
            hero.rest()

        # status
        elif (response == "S"):
            hero.stats()

        # open inventory
        elif (response == "I"):
            hero.inventory.handleInventory(hero)

        #elif(response == "H"):
        #    g_store.enterStore(hero)

        # quit game
        elif (response == "Q"):
            #return False
            try:
                save(hero, r"save_game.txt")
                return False
            except FileNotFoundError:
                print("There was a problem Saving, file not found")
                return False
        return True
Example #4
0
 def examine(self):
     _id = prompt_usr(
         "Which item would you like to examine (Enter the item number): ",
         "number")
     # parse the number(and catch)
     try:
         examine_item(_id)
     except ValueError:
         print("You must enter a valid number")
Example #5
0
 def unequip(self, hero):
     _id = prompt_usr(
         "Which item would you like to unequip (Enter the item number): ",
         "number")
     # parse the number(and catch)
     try:
         self.unequip_item(_id, hero)
     except ValueError:
         print("You must enter a valid number")
def play_again():
    play = prompt_usr("Play Again? Y or N: \t", "string").upper()
    if play == "N":
        print("Fine")
        time.sleep(2)
        print("bye bye")
    elif play == "Y":
        #resart to play again
        return restart()
    else:
        print("!!!What!!!\n\n")
        time.sleep(2)
        print("Nah Forget it, bye")
Example #7
0
 def handleInventory(self, hero):
     response = ""
     while (not response == "C"):
         response = prompt_usr(
             "Choose One: (L)list your items, E(x)amine an item, (S)ell an Item, (E)quip an item,"
             + "\n (U)unequip an item, or (C)lose backpack) \t", "string")
         # list items
         if (response == "L"):
             list_items()
         elif (response == "X"):
             examine(input)
         elif (response == "S"):
             hero.gold += remove()
         elif (response == "E"):
             equip(input, hero)
         elif (response == "U"):
             unequip(input, hero)
def get_treasure(treasure):
    # build a list of items that dropped
    lootItems = []
    # number of basic items
    basic = treasure % 10
    # advanced items
    advanced = treasure / 10 % 10
    # epic items
    epic = treasure / 100 % 10
    # setup the basic items
    for i in range(basic):
        lootItems.append(loot.getBasic(hero))
    # setup the advanced items
    for i in range(advanced):
        lootItems.append(loot.getAdvanced(hero))
    # setup the epic items
    for i in range(epic):
        lootItems.append(loot.getEpic(hero))

    if (len(lootItems) > 0):
        # print a list of the items
        print()
        print("***************")
        print("Treasure Items")
        print("**************")
        for i in lootItems:
            print("{} {}\n".format(i.uniqueID, i.name))
        # ask the user whether they want to(S)ell items or (K)eep items
        valid_response = False
        response = ""
        while (not response == "S" and not response == "K"):
            response = prompt_usr(
                "Do you want to (S)ell or (K)eep the items (duplicates will be added to your current weapons): \t",
                "string")
        # sell
        if (response == "S"):
            for i in lootItems:
                hero.gold += i.price / 10
                print("You wisely sell the items")
    else:
        # put items in inventory(upgrade if duplicate)
        for i in lootItems:
            hero.gold += hero.inventory.append(i)
        print_case()
        print("You wisely put the items in your backpack.")
Example #9
0
    def fight_monster(self):
        monster_list = MonsterList()
        valid_monster = False
        while (not valid_monster):
            cur_monster = monster_list.get_monster()
            if (cur_monster.level <= self.level):
                valid_monster = True
        cur_monster.cur_health = cur_monster.health
        # copy the monsters health
        print("You come face to face with a {}".format(cur_monster.name))
        print(cur_monster.desc)
        print("The {} is poised, ready to attack!".format(cur_monster.name))
        if (self.level >= cur_monster.level):
            print("\n***********************")
            print("Good Monster: {}".format(cur_monster.name))
        else:
            print("\n***********************")
            print("Bad Monster: {}".format(cur_monster.name))

        print("player level: {}".format(self.level))
        print("Monster level: {}".format(cur_monster.level))
        print("***********************\n")
        # calculate potential treasure
        treasure = cur_monster.epic * 100 + cur_monster.advanced * 10 + cur_monster.basic

        # main fighting loop
        keep_fighting = True
        # should we keep fighting
        while (keep_fighting):
            # get their input
            valid_input = False
            response = ""
            while (not valid_input):
                print("\nMonster's HP: {}/{} \t Your HP: {}/{}".format(
                    cur_monster.cur_health, cur_monster.health, self.health,
                    self.max_health))
                response = prompt_usr(
                    "Do you want to (F)lee, make a (S)strong attack, or make a (W)eak attack? \t",
                    "string").upper()
                if (response == "F" or response == "S" or response == "W"):
                    # it is a valid response
                    valid_input = True
                else:
                    print("Invalid input!")
            # end valid_input while

            # generate an attack
            flee = cur_monster.singleAttack(self, response)
            # handles one attack
            # did the player flee?
            if (flee):
                print("\nYou manage to flee!\n")
                # no treasure
                return 0
            # did the player die?
            elif (self.health <= 0):
                # the player died
                print("\nYou have been slain by a {}".format(cur_monster.name))
                print("Total Gold: {}, Total Level {}".format(
                    self.gold, self.level))
                print("Better luck next time!\n")
                return -1
            # did the player win?
            elif (cur_monster.cur_health <= 0):
                print("\n*************************************")
                print("You vanquish the {}".format(cur_monster.name))
                print("Your Health: {}".format(self.health))

                # reward with food, gold and xp
                self.give_food(cur_monster.give_food())
                self.give_gold(cur_monster.give_gold())
                self.give_XP(cur_monster.xp)
                return cur_monster.get_treasure()
        #end keepFight while
        return -1