Hi all im making a text game but first im making a test one and i was writing it and i came across this error:
Traceback (most recent call last):
File "/home/tom/Desktop/Python/Text game/main.py", line 98, in <module>
main()
File "/home/tom/Desktop/Python/Text game/main.py", line 93, in main
print 'his attributes are:' + orc.getAttributesInfo()
TypeError: unbound method getAttributesInfo() must be called with orc instance as first argument (got nothing instead)
heres the code:
#!/usr/bin/env python
import random
choice = 0
class sword():
def _init_(self):
self.attack = random.randrange(1,3)
self.defense = random.randrange(1,3)
class axe():
def _init_(self):
self.attack = player.base_attack + random.randrange(1,5)
self.defense = player.defense + random.randrange(1,4)
print 'You hit him for ' + self.damage + 'damage!'
for self.damage in axe():
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 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:
attack = True
monster.health = monster.health - self.weapon.damage
class orc():
def _init_(self):
self.health = 30
self.defense = 5
self.attack = 4
self.name = 'Orc'
if player.attacking == 1:
print "You are attacking an orc."
if self.health <= 0:
print 'You killed the Orc'
def getAttributesInfo():
return self.name
return 'Attack:' + self.attack
return 'Health:' + self.health
return 'Defense' + self.defense
class troll():
def _init_(self):
self.health = 50
self.defense = 7
self.attack = 7
self.name = 'Troll'
if player.attacking == 1:
print "You are attacking a Troll."
if self.health <= 0:
print 'You killed the Troll'
def getAttributesInfo():
return self.name
return 'Attack:' + self.attack
return 'Health:' + self.health
return 'Defense' + self.defense
def main():
monster_attacking = random.randrange(1,2)
if monster_attacking == 1:
new_monster = orc()
elif monster_attacking == 2:
new_monster = troll()
choce = raw_input('Do you want to attack:')
if choice == 'yes' or 'yer' or ' yes' or ' yer':
if monster_attacking == 1:
print 'his attributes are:' + orc.getAttributesInfo()
if monster_attacking == 2:
print 'his attributes are:' + troll.getAttributesInfo()
if __name__ == '__main__':
main()
hope someone can help, Tom