11 Replies - 8028 Views - Last Post: 01 September 2011 - 05:36 PM Rate Topic: ***-- 2 Votes

#1 Wigglesniff  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 20
  • Joined: 17-August 11

RPG in python

Posted 17 August 2011 - 04:45 PM

I'm 12 and I've been programming in python for about 3 months.
I've been teaching myself so I don't know if I write efficient code.

Here is the code for an RPG I've been working on.
It doesn't really have anything just the ability to save.

def LoadGame():
    choice=input("Enter new for a new player or enter load to load a player. Default is load. =>")
    if choice=='new':
        savefile = open('Drakapalooza.txt', 'w')
        savefile.write('1 0 1 0 100 100')
        savefile.close()
        savefile = open('Drakapalooza.txt', 'r')
        datastring = savefile.readline()
    else:
        savefile = open('Drakapalooza.txt', 'r')
        datastring = savefile.readline()
        savefile.close()
    statstring = datastring.split(' ')
    for i in range(len(statstring)-1):
        statstring[i-1] = eval(statstring[i-1])
    playerstats=statstring
    return playerstats

class Game:

    class Player:

        def __init__(self,playerstats):
            self.attack=playerstats[1]
            self.attxp=playerstats[2]
            self.defense=playerstats[3]
            self.defxp=playerstats[4]
            self.currenthp=playerstats[5]
            self.maxhp=playerstats[6]

    def Playgame(self)
        playerstats=LoadGame()
        player=self.Player(playerstats)
        input('If you need help at any time enter help, press enter to start')

def RunGame():
    game=Game()
    game.Playgame()

RunGame()



Is This A Good Question/Topic? 0
  • +

Replies To: RPG in python

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: RPG in python

Posted 17 August 2011 - 04:56 PM

Is there a question here?
Was This Post Helpful? 0
  • +
  • -

#3 Wigglesniff  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 20
  • Joined: 17-August 11

Re: RPG in python

Posted 17 August 2011 - 05:35 PM

It was vague but I was wondering if it was good,efficient code.
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5882
  • View blog
  • Posts: 12,760
  • Joined: 16-October 07

Re: RPG in python

Posted 17 August 2011 - 05:57 PM

Hmm... is there a question?

You don't really seem to understand the point of a class. The Game class seems confused. The Player class could actually do some work for you.

I'd do something like:
class Player:
	def __init__(self):
		(self.attack, self.attxp, self.defense, self.defxp, self.currenthp, self.maxhp) = (1,0,1,0,100,100)
		self.saveFileName = 'Drakapalooza.txt'
	
	def load(self):
		with open(self.saveFileName, 'r') as fh:
			line = fh.readline()
		values = (int(i) for i in line.split(' '))
		(self.attack, self.attxp, self.defense, self.defxp, self.currenthp, self.maxhp) = values
		
	def save(self):
		values = (self.attack, self.attxp, self.defense, self.defxp, self.currenthp, self.maxhp)
		line = ' '.join(str(i) for i in values) + '\n'
		with open(self.saveFileName, 'w') as fh:
			fh.write(line)

def loadPlayer():
	player = Player()
	choice = input("Enter new for a new player or enter load to load a player. Default is load. =>")
	if choice=='new':
		player.save()
	else:
		player.load()
	return player
	
def RunGame():
	player = loadPlayer()
	input('If you need help at any time enter help, press enter to start')

RunGame()



Hope this helps.
Was This Post Helpful? 1
  • +
  • -

#5 Wigglesniff  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 20
  • Joined: 17-August 11

Re: RPG in python

Posted 17 August 2011 - 06:09 PM

Thanks, I agree with you it's better than what I had.
Was This Post Helpful? 0
  • +
  • -

#6 Wigglesniff  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 20
  • Joined: 17-August 11

Re: RPG in python

Posted 17 August 2011 - 08:20 PM

It didn't quite work so I fixed it up and here's what I have.

class Player:
    
    def __init__(self):
        self.saveFileName = 'Drakapalooza.txt'
     
    def Load(self):
        with open(self.saveFileName, 'r') as savefile:
            line = savefile.readline()
        stats = (int(i) for i in line.split(' '))
        (self.attack, self.attxp, self.defense, self.defxp, self.currenthp, self.maxhp) = stats
         
    def New(self):
        stats = [ 1, 0, 1, 0, 100, 100]
        line = ' '.join(str(i) for i in stats)
        with open(self.saveFileName, 'w') as savefile:
            savefile.write(line)

 
def LoadPlayer():
    player = Player()
    choice = input("Enter new for a new player or enter load to load a player. Default is load. =>")
    if choice=='new':
        player.New()
        player.stats = player.Load()
    else:
        player.stats = player.Load()
    return player

     
def RunGame():
    player = LoadPlayer()
    input('If you need help at any time enter help, press enter to start')
    print(player.defxp)

 
RunGame()


Was This Post Helpful? 0
  • +
  • -

#7 evilyoshi  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 13-August 11

Re: RPG in python

Posted 17 August 2011 - 08:38 PM

Hey, if you are making an rog, download this code and read it, you might learn some things, i know i did.
http://rampantgames.com/hackenslash

the code is at the bottom of the page. i though this was useful, it shows how different parts of the game are coded.
Was This Post Helpful? 1
  • +
  • -

#8 Wigglesniff  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 20
  • Joined: 17-August 11

Re: RPG in python

Posted 18 August 2011 - 08:25 AM

I wasn't really thinking about making it with graphics, just text based. This could be helpful in the future though.
Was This Post Helpful? 0
  • +
  • -

#9 Wigglesniff  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 20
  • Joined: 17-August 11

Re: RPG in python

Posted 29 August 2011 - 02:24 PM

Here's what I have now. If you want to run it you need to make an empty text file called 'Drakapalooza.txt'.
Please tell me what I can fix.
Is it illegal to put code outside of code tags.
I did it so you could copy and paste.

import random
import time
import math

class Player:
    
    def __init__(self):
        self.SaveFileName = 'Drakapalooza.txt'
        items = {}
     
    def Load(self):
        stats = []
        self.items = {}
        with open(self.SaveFileName, 'r') as savefile:
            line = savefile.readline()
        line = line.split(' ')
        for i in range(len(line)):
            stats.append(int(line[i]))
        (self.level, self.xp, self.attack, self.attxp, self.defense, self.defxp, self.hp, self.maxhp) = stats
        line = 'trash'
        with open(self.SaveFileName, 'r') as savefile:
            savefile.readline()
            while not line == '':
                line = savefile.readline()
                if len(line.split(' ')) == 2:
                    line = line.split(' ')
                    self.items[line[0]] = int(line[1])
        return(self)

    def New(self):
        stats = [1, 0, 1, 0, 1, 0, 100, 100]
        line = ' '.join(str(i) for i in (stats))
        with open(self.SaveFileName, 'w') as savefile:
            savefile.write(line)
         
    def Save(self):
        line = ' '.join(str(i) for i in (self.level, self.xp, self.attack, self.attxp, self.defense, self.defxp, self.hp, self.maxhp))
        with open(self.SaveFileName, 'w') as savefile:
            savefile.write(line)
            lines = []
            savefile.write('\n')
            for i in self.items:
                lines.append(i + ' ' + str(self.items[i]) + '\n')
            savefile.writelines(lines)

    def DisplayStats(self):
        print('Level      : ' + str(self.level))
        print('XP         : ' + str(self.xp))
        print('Next Level : ' + str(math.floor(400 * self.level * (1.025 ** self.level))))
        print()
        print('Max HP     : ' + str(self.maxhp))
        print('Curent HP  : ' + str(self.hp))
        print()
        print('Attack     : ' + str(self.attack))
        print('XP         : ' + str(self.attxp))
        print('Next Level : ' + str(math.floor(200 * self.attack * (1.025 ** self.attack))))
        print()
        print('Defense    : ' + str(self.defense))
        print('XP         : ' + str(self.defxp))
        print('Next Level : ' + str(math.floor(200 * self.defense * (1.025 ** self.defense))))

    def Battle(self):
        name = input('    =>')
        totalxpgain = 0
        if name in Enemies.stats:
            enemy = Enemies(name[0].upper() + name[1:], Enemies.stats[name][1], Enemies.stats[name][2], Enemies.stats[name][3], Enemies.drops[name])
            print('Player:' + str(max(0,self.hp)))
            print(enemy.name + ':' + str(max(0,enemy.hp)))
            print()
            while enemy.hp>0 and self.hp>0:
                
                randomatt = random.randint(0, 2 * (enemy.attack + 1))
                randomdef = random.randint(0, 2 * (self.defense + 1))
                if randomatt > randomdef:
                    self.hp = self.hp - (randomatt - randomdef)
                else:
                    totalxpgain = totalxpgain + random.randint(enemy.attack + randomdef - randomatt - 1, enemy.attack + randomdef - randomatt + 1) - self.defense

                randomatt = random.randint(0, 2 * (self.attack + 1))
                randomdef = random.randint(0, 2 * (enemy.defense + 1))
                if randomatt > randomdef:
                    enemy.hp = enemy.hp - (randomatt - randomdef)
                    totalxpgain = totalxpgain + random.randint(enemy.defense + randomatt - randomdef - 1, enemy.defense + randomatt - randomdef + 1) - self.attack

                time.sleep(0.3)
                print('Player:' + str(max(0,self.hp)))
                print(enemy.name + ':' + str(max(0,enemy.hp)))
                print()
            if self.hp<=0:
                print('You lost')
                self.hp = self.maxhp
            else:
                totalxpgain = max(totalxpgain,2)
                attxpgain = math.floor(totalxpgain * random.uniform(0.4,0.6))
                defxpgain = totalxpgain - attxpgain
                self.attxp = self.attxp + attxpgain
                self.defxp = self.defxp + defxpgain
                self.xp = self.xp + totalxpgain
                print('You win')
                print('Enemy drops:')
                for i in range(len(enemy.drops)):
                    itemprob = random.randint(1,100)
                    if itemprob <= enemy.drops[i-1][1]:
                        quantity = random.randint(enemy.drops[i-1][2],enemy.drops[i-1][3])
                        if not enemy.drops[i-1][0] in self.items:
                            self.items[enemy.drops[i-1][0]] = 0
                        self.items[enemy.drops[i-1][0]] = self.items[enemy.drops[i-1][0]] + quantity
                        print('    ' + str(enemy.drops[i-1][0]) + '(' + str(quantity) + ')')
            if self.attxp >= (200 * self.attack * (1.025**self.attack)):
                self.attack = self.attack + 1
            if self.defxp >= (200 * self.defense * (1.025**self.defense)):
                self.defense = self.defense + 1
            if self.xp >= (400 * self.level * (1.025**self.level)):
                self.level = self.level + 1
                self.maxhp = self.maxhp + 10
                self.hp = self.maxhp

    def Eat(self):
        temp = []
        prevhp = self.hp
        fooditem = input('    =>').split(' ')
        for i in range(len(fooditem)-1):
            temp.append(fooditem[i])
        fooditem = [' '.join(temp), fooditem[-1]]
        foodlist = Food()
        if fooditem[0] in foodlist.food and fooditem[0] in self.items:
            if len(fooditem) == 1:
                quantity = 1
            else:
                quantity = math.floor(eval(fooditem[1]))
            if self.items[fooditem[0]] >= quantity and quantity > 0:
                self.items[fooditem[0]] = self.items[fooditem[0]] - quantity
                self.hp = self.hp + (foodlist.food[fooditem[0]] * quantity)
            if self.hp > self.maxhp:
                self.hp = self.maxhp
                print('You ate ' + str(quantity) + ' ' + fooditem[0] + ' and healed ' + str(self.maxhp - prevhp) + '.')
            else:
                print('You ate ' + str(quantity) + ' ' + fooditem[0] + ' and healed ' + str(foodlist.food[fooditem[0]] * quantity) + '.')
            print('Your health is now ' + str(self.hp) + '.')
             
            
def LoadPlayer():
    player = Player()
    choice = input('Enter \'new\' for a new player or enter \'load\' to load a player. Default is load. =>')
    if choice=='new':
        player.New()
        player.stats = player.Load()
    else:
        player.stats = player.Load()
    return player


class Enemies():

    stats = {}
    stats['chicken'] = [1,1,2,11]
    stats['rat'] = [1,2,1,12]
    stats['spider'] = [2,2,1,18]
    stats['cow'] = [3,2,2,19]
    stats['goblin'] = [4,2,3,26]
    stats['imp'] = [4,3,1,21]
    stats['wolf'] = [6,5,3,31]
    stats['wizard'] = [9,10,4,42]
    stats['bear'] = [12,10,10,53]
    stats['guard'] = [19,13,19,69]
    stats['skeleton'] = [23,22,18,87]
    drops = {}
    drops['bear'] = [['meat',75,4,6],['fish',50,1,3],['potion',60,1,3],['super potion',60,1,2],['gold',100,100,140]]
    drops['chicken'] = [['meat',50,1,1],['gold',100,1,10]]
    drops['cow'] = [['meat',75,1,3],['potion',25,1,1],['gold',100,25,45]]
    drops['goblin'] = [['bread',40,1,1],['fish',40,1,2],['potion',25,1,1],['super potion',25,1,1],['gold',100,35,60]]
    drops['guard'] = [['bread',60,2,4],['fish',70,1,3],['potion',55,1,3],['super potion',70,1,2],['gold',100,170,220]]
    drops['imp'] = [['bread',50,1,1],['super potion',25,1,1],['meat',60,1,3],['gold',100,35,60]]
    drops['rat'] = [['meat',30,1,1],['gold',100,1,10]]
    drops['skeleton'] = [['potion',50,1,2],['superpotion',75,1,2],['gold',100,200,250]]
    drops['spider'] = [['potion',20,1,1],['gold',100,10,25]]
    drops['wolf'] = [['fish',50,1,3],['potion',60,1,3],['super potion',50,1,1],['gold',100,70,120]]
    drops['wizard'] = [['bread',40,4,6],['potion',50,1,3],['super potion',50,1,2],['magic candy',25,1,3],['gold',100,90,140]]

    def __init__(self,name,attack,defense,hp,drops):
        self.name = name
        self.attack = attack
        self.defense = defense
        self.hp = hp
        self.drops = drops

class Food():

    def __init__(self):
        self.food = {}
        self.food['meat'] = 5
        self.food['bread'] = 10
        self.food['fish'] = 15
        self.food['magic candy'] = 30
        self.food['potion'] = 25
        self.food['super potion'] = 50 
        

class Menu():

    def RunMenu(player):
        choice = ''
        while not choice == 'exit':
            choice = input('=>')
            if choice == 'save':
                player.Save()
            if choice == 'help':
                Menu.Help.RunHelp()
            if choice == 'stats':
                player.DisplayStats()
            if choice == 'battle':
                player.Battle()
            if choice == 'eat':
                player.Eat()
            if choice in player.items:
                print(choice + '(' + str(player.items[choice]) + ')')

    class Help():

        def RunHelp():
            print('To battle, enter \'fight\' followed by enemy name. For list of enemies, enter \'enemies\'.')
            print('To quit the game, enter \'exit\'')
            choice = input('    =>')
            if choice == 'enemies':
                Menu.Help.DisplayEnemies()

        def DisplayEnemies():
            print('Level   Name')
            print()
            enemylist = []
            for i in Enemies.stats:
                enemylevel = Enemies.stats[i][0]
                enemylist.append([(enemylevel),(' ' + str(enemylevel) + ((9-len(str(enemylevel))) * ' ') + i[0].upper() + i[1:])])
            enemylist.sort()
            for i in enemylist:
                print(i[1])

     
def RunGame():
    player = LoadPlayer()
    input('If you need help at any time, enter \'help\'. Press enter to start.')
    Menu.RunMenu(player)

 
RunGame()



import random
import time
import math

class Player:

def __init__(self):
self.SaveFileName = 'Drakapalooza.txt'
items = {}

def Load(self):
stats = []
self.items = {}
with open(self.SaveFileName, 'r') as savefile:
line = savefile.readline()
line = line.split(' ')
for i in range(len(line)):
stats.append(int(line[i]))
(self.level, self.xp, self.attack, self.attxp, self.defense, self.defxp, self.hp, self.maxhp) = stats
line = 'trash'
with open(self.SaveFileName, 'r') as savefile:
savefile.readline()
while not line == '':
line = savefile.readline()
if len(line.split(' ')) == 2:
line = line.split(' ')
self.items[line[0]] = int(line[1])
return(self)

def New(self):
stats = [1, 0, 1, 0, 1, 0, 100, 100]
line = ' '.join(str(i) for i in (stats))
with open(self.SaveFileName, 'w') as savefile:
savefile.write(line)

def Save(self):
line = ' '.join(str(i) for i in (self.level, self.xp, self.attack, self.attxp, self.defense, self.defxp, self.hp, self.maxhp))
with open(self.SaveFileName, 'w') as savefile:
savefile.write(line)
lines = []
savefile.write('\n')
for i in self.items:
lines.append(i + ' ' + str(self.items[i]) + '\n')
savefile.writelines(lines)

def DisplayStats(self):
print('Level : ' + str(self.level))
print('XP : ' + str(self.xp))
print('Next Level : ' + str(math.floor(400 * self.level * (1.025 ** self.level))))
print()
print('Max HP : ' + str(self.maxhp))
print('Curent HP : ' + str(self.hp))
print()
print('Attack : ' + str(self.attack))
print('XP : ' + str(self.attxp))
print('Next Level : ' + str(math.floor(200 * self.attack * (1.025 ** self.attack))))
print()
print('Defense : ' + str(self.defense))
print('XP : ' + str(self.defxp))
print('Next Level : ' + str(math.floor(200 * self.defense * (1.025 ** self.defense))))

def Battle(self):
name = input(' =>')
totalxpgain = 0
if name in Enemies.stats:
enemy = Enemies(name[0].upper() + name[1:], Enemies.stats[name][1], Enemies.stats[name][2], Enemies.stats[name][3], Enemies.drops[name])
print('Player:' + str(max(0,self.hp)))
print(enemy.name + ':' + str(max(0,enemy.hp)))
print()
while enemy.hp>0 and self.hp>0:

randomatt = random.randint(0, 2 * (enemy.attack + 1))
randomdef = random.randint(0, 2 * (self.defense + 1))
if randomatt > randomdef:
self.hp = self.hp - (randomatt - randomdef)
else:
totalxpgain = totalxpgain + random.randint(enemy.attack + randomdef - randomatt - 1, enemy.attack + randomdef - randomatt + 1) - self.defense

randomatt = random.randint(0, 2 * (self.attack + 1))
randomdef = random.randint(0, 2 * (enemy.defense + 1))
if randomatt > randomdef:
enemy.hp = enemy.hp - (randomatt - randomdef)
totalxpgain = totalxpgain + random.randint(enemy.defense + randomatt - randomdef - 1, enemy.defense + randomatt - randomdef + 1) - self.attack

time.sleep(0.3)
print('Player:' + str(max(0,self.hp)))
print(enemy.name + ':' + str(max(0,enemy.hp)))
print()
if self.hp<=0:
print('You lost')
self.hp = self.maxhp
else:
totalxpgain = max(totalxpgain,2)
attxpgain = math.floor(totalxpgain * random.uniform(0.4,0.6))
defxpgain = totalxpgain - attxpgain
self.attxp = self.attxp + attxpgain
self.defxp = self.defxp + defxpgain
self.xp = self.xp + totalxpgain
print('You win')
print('Enemy drops:')
for i in range(len(enemy.drops)):
itemprob = random.randint(1,100)
if itemprob <= enemy.drops[i-1][1]:
quantity = random.randint(enemy.drops[i-1][2],enemy.drops[i-1][3])
if not enemy.drops[i-1][0] in self.items:
self.items[enemy.drops[i-1][0]] = 0
self.items[enemy.drops[i-1][0]] = self.items[enemy.drops[i-1][0]] + quantity
print(' ' + str(enemy.drops[i-1][0]) + '(' + str(quantity) + ')')
if self.attxp >= (200 * self.attack * (1.025**self.attack)):
self.attack = self.attack + 1
if self.defxp >= (200 * self.defense * (1.025**self.defense)):
self.defense = self.defense + 1
if self.xp >= (400 * self.level * (1.025**self.level)):
self.level = self.level + 1
self.maxhp = self.maxhp + 10
self.hp = self.maxhp

def Eat(self):
temp = []
prevhp = self.hp
fooditem = input(' =>').split(' ')
for i in range(len(fooditem)-1):
temp.append(fooditem[i])
fooditem = [' '.join(temp), fooditem[-1]]
foodlist = Food()
if fooditem[0] in foodlist.food and fooditem[0] in self.items:
if len(fooditem) == 1:
quantity = 1
else:
quantity = math.floor(eval(fooditem[1]))
if self.items[fooditem[0]] >= quantity and quantity > 0:
self.items[fooditem[0]] = self.items[fooditem[0]] - quantity
self.hp = self.hp + (foodlist.food[fooditem[0]] * quantity)
if self.hp > self.maxhp:
self.hp = self.maxhp
print('You ate ' + str(quantity) + ' ' + fooditem[0] + ' and healed ' + str(self.maxhp - prevhp) + '.')
else:
print('You ate ' + str(quantity) + ' ' + fooditem[0] + ' and healed ' + str(foodlist.food[fooditem[0]] * quantity) + '.')
print('Your health is now ' + str(self.hp) + '.')


def LoadPlayer():
player = Player()
choice = input('Enter \'new\' for a new player or enter \'load\' to load a player. Default is load. =>')
if choice=='new':
player.New()
player.stats = player.Load()
else:
player.stats = player.Load()
return player


class Enemies():

stats = {}
stats['chicken'] = [1,1,2,11]
stats['rat'] = [1,2,1,12]
stats['spider'] = [2,2,1,18]
stats['cow'] = [3,2,2,19]
stats['goblin'] = [4,2,3,26]
stats['imp'] = [4,3,1,21]
stats['wolf'] = [6,5,3,31]
stats['wizard'] = [9,10,4,42]
stats['bear'] = [12,10,10,53]
stats['guard'] = [19,13,19,69]
stats['skeleton'] = [23,22,18,87]
drops = {}
drops['bear'] = [['meat',75,4,6],['fish',50,1,3],['potion',60,1,3],['super potion',60,1,2],['gold',100,100,140]]
drops['chicken'] = [['meat',50,1,1],['gold',100,1,10]]
drops['cow'] = [['meat',75,1,3],['potion',25,1,1],['gold',100,25,45]]
drops['goblin'] = [['bread',40,1,1],['fish',40,1,2],['potion',25,1,1],['super potion',25,1,1],['gold',100,35,60]]
drops['guard'] = [['bread',60,2,4],['fish',70,1,3],['potion',55,1,3],['super potion',70,1,2],['gold',100,170,220]]
drops['imp'] = [['bread',50,1,1],['super potion',25,1,1],['meat',60,1,3],['gold',100,35,60]]
drops['rat'] = [['meat',30,1,1],['gold',100,1,10]]
drops['skeleton'] = [['potion',50,1,2],['superpotion',75,1,2],['gold',100,200,250]]
drops['spider'] = [['potion',20,1,1],['gold',100,10,25]]
drops['wolf'] = [['fish',50,1,3],['potion',60,1,3],['super potion',50,1,1],['gold',100,70,120]]
drops['wizard'] = [['bread',40,4,6],['potion',50,1,3],['super potion',50,1,2],['magic candy',25,1,3],['gold',100,90,140]]

def __init__(self,name,attack,defense,hp,drops):
self.name = name
self.attack = attack
self.defense = defense
self.hp = hp
self.drops = drops

class Food():

def __init__(self):
self.food = {}
self.food['meat'] = 5
self.food['bread'] = 10
self.food['fish'] = 15
self.food['magic candy'] = 30
self.food['potion'] = 25
self.food['super potion'] = 50


class Menu():

def RunMenu(player):
choice = ''
while not choice == 'exit':
choice = input('=>')
if choice == 'save':
player.Save()
if choice == 'help':
Menu.Help.RunHelp()
if choice == 'stats':
player.DisplayStats()
if choice == 'battle':
player.Battle()
if choice == 'eat':
player.Eat()
if choice in player.items:
print(choice + '(' + str(player.items[choice]) + ')')

class Help():

def RunHelp():
print('To battle, enter \'fight\' followed by enemy name. For list of enemies, enter \'enemies\'.')
print('To quit the game, enter \'exit\'')
choice = input(' =>')
if choice == 'enemies':
Menu.Help.DisplayEnemies()

def DisplayEnemies():
print('Level Name')
print()
enemylist = []
for i in Enemies.stats:
enemylevel = Enemies.stats[i][0]
enemylist.append([(enemylevel),(' ' + str(enemylevel) + ((9-len(str(enemylevel))) * ' ') + i[0].upper() + i[1:])])
enemylist.sort()
for i in enemylist:
print(i[1])


def RunGame():
player = LoadPlayer()
input('If you need help at any time, enter \'help\'. Press enter to start.')
Menu.RunMenu(player)


RunGame()

This post has been edited by Wigglesniff: 29 August 2011 - 02:31 PM

Was This Post Helpful? 0
  • +
  • -

#10 Akelo  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 98
  • Joined: 12-December 07

Re: RPG in python

Posted 29 August 2011 - 03:01 PM

Hey Wiggle, I like that your posting the code and using it to brainstorm, but here is a question for you. If you're mainly making this rpg to learn python, then no suggestion from me, carry on, awesome sauce. If you're making an rpg to make an rpg, then I would suggest taking a slightly different path than what you're doing right now. A lot of people make games, but never finish them because they program before they have the entire system thought out (now, when I say entire system I mean everything. object classes for the items in the game, character classes, the combat system, how will that work? Is there a story? Purely text based or is it going to be graphical (and which graphics module are you going to use)? How do you want to represent and keep track of where the person is? You'll want to create a mapping system perhaps? There are a lot of things to consider, and I want you to complete this game, since finishing a project is beyond amazing. Most of the time should be spent planning with a short period of intense coding to make your notes and system into a reality. But keep it coming, I really appreciate the discussion thread you started.
Was This Post Helpful? 2
  • +
  • -

#11 Wigglesniff  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 20
  • Joined: 17-August 11

Re: RPG in python

Posted 29 August 2011 - 03:14 PM

I haven't learned graphics yet, but I'm taking a course on artofproblemsolving in graphics.
If I can easily implement graphics, I will try.
I'm teaching my friends python, and I made this to show them how a full program was structured and so they could mess around with it.
My main goal never was to have graphics but, I really will try.

This post has been edited by Wigglesniff: 29 August 2011 - 03:15 PM

Was This Post Helpful? 0
  • +
  • -

#12 Python_4_President  Icon User is offline

  • D.I.C Regular

Reputation: 53
  • View blog
  • Posts: 321
  • Joined: 13-August 11

Re: RPG in python

Posted 01 September 2011 - 05:36 PM

View PostWigglesniff, on 29 August 2011 - 02:24 PM, said:

Here's what I have now. If you want to run it you need to make an empty text file called 'Drakapalooza.txt'.
Please tell me what I can fix.
Is it illegal to put code outside of code tags.
I did it so you could copy and paste.



The CODE box has a hidden menu (mouseover top right corner).

Second option from the left is "Copy to clipboard" which will copy the code (not the line numbers) to your clip board. Then you can paste it like you would paste anything else.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1