So basically im creating this python adventure text game. And so far its good. But i have this problem with class instances(Is that the right term?)

Say for example i have this class,

    class monster(object):
        def __init__(self,health,attack):
            self.damage = damage
   = health

So then I create a class object(again, is that the right term?)

    goblin = monster(5,30)
    skeleton = monster(10,20)

so now, i have this piece of code for the fighting mechanic between the player and the monster. (I just copy past this so the indentation might be messed up)

    if char.location.war == True:
    while death == False:       
        #check where located for enemy localization
        if char.location == GoblinCmp:
            enemy = goblin
            boss = goblinChief
        elif char.location == Forest:
            enemy = skeleton
            boss = SkeletalKing

        #Randomly Chooses wave
        wavenum = random.randrange(1,4)
        currentwave = 0
        #Actual Fighting stage

        if currentwave > wavenum:
            enemy = boss

        if enemy.boss == False:
            print "Wave %s!\n" % currentwave
            print "A %s attacks you!" %
        if enemy.boss == True:
            print "The miniboss %s appears! Get ready!" %

        if currentwave <= wavenum:               
            while death == False:
                print fightstats % {'1','2','3':enemy.att,'b','c':char.att}


                #User choices when fighting
                if fightuser == "attack":
                    outcome = random.choice(attackstat)
                    if outcome == 'hit':
               = - char.att
                        print ('You hit him! You dealt %(1)s damage to the %(a)s!\n') % {'1':char.att,'a'}
                    elif outcome == 'miss':
                        print ('You attacked, but missed!\n')
                    elif outcome == 'graze':
                        currentatt = char.att / 2
               = - currentatt
                        print ('You grazed it! You dealth %(1)s damage to the %(2)s!\n') % {'1':currentatt,'2'}

                if <= 0:
                    print 'You defeated the %(a)s! You earned %(b)s gold! \n' % {'a', 'b':enemy.drops}
                    print 'Press enter to continue!'
           = + enemy.drops
                    currentwave = currentwave + 1

                eneoutcome = random.choice(attackstat)
                #Enemy Hits
                if eneoutcome == 'hit':
           = - enemy.att
                    print ('The %(a)s hit you! It dealth %(b)s damage to you!\n') % {'a','b':enemy.att} 
                #Enemy Miss
                elif eneoutcome == 'miss':
                    print ('The %s attacked, but missed!\n') %
                #Enemy Graze
                elif eneoutcome == 'graze':
                    grazed_attack = enemy.att / 2
           = - grazed_attack
                    print ('The %(a)s grazed you! It dealth %(b)s damage to you!\n') % {'a','b':grazed_attack}

                if <= 0:
                    print 'You Died! Press enter to End game!'
                    death = True

As you can see, i have a wave system in this. everytime a player enters a location that has a "war" property, they have to fight a few waves of monsters. The problem here is that i thought if i did

    enemy = goblin #Or something like this.

It would create a whole new class object(Im sure that isn't the proper term.) apprantly it doesn't. Instead everytime i do something like = 0 it changes as well.I dont want that to happen. I only need to change. Is there anyway something like that might be possible? Also optional, is there anyway to clean up this code a little?

Well, when you set enemy equal to goblin, that's really just an association, not a new object. You can see an explanation of the issue and the use of "copy" to deal with it here. Perhaps it is simpler just to instantiate a new obect.

Well, for this game, the player should be able to fight monsters as much as they want. So i don't think creating an object for EVERY monster they fight will work.

Also, i checked out that link you gave me. I think its what need. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.