Mar-16-2019, 01:45 PM
Please understand that I'm extremely new to Python and object oriented programming so I'm sure this code looks like a mess. I'm working on a basic RPG style battle system and I'm reaching the limits of my knowledge. I made a character class and worked out the basics mechanics of how battle works. You'll notice i have a SPD (speed) described in the class. I want this number to determine who goes first, but I have no idea how to apply this. I have other goals, but ill start small with that one. Any advice?
1 2 3 4 5 6 7 8 |
class Character: def __init__( self , name, HP, ATK, DEF, SPD): self .name = name self .HP = HP self .ATK = ATK self .DEF = DEF self .SPD = SPD |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
from character import Character import random import time character1 = Character( "Adam" , 5000 , 100 , 0 , 0 ) character2 = Character( "Buddy" , 5000 , 100 , 0 , 1 ) round = 0 ### Battle Mechanics ### while character1.HP > = 0 and character2.HP > = 0 : winner = "" round + = 1 dice1 = random.randint( 1 , 50 ) dice2 = random.randint( 1 , 50 ) swing1 = character1.ATK - character2.DEF + dice1 swing2 = character2.ATK - character1.DEF + dice2 crit1 = False crit2 = False if dice2 > = 47 : swing2 = swing2 * 2 crit2 = True if dice1 > = 47 : swing1 = swing1 * 2 crit1 = True fumble1 = False fumble2 = False if dice2 < = 3 : swing2 = swing2 / 2 fumble2 = True if dice1 < = 3 : swing1 = swing1 / 2 fumble1 = True ### Print ### print ( "\nRound " + str ( round ) + ":" ) time.sleep(. 25 ) if character1.HP < = 0 : winner = character2.name else : print (character1.name + " hit " + character2.name + " for " + str (swing1) + " damage." ) if crit1: print ( "Critical hit!" ) if fumble1: print (character1.name + " has fumbled!" ) time.sleep(. 25 ) if character2.HP < = 0 : winner = character1.name else : print (character2.name + " hit " + character1.name + " for " + str (swing2) + " damage." ) if crit2: print ( "Critical hit!" ) if fumble2: print (character2.name + " has fumbled!" ) time.sleep(. 25 ) ### Apply Damage ### if character1.HP > 0 and character2.HP > 0 : character2.HP - = (swing1) character1.HP - = (swing2) ### Outcome Print ### print ( "\n\n\n" ) if character1.HP > character2.HP: print (character1.name + " has killed " + character2.name) else : print (character2.name + " has killed " + character1.name) print ( "Rounds: " + str ( round )) print (character1.name + "'s HP: " + str (character1.HP)) print (character2.name + "'s HP: " + str (character2.HP)) |