Hi guys, I'm making an RPG(role-playing game) and I need some help. Here is the code so far:

class Create:
    def __init__(self, power, attack, defense):
        self.power = power
        self.attack = attack
        self.defense = defense
warrior = Create(300, 50, 150)
wizard = Create(500, 100, 230)

characters = [
    "warrior",
    "wizard"
]
waweapons = [
    'sword',
    'crossbow',
    'knife'
]
wiweapons = [
    'wand',
    'staff',
    'fire'
]
sword = Create('', 60, '')
crossbow = Create('', 30, '')
knife = Create('', 20, '')
wand = Create('', 50, '')
staff = Create('', 40, '')
fire = Create('', 80, '')
experience = 0

print "Enter in a character"
print "The characters are:"
print "\tWarrior"
print "\tWizard"
print "Warrior info:"
print "\tPower: %s" % warrior.power
print "\tAttack: %s" % warrior.attack
print "\tDefense: %s" % warrior.defense
print "\tAttacks: sword, crossbow, knife"
print
print "Wizard info:"
print "\tPower: %s" % wizard.power
print "\tAttack: %s" % wizard.attack
print "\tDefense: %s" % wizard.defense
print "\tAttacks: wand, staff, fire"
character = raw_input()
while character not in characters:
    print "No character found."
    character = raw_input()
if character.lower().startswith('warrior'):
    print "You are a warrior."
if character.lower().startswith('wizard'):
    print "You are a wizard."

Orc = Create(20, 75, 0)
Troll = Create(500, 100, 500)
Dog = Create(20, 20, 20)


print "The people of Fanlack lived peacefully"
print "But then, one day the evil ruler of Tardsat decided to conquer Fanlack"
print "The evil ruler Rugak succeeded,"
print "But in the mist a hero arised."
print "That hero is..."
print "YOU!!!"
print "Your journey is to reconquer Fanlack and destroy Tardsat."
print "You will need training."

def train():
    global sword, crossbow, knife, experience, Orc, Troll, Dog
    print
    print "-------------------------Monsters-------------------------"
    print "There are certain types of monsters."
    print "The three main monsters are:"
    print "\tOrcs"
    print "\tTroll"
    print "\tDog"
    print "Orc info:"
    print "\tPower: %s" % Orc.power
    print "\tAttack: %s" % Orc.attack
    print "\tDefense: %s" % Orc.defense
    print
    print "Troll info:"
    print "\tPower: %s" % Troll.power
    print "\tAttack: %s" % Troll.attack
    print "\tDefense: %s" % Troll.defense
    print
    print "Dog info:"
    print "\tPower: %s" % Dog.power
    print "\tAttack: %s" % Dog.attack
    print "\tDefense: %s" % Dog.defense
    print
    print "A orc is just a regular bad guy.  Orcs are just like men, but"
    print "sometimes stronger.  A troll is a hard bad creature.  Beginners"
    print "will definitely not beat it.  A dog is the easiest bad creature.  It"
    print "is easy to kill a dog."
    print
    print "-------------------------Weapons-------------------------"
    print "There are weapons.  I have equiped you with a sword, crossbow, and a"
    print "knife.  Swords are good for short range attacks.  Crossbows are good"
    print "for long range attacks.  You have to get up close to attack with a"
    print "knife.  Now let's train."
    print
    print "-------------------------Training-------------------------"
    print "Let's start with a dog.  You move first and attack.  Then the dog"
    print "attacks.  You keep on going until you die or the dog dies."
    print
    raw_input("Hit enter to start")
    if character == 'warrior':
        print "Your XP: %s\t\t\tDog XP: %s" % (warrior.power, Dog.power)
        weapon = raw_input("Choose a weapon: ")
        if weapon not in waweapons:
            print "No weapon found."
            weapon = raw_input("Choose a weapon: ")
        if weapon.lower().startswith('sword'):
            print "You attack the dog with a sword."
            Dog.power -= sword.attack
            while Dog.power > 0:
                print "Your XP: %s\t\t\tDog XP: %s" % (warrior.power, Dog.power)
                weapon = raw_input("Choose a weapon: ")
            if Dog.power <= 0:
                print "Dog dead!!"
                print "HOORAY!!!"
        if weapon.lower().startswith('crossbow'):
            print "You attack the dog with a crossbow."
            Dog.power -= crossbow.attack
            while Dog.power > 0:
                print "Your XP: %s\t\t\tDog XP: %s" % (warrior.power, Dog.power)
                weapon = raw_input("Choose a weapon: ")
            if Dog.power <= 0:
                print "Dog dead!!"
                print "HOORAY!!!"
        if weapon.lower().startswith('knife'):
            print "You attack the dog with a knife."
            Dog.power -= knife.attack
            while Dog.power > 0:
                print "Your XP: %s\t\t\tDog XP: %s" % (warrior.power, Dog.power)
                weapon = raw_input("Choose a weapon: ")
            if Dog.power <= 0:
                print "Dog dead!!"
                print "HOORAY!!!"
        if Dog.power <= 0:
            experience += 2
            print "Your experience is %s" % experience
            print "You're ready!  Now get out there and show your skills!"
            print
            print "End of Training"
            Dog.power += 20
    if character == 'wizard':
        print "Your XP: %s\t\t\tDog XP: %s" % (wizard.power, Dog.power)
        weapon = raw_input("Choose a weapon: ")
        if weapon not in wiweapons:
            print "Weapon not found."
            weapon = raw_input("Choose a weapon: ")
        if weapon.lower().startswith('wand'):
            print "You attack the dog with a wand."
            Dog.power -= wand.attack
            while Dog.power > 0:
                print "Your XP: %s\t\t\tDog XP: %s" % (wizard.power, Dog.power)
                weapon = raw_input("Choose a weapon: ")
            if Dog.power <= 0:
                print "Dog dead!!"
                print "HOORAY!!!"
        if weapon.lower().startswith('staff'):
            print "You attack the dog with a staff."
            Dog.power -= staff.attack
            while Dog.power > 0:
                print "Your XP: %s\t\t\tDog XP: %s" % (wizard.power, Dog.power)
                weapon = raw_input("Choose a weapon: ")
            if Dog.power <= 0:
                print "Dog dead!!"
                print "HOORAY!!!"
        if weapon.lower().startswith('fire'):
            print "You attack the dog with fire."
            Dog.power -= fire.attack
            while Dog.power > 0:
                print "Your XP: %s\t\t\tDog XP: %s" % (wizard.power, Dog.power)
                weapon = raw_input("Choose a weapon: ")
            if Dog.power <= 0:
                print "Dog dead!!"
                print "HOORAY!!!"
        if Dog.power <= 0:
            experience += 2
            print "Your experience is %s" % experience
            print "You're ready!  Now get out there and show your skills!"
            print
            print "End of Training"
            Dog.power += 20
def game():
    print "Quest: Go to Sando Tower to get stronger."
    std = 'north'
    ud = raw_input("Enter in a direction(north, east, south, west) to go: ")
    if ud == std:
        print "Quest done! You have found Sando Tower!"
    if ud != std:
        if ud == 'east':
            print "You arrive in a dark forest.  Then suddenly a Demon Dog jumps"
            print "on you!"
            print
            print "Game Over"
        if ud == 'south':
            print "You arrive at a tower.  But it is not Sando Tower!  Many Orcs"
            print "come out of the tower.  They kill you!"
            print
            print "Game Over"
        if ud == 'west':
            print "You find a castle.  Two trolls are guarding it.  They get"
            print "their clubs and crush you!"
            print
            print "Game Over"
def main():
    training()
    game()
main()

I'm running it on Python 2.5. Please help me.

What are you asking? Ideas for the game story? Help with the game code? Whats the problem?

As the other posters say, you haven't explained what problems you are having. We can't do much without more information, I am afraid.

I will make a comment, however: with the current version, you are hard-coding a lot of details which could, and probably should, be broken into more general methods. For example, you have the following code, which essentially repeats the same operation:

    print "Warrior info:"
    print "\tPower: %s" % warrior.power
    print "\tAttack: %s" % warrior.attack
    print "\tDefense: %s" % warrior.defense
    print "\tAttacks: sword, crossbow, knife"
    print
    print "Wizard info:"
    print "\tPower: %s" % wizard.power
    print "\tAttack: %s" % wizard.attack
    print "\tDefense: %s" % wizard.defense
    # ... further down ...
    print "Orc info:"
    print "\tPower: %s" % Orc.power
    print "\tAttack: %s" % Orc.attack
    print "\tDefense: %s" % Orc.defense
    print
    print "Troll info:"
    print "\tPower: %s" % Troll.power
    print "\tAttack: %s" % Troll.attack
    print "\tDefense: %s" % Troll.defense
    print
    print "Dog info:"
    print "\tPower: %s" % Dog.power
    print "\tAttack: %s" % Dog.attack
    print "\tDefense: %s" % Dog.defense

As a rule, it would make more sense to have a common function or method which would perform this operation, preferably once and only once. It could even apply to both the 'player characters' and the 'creatures', if you have a parent class which both inherit from.

    class Creature (object):
        def __init__(self, name, power, attack, defense):
            self.name = name
            self.power = power
            self.attack = attack
            self.defense = defense

        def stats(self):
            print ("%s's info:" % self.name)
            print ("\tPower: %d" % self.power)
            print ("\tAttack: %d" % self.attack)
            print ("\tDefense: %d" % self.defense)

    class Player(Creature):
        def __init__(self, name, power, attack, defense, player_class):
            Creature.__init__(self, name, power, attack, defense)
            self.player_class = player_class

    wizard = Player("Gandalf", 300, 150, 150, "wizard")
    warrior = Player("Aragorn", 150, 250, 250, "warrior")

    orc = Creature("Gothmog", 100, 350, 350)

    wizard.stats()    # prints the character's statistics, inherited from Creature
    warrior.stats()
    orc.stats()

I hope this gives you some food for thought, if nothing else.

Edited 4 Years Ago by Schol-R-LEA

This article has been dead for over six months. Start a new discussion instead.