[Tutor] newbie needs help with rpg code in python
Michael Langford
mlangford.cs03 at gtalumni.org
Sun Mar 16 21:00:29 CET 2008
If you'd like to damage_to_enemy from temp_e_hp, you do the following
temp_e_hp -= damage_to_enemy
or
temp_e_hp = temp_e_hp- damage_to_enemy.
Read the single equals sign as the word "gets" in your head.
To get a random integer between two numbers, you do the folowing:
import random
random.randrange(a, b)
Where it will give you an integer of at least a and less than b.
So in your case, you could do
temp_e_hp -= random.randrange(damage_to_enemy * 0.80 ,damage_to_enemy * 1.2)
Which will do between 80-120% the damage_to_enemy to the enemy.
--Michael
On Sun, Mar 16, 2008 at 1:59 PM, jake cooper <lord_cooper at hotmail.co.uk> wrote:
>
> 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 = 180
> max_c_mp = 30
> c_strength = 50
> c_defence = 25
> c_agility = 50
> c_fireball = 60
> c_heal = 100
> #Skeleton stats (lv1)
> max_e_hp = 230
> max_e_mp = 30
> e_strength = 48
> e_defence = 30
> e_agility = 50
> e_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 flow
> temp_c_hp = max_c_hp # creates a temporary stat for characters hp, just to
> be used in this battle
> temp_e_hp = max_e_hp #creates a temporary stat for enemies hp, just to be
> used in this battle
> battle_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
>
> -Jake
>
> ________________________________
> She said what? About who? Shameful celebrity quotes on Search Star!
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
More information about the Tutor
mailing list