Exemple #1
0
 def load():#File and/or content should be decrypted.
     try:
         file = open("save.txt", "r")
         Player.name = file.readline().replace("\n", "")
         Player.gender = file.readline().replace("\n", "")
         Player.race = file.readline().replace("\n", "")
         Player.cclass = file.readline().replace("\n", "")
         Player.xp = file.readline().replace("\n", "")
         Player.xp = int(Player.xp)
         Player.strength = file.readline().replace("\n", "")
         Player.dexterity = file.readline().replace("\n", "")
         Player.intelligence = file.readline().replace("\n", "")
         Player.currentHealth = file.readline().replace("\n", "")
         Player.currentHealth = int(Player.currentHealth)
         Player.maxHealth = file.readline().replace("\n", "")
         Player.maxHealth = int(Player.maxHealth)
         Player.constitution = file.readline().replace("\n", "")
         Player.wisdom = file.readline().replace("\n", "")
         Player.charisma = file.readline().replace("\n", "")
         Player.isAlive = file.readline().replace("\n", "")
         if Player.isAlive == "True":
             Player.isAlive = True
         else:
             Player.isAlive = False
         Player.Inventory.rightArm = getattr(Player.Item, (file.readline().replace("\n", "")))
         Player.hasKey = file.readline().replace("\n", "")
         if Player.hasKey == "True":
             Player.hasKey = True
         else:
             Player.hasKey = False
         Player.isLocked = file.readline().replace("\n", "")
         if Player.isLocked == "True":
             Player.isLocked = True
         else:
             Player.isLocked = False
         Player.room = file.readline().replace("\n", "")
         Player.room = int(Player.room)
         Player.getModifier()
         file.close()
     except:
         print("\nThere is either no savefile or something went wrong! Please create a new character!")
Exemple #2
0
    def newCharacter():

        def getName():#Restrict to alpha-numeric?
            return input("Name: ")

        def getGender():
            while True:
                gender = input("Gender: (Male, Female) ")
                if gender == "Male" or gender == "m" or gender == "M":
                    return gender
                elif gender == "Female" or gender == "f" or gender == "F":
                    return gender
                else:
                    print("Please try again")

        def getRace():#More races to come; Races should have influence in some way.
            while True:
                race = input("Race: (Human, Elf, Half-Elf) ")
                if race == "Human":
                    return race
                elif race == "Elf":
                    return race
                elif race == "Half-Elf":
                    return race
                else:
                    print("Please try again")

        def getCclass():#Same as race.
            while True:
                cclass = input("Class: (Warrior, Ranger, Mage) ")
                if cclass == "Warrior":
                    Player.Inventory.rightArm = Player.Item.Sword
                    Player.AM = 6
                    return cclass
                elif cclass == "Ranger":
                    Player.Inventory.rightArm = Player.Item.Bow
                    Player.AM = 4
                    return cclass
                elif cclass == "Mage":
                    Player.Inventory.rightArm = Player.Item.Staff
                    Player.AM = 2
                    return cclass
                else:
                    print("Please try again")

        def rollStats():#Thinking about letting the player edit stats.
            accepted = False
            while accepted == False:
                strength = random.randrange(8,19)
                dexterity = random.randrange(8,19)
                constitution = random.randrange(8,19)
                intelligence = random.randrange(8,19)
                wisdom = random.randrange(8,19)
                charisma = random.randrange(8,19)
                print("\nStrength:", strength)
                print("Dexterity:", dexterity)
                print("Constitution:", constitution)
                print("Intelligence:", intelligence)
                print("Wisdom:", wisdom)
                print("Charisma:", charisma)
                answer = input("\nDo you want to keep this Abilities? (y/n) ")
                if answer == "y":
                    Player.strength = strength
                    Player.dexterity = dexterity
                    Player.constitution = constitution
                    Player.intelligence = intelligence
                    Player.wisdom = wisdom
                    Player.charisma = charisma
                    Player.maxHealth = constitution * 2
                    Player.currentHealth = Player.maxHealth
                    accepted = True
                elif answer == "n":
                    continue

        Player.name = getName()
        Player.gender = getGender()
        Player.race = getRace()
        Player.cclass = getCclass()
        Player.xp = "0"
        rollStats()
        Player.isAlive = True
        Player.hasKey = False
        Player.isLocked = False
        Player.room = 0
        Player.getModifier()