Skip to main content

Item() rundown

 The item() class holds the information of the item and also runs the item effect when it gets used. Constructor def __init__ ( self , command , name , cost , usage): self .effect = command self .name = name self .cost = cost self .usage = usage The effect holds the string name of the effect for the item,  usage holds the value of the Effect . The rest are self-explanatory. EffectHandler() def effectHandler ( self , user: PlayableCharacter , equip= True ): #learned how to specify type of parameter. if equip: if self .effect == "Def" : user.defense = user.defense + self .usage elif self .effect == "AtkPhy" or self .effect == "AtkMag" : user.attack = user.attack + self .usage else : if self .effect == "hp" : user = self .healing(user) return user This handles the effects of the item when it is used. If equip is true then it will check for the equip...

Combat.turn()

 Now finally I can do the beloved turn(), this function executes a turn for the specified character.

Local Variables and Parameters

def turn(self, ally):
choices = []
chosen = 0
i = 0

Ally, must be a character() object. Choices are a list where the options will be stored for when I call inputandCheck(). Chosen is where the returned value of input and check will be stored. i is used as a variable for counting through my loops.

The rundown

if isinstance(ally, Monster):
print("Turn: " + ally.displayName)
self.baseAttack(ally)

First, I right away check if the ally is a monster and if it is, I display that it’s the monster’s turn and then have it call for a baseAttack().

else:
if ally.currentHealth > 0:
try:
print("up next:" + self.intiativeDisplay(ally.displayName))
print("Current turn: " + self.quickdisplay(ally))
if ally.displayName not in self.protected:
for skill in ally.skills:
if ally.skillCosts[i] <= ally.currentEnergy:
print(str(i) + ": " + skill)
choices.append(i)
i += 1
protect = i
if self.saftey():
print(str(protect)+ ": Fall back")
choices.append(i)
chosen = inputAndCheck("What will " + ally.displayName + " do? ", choices)
if chosen == protect:
self.saftey(availability= False, Ally= ally.displayName)
else:
ally.currentEnergy = ally.currentEnergy - ally.skillCosts[chosen]
self.skillHandler(ally, ally.skills[chosen])

Else, I assume the ally is a PlayableCharacter() and I check if they have more than zero hp. The try block is there just in case a nonplayable character gets through. Then I display important info like who’s turn it is and who’s coming up next using the display functions in the class.

If they aren’t protected, I use a for loop to check the energy cost of the character’s skills with the character’s current energy. If the character has enough energy I display the skill as an option and add the current i value to choices. I also use i in this loop to create an additional option for my fallback gimmick. If there isn’t anyone already in the back line and the ally isn’t the last PlayableCharacter() standing (self.saftey()) then I display falling back as an option.

chosen = inputAndCheck("What will " + ally.displayName + " do? ", choices)
if chosen == protect:
self.saftey(availability= False, Ally= ally.displayName)
else:
ally.currentEnergy = ally.currentEnergy - ally.skillCosts[chosen]
self.skillHandler(ally, ally.skills[chosen])

Now that the options are displayed, I call input and check for the player input via inputAndCheck(). And store it in chosen. If the protected value was chosen then I put the character in the back line by adding them to the protected class variable (via self.saftey()). Otherwise, I use the chosen value to get the cost of the skill and subtract it from the characters total and fetch the name of the skill so I can plug it into the skillHandler() to execute the skill’s effect.

else:
choices = [0,1]
print("0: Stay back")
print("1: go back to front")
chosen = inputAndCheck("What will " + ally.displayName + " do? ", choices)
if chosen == 0:
self.safteyRecovery(ally.displayName)
else:
self.saftey(Ally= ally.displayName, Removal= True)

If they were protected earlier, then they only have two options: Leave the back line or stay back. I display those options on the screen and pass an inputAndCheck(). If they stay in the back (option 0) then I gave them some healing and energy generation (self.safteyRecovery()). If they go back (option 1) they get removed from the protected list.

counter = -1
for defender in self.defRaise:
counter += 1
if defender[0] == ally.displayName:
defender[1] = defender[1] - 1
if defender[1] <= 0:
ally.defense = ally.defense - defender[2]
break
try:
self.defRaise.pop(counter)
except IndexError:
pass
counter = -1
for attacker in self.atkRaise:
counter += 1
if attacker[0] == ally.displayName:
attacker[1] = attacker[1] - 1
if attacker[1] <= 0:
ally.attack = ally.attack - attacker[2]
break
try:
self.atkRaise.pop(counter)
except IndexError:
pass
counter = -1
for annoyance in self.taunt:
counter += 1
if annoyance[0] == ally.displayName:
annoyance[1] = annoyance[1] - 1
if annoyance[1] <= 0:
break
try:
self.taunt.pop(counter)
except IndexError:
pass

These last couple of loops are to tick down any passive effects on the character, so it checks all the listings and if the character name is not found there then it moves on. If it does find a match I tick the count of the effect down by one if it goes down to zero, I remove the effect from the character. Counter here is to help keep track of the index so I can remove them from the list easily after the loop finishes. The reason I wait until after the loop to remove things is that python doesn’t like it when you try to change a list or dictionary while iterating over it at the same time.

 

This is the most central portion of this class. as you can see it calls a lot of other functions to make it do what it does. I’ll be going over all the display functions next, then I will dissect the remaining 6 big ones: targetChooser(),skillHandler(), baseAttack(), safety(), and safetyRecovery(), combatEndCheck().

Comments

Popular posts from this blog

Item() rundown

 The item() class holds the information of the item and also runs the item effect when it gets used. Constructor def __init__ ( self , command , name , cost , usage): self .effect = command self .name = name self .cost = cost self .usage = usage The effect holds the string name of the effect for the item,  usage holds the value of the Effect . The rest are self-explanatory. EffectHandler() def effectHandler ( self , user: PlayableCharacter , equip= True ): #learned how to specify type of parameter. if equip: if self .effect == "Def" : user.defense = user.defense + self .usage elif self .effect == "AtkPhy" or self .effect == "AtkMag" : user.attack = user.attack + self .usage else : if self .effect == "hp" : user = self .healing(user) return user This handles the effects of the item when it is used. If equip is true then it will check for the equip...

UML Diagram and Object Oriented Programing.

Currently, the game uses only global variables and the methods in theMain.py to open and load data. It's become cumbersome to constantly call on the global variables for all my methods and I've realized that I'll be limited in the number of monsters I have if I only use global variables for everything. So this has led me to decide to shift to using Object-oriented programing to run my game. Thus I've prepared a UML diagram to show you all my classes, and subclasses, as well as their interactions, methods, and variables.      theMain.py will function as my main line where all classes and methods will be called as well as have some very important functions built into it. That's they it is connected to almost all the other classes. It'll take care of exploration, descriptions, story tracking, starting the game, ending the game, encounter rates, and gold.      GameMenu will be treated as a static class that has information displayed for the game menu as well as...

Combat() completion! Fights exist now!

Combat() has been completed and the game now is starting to feel like a game. It was a lot of work, but I will be honest I was distracted by holiday events and starting University and that's why it took so long to complete. There is so much to go over with Combat() that I'll be making separate posts for each piece of the Combat class with breakdowns on what they do and how. Here I'll post the results and an implementation overview. Comba() as of now: class Combat( object ): def __init__ ( self , continueStatus = True ): self .order = [] self .listing = {} self .continueStatus = continueStatus self .taunt = [] self .defRaise = [] self .atkRaise = [] self .protected = [] self .exp = 0 def combatantOrganizer ( self ): organizedOrder = [] theStringOrder = [] NumOrder = [] for listing in self .order: NumOrder.append(listing[ 1 ]) NumOrder.sort() for...