Hi all,
Im making a test text game and i got this error when i was trying to run it, after i had told it i wanted to attack:
Traceback (most recent call last):
File "/home/tom/Desktop/Python/Text game/main.py", line 109, in <module>
main()
File "/home/tom/Desktop/Python/Text game/main.py", line 105, in main
print 'his attributes are:' + new_monster.getAttributesInfo()
File "/home/tom/Desktop/Python/Text game/main.py", line 84, in getAttributesInfo
Monster.getAttributesInfo()
TypeError: unbound method getAttributesInfo() must be called with Monster instance as first argument (got nothing instead)
Heres the code for the game:
#!/usr/bin/env python
import random
choice = 0
class weapon(object):
def _init_(self, attack, defense):
self.attack = self.attack
defense = self.defense
def getAttributesInfo(self):
attributes = ['Attack:' + self.attack,
'Defense:' + self.defense]
return ' '.join(attributes)
class sword(weapon):
def _init_(self):
wepon._init_(self, random.randrange(1,3), random.randrange(1,3))
def getAttributesInfo(self):
weapon.getAttributesInfo()
class axe(weapon):
def _init_(self):
weapon._init_(self, random.randrange(1,5), random.randrange(1,5))
print 'This Axe\'s Attributes are:'
print 'Attack:' + self.attack
print 'Defense:' + self.defense
def getAttributesInfo(self):
weapon.getAttributesInfo()
class player():
def _init_(self):
self.health = 10
self.defense = 4
self.base_attack = 3
self.attacking = 1
def weapon(self):
self.weapon = random.range(1,2)
if self.weapon == 1:
self.weapon = sword()
print "you got a sword."
elif self.weapon == 2:
self.weapon = axe()
print "you got an axe."
def attack(Monster):
if not self.attacking == 1:
self.attacking = 1
if self.weapon.attack > monster.defense:
hit = True
monster.health = monster.health - self.weapon.damage
print 'You hit him for ' + self.damage + 'damage!'
for self.damage in axe() and sword():
if self.attack > troll.defense or orc.defense:
self.damage = (player.attack +self.attack) - monster.defense
elif self.attack < troll.defense or orc.defense:
print 'You did\'nt do any damage...'
class Monster(object):
def __init__(self, attack, health, defense,):
self.attack = attack
self.health = health
self.defense = defense
def getAttributesInfo():
attributes = [ "Attack: " + self.attack,
"Health: " +self.health,
"Defense: " + self.defense]
return " ".join(attributes)
class orc(Monster):
def _init_(self):
Monster._init_(self, 4, 30, 5,)
if player.attacking == 1:
print "You are attacking an orc."
if self.health <= 0:
print 'You killed the Orc'
def getAttributesInfo(self):
Monster.getAttributesInfo()
class troll(Monster):
def _init_(self):
Monster._init_(self, 7, 50, 7,)
if player.attacking == 1:
print "You are attacking a Troll."
if self.health <= 0:
print 'You killed the Troll'
def getAttributesInfo(self):
Monster.getAttributesInfo()
def main():
monster_attacking = random.randrange(1,2)
if monster_attacking == 1:
new_monster = orc(4, 30, 5)
elif monster_attacking == 2:
new_monster = troll(7, 50, 7)
choice = raw_input('Do you want to attack:')
if choice == 'yes' or 'yer' or ' yes' or ' yer':
print 'his attributes are:' + new_monster.getAttributesInfo()
attack()
if __name__ == '__main__':
main()
Any ideas and help would be appreciated.