2 Replies - 3769 Views - Last Post: 21 March 2009 - 07:24 PM Rate Topic: -----

#1 jmanelson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 26-February 09

simple text based rpg help

Posted 20 March 2009 - 05:47 PM

I am making(or really just testing out python) a text based rpg. Python is my first language and ive only been learning for a few weeks. And i just started an im already stuck. My knowledge of classes and functions are still incredibly low and my logic is probably faulty. but here is my code.
class player:
	def sethp(self, hp):
		self.hp = hp
	def setmp(self, mp):
		self.mp = mp
	def setatt(self, att):
		self.att = att
	def setdef(self, arm):
		self.arm = arm

def battle(hero, noob):
	print("hero hp"), hero.hp,("noob hp"), noob.hp
	battlechoice = input(int("what would u like to do"))
	if battlechoice==1:
		noob.hp-(hero.att-noob.arm)
	else:
		noob.hp-(hero.att-noob.arm)
	print("hero hp"), hero.hp,("noob hp"), noob.hp 

def noob:
	setmp(noob, 10)
	sethp(noob, 10)
	setatt(noob, 10)
	setdef(noob, 5)

def hero:
	setmp(hero, 10)
	sethp(hero, 10)
	setatt(hero, 15)
	setdef(hero, 10)
name = raw_input("enter heroes name")

print "what would u like to do", name
print "1. fight"

choice = input()

if choice==1:
	battle(hero, noob)
else:
	print("boo")



I get a syntax error with the : after defining noob. I'm not sure why. Also i tried to put the class and and the noob and hero definitions in another file and import it but i got an error. I don't fully or much at all understand modules so i just put all the code in one file.

This isn't something that i intend to finish or be enjoyable i am just attempting to produce something with what little python i know to help to not forget it and get a better understanding.

thx for the help guys. I plan on buying the O'reily book on learning python. any good?

This post has been edited by jmanelson: 20 March 2009 - 05:48 PM


Is This A Good Question/Topic? 0
  • +

Replies To: simple text based rpg help

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: simple text based rpg help

Posted 20 March 2009 - 08:30 PM

I think you want something more like this:
class player:
    def sethp(self, hp):
        self.hp = hp
    def setmp(self, mp):
        self.mp = mp
    def setatt(self, att):
        self.att = att
    def setdef(self, arm):
        self.arm = arm

def battle(hero, noob):
    print("hero hp"), hero.hp,("noob hp"), noob.hp
    while noob.hp > 0 and int(input("what would u like to do")) == 1:
        noob.hp = noob.hp - (hero.att-noob.arm)
        print("hero hp"), hero.hp,("noob hp"), noob.hp
        
# Create noob player
noob = player()
noob.setmp(10)
noob.sethp(10)
noob.setatt(10)
noob.setdef(5)

# Create hero player
hero = player()
hero.setmp(10)
hero.sethp(10)
hero.setatt(15)
hero.setdef(10)
name = raw_input("enter heroes name")

print "what would u like to do", name
print "1. fight"

choice = input()

if choice==1:
    battle(hero, noob)
else:
    print("boo")


Was This Post Helpful? 1
  • +
  • -

#3 jmanelson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 26-February 09

Re: simple text based rpg help

Posted 21 March 2009 - 07:24 PM

it works jsut as i wanted. thx man
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1