Gladiators of Teldrin: Text Based Gladiatorial Combat RPG (In early stages, playable)

Started by
9 comments, last by Scouting Ninja 7 years, 1 month ago

Hello GameDev.net. I, after working off and on for a while and several restarts, spent a weekend a couple of weeks ago actually successfully making something that I can personally be proud of. It is a text-based gladiator RPG where you climb the ladder. I plan to use my pseudo-engine in later projects. At the moment, I have a small game that I plan to expand on uploaded to Github at this link:

https://github.com/sckaledoom/My-Games/blob/master/Gladiators%20of%20Teldrin%20v0.5.7z

I wanted to post this here to get some feedback on what I've already got done, any feedback is greatly appreciated. To play, just unzip the contents, install Python 2.7, open cmd and type the following:

cd\

C:\python27\python.exe C:\%PATH%/"Gladiators of Teldrin v0.5"/"Gladiators of Teldrin.py"

Hope you enjoy!

Advertisement

My first thought is: the code is kind of hard to follow.

I don't remember much Python but one thing I quickly noticed with your game is that you basically have a giant switch statement for fights and set the "enemy stats" manually for each switch. Although this works it is rather redundant and hard to follow. An alternative you could do is use classes and make an object for each enemy(either set in code or from a file) and then have much shorter/simpler code for the fight part, since you wouldn't have that massive blob of stat setting repeated over and over again.

Another suggestion would be to split up the combat function more, usually more functions is easier to follow than less because function naming helps to separate out what each section of the code is doing, that can be useful even if the code isn't repeated.

You could also look into using multiple files, if I remember right python lets you import functions from different files so everything isn't in one giant blob of a file.

But it's not bad.

You could also look into using multiple files, if I remember right python lets you import functions from different files so everything isn't in one giant blob of a file.

Yeah, I tried doing that with my functions, but it kept giving me errors that it was harder to fix than it would be to just have that code there.

Another suggestion would be to split up the combat function more, usually more functions is easier to follow than less because function naming helps to separate out what each section of the code is doing, that can be useful even if the code isn't repeated.

Also tried this, but I couldn't find a good place to cut off the combat code that didn't cause some bug in the way it worked.

An alternative you could do is use classes and make an object for each enemy(either set in code or from a file) and then have much shorter/simpler code for the fight part, since you wouldn't have that massive blob of stat setting repeated over and over again.

TBH, I went in with a small amount of prior knowledge, and learned as I went along. Didn't even realize Python had classes that could be easily set. My fault for not thinking, it is C-based after all.

Thanks for the advice, will definitely take it into account while working on the next build.

cd\ C:\python27\python.exe C:\%PATH%/"Gladiators of Teldrin v0.5"/"Gladiators of Teldrin.py"

Go to https://repl.it/ search python (not python3) and paste the code.

[Spoiler]


from sys import argv
import random
print "Welcome to Gladiators of Teldrin"
print "(S)tart"
print "(C)lose"
def ShowStats():
    print "Would you like to see your stats? (y/n)"
    stats= raw_input()
    if stats == "y":
            print "HP =" + str(maxHP)
            print "mana =" + str(maxmana)
            print "Endurance =" + str(End)
            print "Strength =" + str(Str)
            print "Dexterity =" + str(Dex)
            print "Intellect =" + str(Intellect)
def UndoSpells():
    global waActive
    global saActive
    global enemywaActive
    global enemysaActive
    global sdActive
    global enemysdActive
    global enemydmgMod
    global dmgMod
    dmgMod = 0
    enemydmgMod = 0
    sdActive = 0
    enemysdActive = 0
    waActive = 0
    saActive = 0
    enemywaActive = 0
    enemysaActive = 0
    HP = maxHP
    mana = maxmana
    damage = 0
def Combat():
        global end
        global fight
        global enemydmgMod
        global EnemyHP
        global enemyMana
        global critChance
        global damage
        global HP
        global mana
        global dmgMod
        global sdActive
        global enemysdActive
        global waActive
        global saActive
        global AC
        global enemyStr
        global enemyDex
        global enemyTHAC0
        global enemyAC
        global maxHP
        end = 0
        print "HP= " +str(HP)
        print "Mana= " +str(mana)
        print "Do you:"
        print "(A)ttack"
        print "(B)lock"
        print "(C)ast"
        print "(R)un away"
        totalDamage = 0
        action = raw_input()
        if action == "r":
            print "You have run away, forfeiting the match and angering your trainers. Still, the punishment you will recieve will be far less than what you would see in the aferlife"
            fight +=1
            enemydamage = 0
            damage = 0
        elif action == "a":
            toHit = THAC0 - (random.randint(1,20) + int(Dex/5))
            critical = random.randint(1,100)
            if critical == critChance:
                dmgMod = 3
            if sdActive == 1:
                if toHit <= enemyAC:
                    damage = (random.randint(2,16) + int(Str/5) * enemydmgMod) * int(Dex/5)
                    print "You hit for " + str(damage) + " HP!"
                    enemydmgMod = 1
                    sdActive = 0
                    saActive = 0
                    waActive = 0
                else:
                    print "Even with the magic in your sword arm, you missed!"
                    damage = 0
            else:
                if toHit <= enemyAC:
                    damage = (int(Str/5) + random.randint(1,8) * enemydmgMod) * int(Dex/5)
                    enemydmgMod = 1
                    print "You hit for " + str(damage) + " HP!"
                else:
                    print "You missed!"
                    damage = 0
                    enemydmgMod = 1
        elif action == "b":
            dmgMod = dmgMod * .5
            damage = 0
            print "You are blocking"
        elif action == "c":
            print "Which spell?"
            print "(M)agic Bullet"
            print "(S)word Dance"
            print "(W)eaken Armor"
            print "S(u)nder Weapons"
            spell = raw_input()
            if mana > 0:
                if spell == "m":
                    damage = random.randint(2,5) * Intellect
                    print "The magical weapon soars through the air and slams into your enemy for " + str(damage) + " HP!"
                    mana = mana-1
                    waActive = 0
                    saActive = 0
                elif spell == "s":
                    sdActive = 1
                    print "You feel the magical energies suffuse your blades and sword arm."
                    mana = mana-1
                    damage = 0
                    saActive = 0
                    waActive = 0
                elif spell == "w":
                    waActive = 1
                    saActive = 0
                    if waActive == 1:
                        enemydmgMod = enemydmgMod * 3
                    damage = 0
                    print "You have weakened your enemy's armor for a round."
                    mana = mana -1
                elif spell == "u":
                    waActive = 0
                    saActive = 1
                    if saActive == 1:
                        dmgMod = dmgMod * .3
                    print "You have sundered your enemy's weapons"
                    damage = 0
            else:
                print "You don't have any mana"
        EnemyHP = EnemyHP - damage
        if EnemyHP <= 0:
            fight += 1
            HP = maxHP
            mana = maxmana
            print "The enemy falls to the ground. Your sword point hovers above his throat. You look up at the master of the arena. He hold his thumb down. Everyone cheers as you slide the sword point into his throat."
            print "You go back to the barracks, the thrill from your fight still coursing through your veins."
            IncreaseXP()
            Levelup()
            print "You are awakened by the sound of your trainer's voice telling you to go to the chariot"
            enemysdActive = 0
        elif enemyMana > 0:
            enemyChoice = random.randint (1,3)
            if enemyChoice == 1:
                toHit =enemyTHAC0 - (random.randint (1,20) + int(enemyDex/5))
                if enemysdActive == 1:
                    if toHit <= AC:
                        damage = (int(enemyStr/5) + random.randint(2,16) * dmgMod) * int(enemyDex/5)
                        print "He hits you for " + str(damage) + " HP!"
                        dmgMod = 1
                        enemysdActive = 0
                        enemywaActive = 0
                        enemysaActive = 0
                    else:
                        print "Even with the magic in his sword arm, he missed!"
                        damage = 0
                        dmgMod = 1
                else:
                    if toHit >= 10:
                        damage = (int(enemyStr/5) + random.randint(1,8) * dmgMod) * int(enemyDex/5)
                        enemysaActive = 0 
                        enemywaActive = 0
                        print "He hits you for " + str(damage) + " HP!"
                    else:
                        print "He missed!"
                        damage = 0
                        enemysaActive = 0
                        enemywaActive = 0
            elif enemyChoice == 2:
                enemydmgMod = enemydmgMod * .5
                damage = 0
                enemysaActive = 0
                enemywaActive = 0
                print "He blocks!"
            elif enemyChoice == 3:
                spell = random.randint (1,4)
                if spell == 1:
                    damage = (random.randint (2,5)) * enemyIntellect
                    enemyMana = enemyMana - 1
                    enemysaActive = 0
                    enemywaActive = 0
                    print "He fires a Magic Bullet and it arcs through the air to hit you, dealing " + str(damage) + " HP in damage"
                elif spell == 2:
                    enemysdActive = 1
                    print "Magic suffuses the enemy's sword and arm."
                    enemysaActive = 0
                    enemywaActive = 0
                    damage = 0
                    enemyMana = enemyMana -1
                elif spell == 3:
                    enemywaActive = 1
                    if enemywaActive == 1:
                        dmgMod = dmgMod * 3
                    print "The opponent weakens your armor"
                    damage = 0
                    enemysaActive = 0
                    enemyMana = enemyMana - 1
                elif spell == 4:
                    enemysaActive = 1
                    enemywaActive = 0
                    if enemysaActive == 1:
                        enemydmgMod = enemydmgMod * .3
                    damage = 0
                    print "Your sword is sundered"
                    enemyMana = enemyMana -1
        else:
            enemyChoice = random.randint (1,3)
            if enemyChoice == 1 or 2:
                toHit = random.randint (1,20)
                if enemysdActive == 1:
                    if toHit >= 5:
                        damage = (int(enemyStr/5) + random.randint(2,16) * dmgMod) * (enemyDex/5)
                        print "He hits you for " + str(damage) + " HP!"
                        enemysdActive = 0
                        enemysaActive = 0
                        enemywaActive = 0
                    else:
                        print "Even with the magic in his sword arm, he missed!"
                        damage = 0
                        enemysdActive = 0
                        enemysaActive = 0
                        enemywaActive = 0
                else:
                    if toHit >= 10:
                        damage = (int(enemyStr/5) + random.randint(1,8) * dmgMod) * int(enemyDex/5)
                        enemysaActive = 0
                        enemywaActive = 0
                        print "He hits you for " + str(damage) + " HP!"
                    else:
                        print "He missed!"
                        damage = 0
                        enemysaActive = 0
                        enemywaActive = 0
            elif enemyChoice == 2:
                enemydmgMod = enemydmgMod * .5
                print "He blocks!"
                enemysaActive = 0
                enemywaActive = 0
                damage = 0
        HP = HP - int(damage)
        totalDamage = totalDamage + damage
        if HP<=0:
            print "Some are lucky enough to fight in the arena long enough to earn their freedom... Onlookers realize as you bleed out that you are not one."
            end = 1
        if end == 1:
            print "You have failed."
            exit()
            
def IncreaseXP():
    global XP
    global enemyXP
    XP = XP + enemyXP
    print "You gained " + str(enemyXP) + " XP"
def Levelup():
    global maxHP
    global THAC0
    global maxmana
    global critChance
    global Nextlvl
    global Str
    global Dex
    global End
    global Intellect
    if XP >=Nextlvl:
        Nextlvl *=1.5
        print "You levelled up!"
        print "Your health increased"
        print "Your chance to hit went up!"
        strRoll = random.randint(1,100)
        endRoll = random.randint(1,100)
        dexRoll = random.randint(1,100)
        if strRoll <= 50:
            print "Your strength increased by 1"
            Str +=1
        if endRoll <= 50:
            print "Your endurance went up by 1"
            End +=1
        if dexRoll <= 50:
            print "Your dexterity increased by 1"
            Dex +=1
        if int(PCclass) == 1:
            maxHP = maxHP + random.randint(1,10) + int(End/5)
            THAC0 = THAC0 - 2
        elif int(PCclass) == 2:
            print "Your mana increased"
            IntRoll = random.randint(1,100)
            if IntRoll <= 50:
                print "Your intellect increased."
                Intellect +=1
            maxHP = maxHP +random.randint(1,4) + int(End/5)
            maxmana = maxmana + random.randint(1,3)
            THAC0 = THAC0 - .25
        elif int(PCclass) == 3:
            maxHP += random.randint(1,6) + int(End/5)
            THAC0 += - .5
        elif int(PCclass) == 4:
            print "Your mana increased"      
            IntRoll = random.randint(1,100)
            if IntRoll <= 33:
                print "Your intellect increased."
                Intellect +=1
            maxHP = maxHP + random.randint (1,8) + int(End/5)
            maxmana = maxmana + 1
            THAC0 = THAC0 - 1
        HP = maxHP
        print "HP = " + str(maxHP)
        print "Mana = " + str(maxmana)
        print "Strength = " + str(Str)
        print "Endurance = " + str(End)
        print "Dexterity = " + str(Dex)
        print "Intellect = " + str(Intellect)
response=raw_input()
if response == "s":
    print "Create your character"
    print "Choose a class:"
    print "1) Fighter"
    print "2) Mage"
    print "3) Rogue"
    print "4) Gladiator"
    PCclass=raw_input()
    if int(PCclass) == 1:
        End = 14
        maxHP = 50 + int(End/5)
        Str = 15
        Dex = 10
        critChance = 5
        AC = 3
        maxmana = 0
        THAC0 = 17
        XP = 0
        Intellect = 1
        Nextlvl = 1000
    if int(PCclass) == 2:
        End = 10
        maxHP = 20 + int(End/5)
        Str = 5
        Dex = 5
        maxmana = 25
        THAC0 = 20
        Intellect = 2
        AC = 10
        critChance = 0
        XP = 0
        Nextlvl = 500
    if int(PCclass) == 3:
        Str = 10
        Dex = 15
        End = 13
        AC = 5
        Intellect = 1
        critChance = 15
        maxHP = 45 + int(End/5)
        maxmana = 0
        THAC0 = 19
        XP = 0
        Nextlvl = 500
    if int(PCclass) == 4:
        Str = 15
        Dex = 8
        End = 15
        maxHP = 35 + int(End/5)
        critChance = 2
        maxmana = 2
        AC = 4
        THAC0 = 18
        Intellect = 1
        XP = 0
        Nextlvl = 750
    print "You are a gladiator in a massive arena, a participant in a bloody spectacle for millions to see."
    print "You are facing your first enemy, also a novice in the art of combat."
    HP = maxHP
    mana = maxmana
    EnemyHP = 35
    enemyMana = 2
    fight = 0
    enemydmgMod = 1
    dmgMod = 1
    sdActive = 0
    enemysdActive = 0
    enemyDex = 7
    enemyStr = 15
    enemyAC = 6
    enemyTHAC0 = 18
    enemyXP = 500
    ShowStats()
    enemyIntellect = 1
    mana = maxmana
    while fight==0:
        Combat()
    EnemyHP = 57
    enemyStr = 13
    enemyDex = 19
    enemyTHAC0 = 17
    enemyMana = 0
    enemyAC = 7
    enemyIntellect = 1
    enemyXP = 1000
    UndoSpells()
    ShowStats()
    HP = maxHP
    mana = maxmana
    print "You are told that your next opponent is to be Galsin the Lightning Step, an exceptionally fast person who it is told that he can attack three times in the amount of time that most people can only hit once or twice."
    while fight == 1:
        Combat()
    EnemyHP = 40
    enemyStr = 9
    enemyDex = 10
    enemyTHAC0 = 19
    enemyMana = 30
    enemyAC = 8
    enemyIntellect = 2
    enemyXP = 1050
    UndoSpells()
    ShowStats()
    HP = maxHP
    mana = maxmana
    print "Your master leans in and says, \"You are skilled. That is why I trust you with the next fight. Your next opponent is a great mage named Haros. He is powerful and experienced. \" He gives you a comforting pat on the shoulder, \"I believe that you have this fight, though.\" "
    while fight == 2:
        Combat()
    EnemyHP = 75
    enemyIntellect = 1
    enemyMana = 0
    enemyStr = 25
    enemyDex = 14
    enemyTHAC0 = 15
    enemyAC = 3
    enemyXP = 2000
    UndoSpells()
    ShowStats()
    mana = maxmana
    HP = maxHP
    print "The other gladiators performing today look at you as one would look at a fresh corpse. One of them tells you that your next opponent, and likely last, is the brute Garmesh the Giant. With strength superhuman, and speed to back it up, he has smashed all of the previous opponents he had fought. He is favored to win seventeen to one.Your task this day is to prove them wrong."
    while fight == 3:
        Combat()
    EnemyHP = 90
    enemyIntellect = 2
    enemyMana = 10
    enemyStr = 19
    enemyDex = 16
    enemyTHAC0 = 16
    enemyAC = 4
    enemyXP = 1500
    UndoSpells()
    ShowStats()
    mana = maxmana
    HP = maxHP
    print "Your master leans in and says, \"That victory against Garmesh has caught wind and made our school famous. Now, you are recieving a large amount of requests. I did accept this one, because it seems like it shouldn't be TOO hard\" He smiles a crinkled, though genuine smile."
    while fight == 4:
        Combat()
    EnemyHP = 100
    enemyIntellect = 1
    enemyMana = 0
    enemyStr = 15
    enemyDex = 25
    enemyTHAC0 = 15
    enemyAC = 4
    enemyXP = 1750
    mana = maxmana
    UndoSpells()
    ShowStats()
    HP = maxHP
    print "\"This next fight is against Faren the Rogue. He is superhumanly fast, and has a normal person's strength. In fact, he makes Galen look slow. He will be exceptionally difficult.\""
    while fight == 5:
        Combat()
    EnemyHP = 95
    enemyIntellect = 6
    enemyMana = 27
    enemyStr = 10
    enemyDex = 13
    enemyTHAC0 = 17
    enemyAC = 5
    enemyXP = 2500
    mana = maxmana
    HP = maxHP
    UndoSpells()
    ShowStats()
    print "Your next opponent is a man from far to the West whose name is Daleshin the Genius. He is smarter than most people could ever hope to be and even a large portion of mages look at him as a genius. Unlike most magi, he hasn't given up physical ability in return for this."
    while fight == 6:
        Combat()
    print "Goodbye"

[/spoiler]

Most of us have a Python installed and don't want to install a new one. If you plan on making more of these you can share it using that site.
Not a bad game, although it took me a bit of time to get to terms with it.
The only complaint I have is that I am blind, and not because of the graphics. I enter the arena and I know my own condition, I know there is some one there; do I Attack, Block or Run?
The thing is I can't make a educated choice, because I don't know what is happening.
It was only a few steps into battle that I was able to form a understanding of events.
A good idea would be to describe the enemy entering the arena: "A gigantic Minotaur enters the Arena, basking in the cheers from the crowd." Then following it with commands related to what the player read.
Do you attack while the Minotaur is distracted by the crowd?, Do you take this chance to hide behind a broken pillar or do you flee for your live before the monster notices you?
It's the same Attack,Block and Run format. The player now just has a visual and audio idea of what is happening.
Thanks Scouting Ninja. I was planning to implement this at a later point, especially for the endgame enemies and to a lesser extent with the earlier ones, because I sort of wanted it to escalate from facing noobish sorts into facing godlike figures. I do definitely see what you're saying, though.

An alternative you could do is use classes and make an object for each enemy(either set in code or from a file) and then have much shorter/simpler code for the fight part, since you wouldn't have that massive blob of stat setting repeated over and over again.

I don't get what I'm doing wrong here.

Here's the code:

[spoiler]


from sys import argv
import random
import Enemy1
from Enemy1 import Novice
print "Welcome to Gladiators of Teldrin"
print "(S)tart"
print "(C)lose"
def ShowStats():
    print "Would you like to see your stats? (y/n)"
    stats= raw_input()
    if stats == "y":
            print "HP =" + str(maxHP)
            print "mana =" + str(maxmana)
            print "Endurance =" + str(End)
            print "Strength =" + str(Str)
            print "Dexterity =" + str(Dex)
            print "Intellect =" + str(Intellect)
            

def UndoSpells():
    global waActive
    global saActive
    global enemywaActive
    global enemysaActive
    global sdActive
    global enemysdActive
    global enemydmgMod
    global dmgMod
    dmgMod = 0
    enemydmgMod = 0
    sdActive = 0
    enemysdActive = 0
    waActive = 0
    saActive = 0
    enemywaActive = 0
    enemysaActive = 0
    HP = maxHP
    mana = maxmana
    damage = 0
def Combat(enemy):
        global end
        global fight
        global enemydmgMod
        global EnemyHP
        global enemyMana
        global critChance
        global damage
        global HP
        global mana
        global dmgMod
        global sdActive
        global enemysdActive
        global waActive
        global saActive
        global AC
        global enemyStr
        global enemyDex
        global enemyTHAC0
        global enemyAC
        global maxHP
        end = 0
        print "HP= " +str(HP)
        print "Mana= " +str(mana)
        print "Do you:"
        print "(A)ttack"
        print "(B)lock"
        print "(C)ast"
        print "(R)un away"
        totalDamage = 0
        action = raw_input()
        if action == "r":
            print "You have run away, forfeiting the match and angering your trainers. Still, the punishment you will recieve will be far less than what you would see in the aferlife"
            fight +=1
            enemydamage = 0
            damage = 0
        elif action == "a":
            toHit = THAC0 - (random.randint(1,20) + int(Dex/5))
            critical = random.randint(1,100)
            if critical == critChance:
                dmgMod = 3
            if sdActive == 1:
                if toHit <= enemyAC:
                    damage = (random.randint(2,16) + int(Str/5) * enemydmgMod) * int(Dex/5)
                    print "You hit for " + str(damage) + " HP!"
                    enemydmgMod = 1
                    sdActive = 0
                    saActive = 0
                    waActive = 0
                else:
                    print "Even with the magic in your sword arm, you missed!"
                    damage = 0
            else:
                if toHit <= enemyAC:
                    damage = (int(Str/5) + random.randint(1,8) * enemydmgMod) * int(Dex/5)
                    enemydmgMod = 1
                    print "You hit for " + str(damage) + " HP!"
                else:
                    print "You missed!"
                    damage = 0
                    enemydmgMod = 1
        elif action == "b":
            dmgMod = dmgMod * .5
            damage = 0
            print "You are blocking"
        elif action == "c":
            print "Which spell?"
            print "(M)agic Bullet"
            print "(S)word Dance"
            print "(W)eaken Armor"
            print "S(u)nder Weapons"
            spell = raw_input()
            if mana > 0:
                if spell == "m":
                    damage = random.randint(2,5) * Intellect
                    print "The magical weapon soars through the air and slams into your enemy for " + str(damage) + " HP!"
                    mana = mana-1
                    waActive = 0
                    saActive = 0
                elif spell == "s":
                    sdActive = 1
                    print "You feel the magical energies suffuse your blades and sword arm."
                    mana = mana-1
                    damage = 0
                    saActive = 0
                    waActive = 0
                elif spell == "w":
                    waActive = 1
                    saActive = 0
                    if waActive == 1:
                        enemydmgMod = enemydmgMod * 3
                    damage = 0
                    print "You have weakened your enemy's armor for a round."
                    mana = mana -1
                elif spell == "u":
                    waActive = 0
                    saActive = 1
                    if saActive == 1:
                        dmgMod = dmgMod * .3
                    print "You have sundered your enemy's weapons"
                    damage = 0
            else:
                print "You don't have any mana"
        EnemyHP = EnemyHP - damage
        if EnemyHP <= 0:
            fight += 1
            HP = maxHP
            mana = maxmana
            print "The enemy falls to the ground. Your sword point hovers above his throat. You look up at the master of the arena. He hold his thumb down. Everyone cheers as you slide the sword point into his throat."
            print "You go back to the barracks, the thrill from your fight still coursing through your veins."
            IncreaseXP()
            Levelup()
            print "You are awakened by the sound of your trainer's voice telling you to go to the chariot"
            enemysdActive = 0
        elif enemyMana > 0:
            enemyChoice = random.randint (1,3)
            if enemyChoice == 1:
                toHit =enemyTHAC0 - (random.randint (1,20) + int(enemyDex/5))
                if enemysdActive == 1:
                    if toHit <= AC:
                        damage = (int(enemyStr/5) + random.randint(2,16) * dmgMod) * int(enemyDex/5)
                        print "He hits you for " + str(damage) + " HP!"
                        dmgMod = 1
                        enemysdActive = 0
                        enemywaActive = 0
                        enemysaActive = 0
                    else:
                        print "Even with the magic in his sword arm, he missed!"
                        damage = 0
                        dmgMod = 1
                else:
                    if toHit >= 10:
                        damage = (int(enemyStr/5) + random.randint(1,8) * dmgMod) * int(enemyDex/5)
                        enemysaActive = 0 
                        enemywaActive = 0
                        print "He hits you for " + str(damage) + " HP!"
                    else:
                        print "He missed!"
                        damage = 0
                        enemysaActive = 0
                        enemywaActive = 0
            elif enemyChoice == 2:
                enemydmgMod = enemydmgMod * .5
                damage = 0
                enemysaActive = 0
                enemywaActive = 0
                print "He blocks!"
            elif enemyChoice == 3:
                spell = random.randint (1,4)
                if spell == 1:
                    damage = (random.randint (2,5)) * enemyIntellect
                    enemyMana = enemyMana - 1
                    enemysaActive = 0
                    enemywaActive = 0
                    print "He fires a Magic Bullet and it arcs through the air to hit you, dealing " + str(damage) + " HP in damage"
                elif spell == 2:
                    enemysdActive = 1
                    print "Magic suffuses the enemy's sword and arm."
                    enemysaActive = 0
                    enemywaActive = 0
                    damage = 0
                    enemyMana = enemyMana -1
                elif spell == 3:
                    enemywaActive = 1
                    if enemywaActive == 1:
                        dmgMod = dmgMod * 3
                    print "The opponent weakens your armor"
                    damage = 0
                    enemysaActive = 0
                    enemyMana = enemyMana - 1
                elif spell == 4:
                    enemysaActive = 1
                    enemywaActive = 0
                    if enemysaActive == 1:
                        enemydmgMod = enemydmgMod * .3
                    damage = 0
                    print "Your sword is sundered"
                    enemyMana = enemyMana -1
        else:
            enemyChoice = random.randint (1,3)
            if enemyChoice == 1 or 2:
                toHit = random.randint (1,20)
                if enemysdActive == 1:
                    if toHit >= 5:
                        damage = (int(enemyStr/5) + random.randint(2,16) * dmgMod) * (enemyDex/5)
                        print "He hits you for " + str(damage) + " HP!"
                        enemysdActive = 0
                        enemysaActive = 0
                        enemywaActive = 0
                    else:
                        print "Even with the magic in his sword arm, he missed!"
                        damage = 0
                        enemysdActive = 0
                        enemysaActive = 0
                        enemywaActive = 0
                else:
                    if toHit >= 10:
                        damage = (int(enemyStr/5) + random.randint(1,8) * dmgMod) * int(enemyDex/5)
                        enemysaActive = 0
                        enemywaActive = 0
                        print "He hits you for " + str(damage) + " HP!"
                    else:
                        print "He missed!"
                        damage = 0
                        enemysaActive = 0
                        enemywaActive = 0
            elif enemyChoice == 2:
                enemydmgMod = enemydmgMod * .5
                print "He blocks!"
                enemysaActive = 0
                enemywaActive = 0
                damage = 0
        HP = HP - int(damage)
        totalDamage = totalDamage + damage
        if HP<=0:
            print "Some are lucky enough to fight in the arena long enough to earn their freedom... Onlookers realize as you bleed out that you are not one."
            end = 1
        if end == 1:
            print "You have failed."
            exit()
... (Some stuff that's not necessary)

    HP = maxHP
    mana = maxmana
    Novice
    ShowStats()
    mana = maxmana
    UndoSpells()
    fight = 0
    while fight==0:
        Combat(Novice)

[/spoiler]

And here's where I define the class enemy and the object Novice (in Enemy1.py) :

[spoiler]


class Enemy:
    global EnemyHP 
    global enemyMana
    global fight
    global enemydmgMod
    global dmgMod
    global sdActive
    global enemysdActive
    global enemyDex
    global enemyStr
    global enemyAC
    global enemyTHAC0
    global enemyXP
    global enemyIntellect
Novice = Enemy()
Novice.EnemyHP = 35
Novice.enemyIntellect = 1
Novice.enemyMana = 2
Novice.fight = 0
Novice.enemydmgMod = 1
Novice.dmgMod = 1
Novice.sdActive = 0
Novice.enemysdActive = 0
Novice.enemyDex = 7
Novice.enemyStr = 15
Novice.enemyAC = 6
Novice.enemyTHAC0 = 18
Novice.enemyXP = 500

[/spoiler]

I think you missed the point of classes, they allow local values for each instance; making it easy to reuse preset variables.

[spoiler]


class Minotaur:
    def __init__(self): #don't use globals, the idea is that every instance of the class has it's own variables
        self.HPMax = 100
        self.Atk   = 10
        self.Def   = 4
 
        self.intro = "A gigantic Minotaur enters the Arena, basking in the cheers from the crowd"
 
    def getMinotaurAtk(self):
        return self.Atk
    
    def setMinotaurAtk(self,value):
        self.Atk = value
 
#Here we use the class 
EnemyA = Minotaur()
EnemyB = Minotaur() #Enemy A and B are not the same thing, each is a instance of the class.
print(EnemyA.getMinotaurAtk()) #one way to get value
print(EnemyA.Atk) #easy way to get the value
print("*"*10)
EnemyA.setMinotaurAtk(100) #one way to set the local value
EnemyB.Atk = 5 #easy way to set local value
print(EnemyA.Atk)
print(EnemyB.Atk) #See 2 enemies

[/spoiler]

This is Python3, there is some differences, for example I use print("text") and not print "text".

Everything you need can be found in the python documentation that is installed with every python. It should be in the same folder where python is, or just search your PC. There is a tutorial in the documents.

Also https://www.codecademy.com/learn/python is a good online course for learning python.

But what if I wanted the stats to be imported from a separate file (Enemy1.py) into the main module? It doesn't seem to find the stats unless I make them global

Edit: Nevermind, figured it out. Had to create a function in the main module to call the stats and replace the main module version with them. Thanks for that example by the way. It really helped in figuring out how to use them and how to fix the problem.

Edit: Nevermind, figured it out. Had to create a function in the main module to call the stats and replace the main module version with them. Thanks for that example by the way. It really helped in figuring out how to use them and how to fix the problem.

It's good to know you found a fix, looks different from how I would have done it.

But what if I wanted the stats to be imported from a separate file (Enemy1.py) into the main module? It doesn't seem to find the stats unless I make them global

Just want to point this out:

My first file was called: FileWithClass.py


#File loading example
class Character:
    def __init__(self, name):
        self.Name  = name
        self.HpMax = 100
        self.Def   = 10
        self.Atk   = 8
 
    def DoThing(self):
        print(self.Name)

import FileWithClass
 
FWC = FileWithClass #We can make a pointer if we will be using it a lot.
NewThing  = FileWithClass.Character("Bob")
NewThingB = FWC.Character("NotBob")
NewThing.DoThing()

[spoiler]


def damage(w):
    w.damage= int(damage)
    return 
...
                if toHit <= enemyAC:
                    damage(w)

[/spoiler]

[spoiler]


import random
class Weapon:
    damage = 0
    ACmod = 0
class Potion:
    effect = 0
    descr= ''

Staff = Weapon()
Staff.damage = random.randint(2,4)
Staff.ACmod = 2

Shortsword = Weapon()
Shortsword.damage = random.randint(1,6)
Shortsword.ACmod = -1

Longsword = Weapon()
Longsword.damage = random.randint(1,8)
Longsword.ACmod = - 1 

Dagger = Weapon()
Dagger.damage = random.randint(1,4)
Dagger.ACmod = 1

Club = Weapon()
Club.damage = random.randint(1,5)
Club.ACmod = 2

[/spoiler]

I have it set the value of w to one of the weapons, but it gives me a TypeError that I can't subtract EnemyHP and damage because damage is a function. Why does it give me this? I tried specifying that damage should be an integer, but it then tells me that a integer can't be called. Any help is appreciated greatly.

This topic is closed to new replies.

Advertisement