[Tutor] newbie needs help with rpg code in python

jake cooper lord_cooper at hotmail.co.uk
Sun Mar 16 18:59:05 CET 2008

Hey everyone :)
I'm extremely new to programming as python is the first language I have attempted to learn (and I only started yesterday!)
I decided to start learning by attempting to create a short textbased rpg.
My progress so far has been rather haphazard to say the least, but I think I might be finally getting somewhere with this.
Below is my code as it currently exists:
#Character stats (lv 1)
max_c_hp = 180max_c_mp = 30c_strength = 50c_defence = 25c_agility = 50c_fireball = 60c_heal = 100
#Skeleton stats (lv1)
max_e_hp = 230max_e_mp = 30e_strength = 48e_defence = 30e_agility = 50e_fireball = 75
#Battle functions
def battle_start(): #Allows player to choose to fight or run    print 'A skeleton appears from the shadows!'    fight_or_run = int(raw_input ('Do you fight[1] or run[2]?'))    if fight_or_run == 1:        print 'You engage the enemy.'        battle_menu() #Sends player to battle menu    elif fight_or_run == 2:        escape()
def battle_menu(): #Allows player to choose primary action in battle    print 'Attack[1]'    print 'Magic[2]'    print 'Escape[3]'    menu_selection = int(raw_input ('Enter your choice.'))    if menu_selection == 1:        c_attack()    elif menu_selection == 2:        c_m_attack()    elif menu_selection == 3:        escape()
def c_attack(): #Processes damage dealt by a physical attack    damage_to_enemy = c_strength - e_defence     print 'You inflicted', damage_to_enemy, "points of damage to your enemy"  #shows damage dealt    temp_e_hp - damage_to_enemy #!!!attempts to deduct damage_to_enemy from temp_e_hp!!!    print temp_e_hp    if temp_e_hp == 0:        victory()    else:        battle_menu()
def escape(): #Allows player to escape from a battle    print 'You attempt to flee the battle!'    if c_agility > e_agility:        print 'You succssfully escape' #!!!Need to quit battle and return to field!!!    elif c_agility < e_agility:        print 'You fail to escape and miss a battle turn.' #!!!Need to find a way to miss a turn after tb system written!!!        battle_menu()    elif c_agility == e_agility:        print 'You fail to escape and are forced to contine engaging the enemy.'        battle_menu() #Sends player to battle menu
#Battle flowtemp_c_hp = max_c_hp # creates a temporary stat for characters hp, just to be used in this battletemp_e_hp = max_e_hp #creates a temporary stat for enemies hp, just to be used in this battlebattle_start() # launches battle sequence
As you can see, I've annotated it rather thoroughly to display the (simple) processes being performed and there are several issues slowing my progress.  The main one I need help with is in the c_attack function.  For some reason, I cant manage to subtract damage_to_enemy from temp_e_hp.  Any help with my script (especially with this problem) would be highly appreciated.
And for one final question, is there a way to use random percentages of a number.  For example, to subtract 80 - 120 % of damage_to_enemy from temp_e_hp?
Sorry for all the questions, but I'm totally stumped at the moment.
Thanks for your time
Free games, great prizes - get gaming at Gamesbox. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080316/a145989c/attachment-0001.htm 

More information about the Tutor mailing list