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.baseAttack()

 This is the basic command that is run for all monster attacks.

Parameters

It simply takes the current monster as a parameter named attacker.

The rundown

def baseAttack(self, attacker):
targetingNum = int(random.random() * 100)
while targetingNum < 1:
targetingNum = int(random.random() * 100)
targets = []

I start by generating a random number into targetingNum and ensuring it’s greater than 1.

for fighter in self.listing:
if isinstance(self.listing[fighter], PlayableCharacter):
targets.append(fighter)

Then I add all the available playable characters a monster can attack using a loop that iterates over the listing. Those characters’ names are added to targets.

if self.taunt == []:
dividers = [81, 61, 41, 21]
else:
dividers = []
counter = 100
for peep in targets:
if peep == self.taunt[0][0]:
counter -= 34
dividers.append(counter)
else:
counter -= 14
dividers.append(counter)

If there is nothing in taunt, then I simply set up some evenly separated numbers for our characters in dividers. Otherwise, I go through the targets and compare those names to the name found in the taunt. If there is a match the match will receive a bigger number in divider than the other characters making it more likely for them to be hit.

flag = False
for divider in dividers:
if flag:
break
if targetingNum > divider:
target = targets[dividers.index(divider)]
flag = True

Now I set up an indicator bool called flag for another loop. This loop checks each number of the divider to see if it was less than the targetingNum. How this works is that each character in targets has a corresponding number (at the same index) in dividers and the numbers are decreasing as you iterate through dividers. This makes it so that I only need to check greater than (because all the unwanted numbers higher than previous ones have already been checked), and, using the index of the number, I can quickly set target to the corresponding name of the target. Once this target is found the flag is set to true so it can break us out of the loop.

try:
if target not in self.protected:
if self.listing[target].level > 0 and self.listing[target].currentHealth > 0:
self.attackDispaly(attacker, target)
if (attacker.attack - self.listing[target].defense >= 0):
self.listing[target].currentHealth = self.listing[target].currentHealth - attacker.attack + self.listing[target].defense
else:
self.listing[target].currentHealth = self.listing[target].currentHealth - 1
except UnboundLocalError:
pass

Should a target fail to be selected, the first lines of the code that are in the try statement will return a UnboundLocalError., so I added an exception that will do nothing. I did this knowing that if a specific target wasn’t selected, then the monster wasn’t lucky and their attack missed all the characters. If there is a specifically selected target name in target, we first check to make sure they aren’t protected then we apply the damage by taking attack of the attacker and subtracting it from the defender’s defense. If the result for that subtraction is grater than zero than subtract it from the target’s currentHealth. If the result is less than zero, then we subtract 1 form the defender’s currentHealth.

Comments

Popular posts from this blog

Shop() run down

 This class is responsible for running the shop and creating the Item() objects. Constructor: def __init__ ( self ): self .items = [] f = open ( "items.csv" ) fReader = csv.reader(f) for line in fReader: if line == []: continue self .items.append(Item(line[ 2 ] , line[ 0 ] , int (line[ 1 ]) , int (line[ 3 ]))) f.close() When the class is called the class list items are filled with Item() objects created by opening items.csv and taking the data in there to instantiate the items. Then we close the file. WhoIsShopping(): def whoIsShopping ( self , squad : list ): counter = 0 choices = [] print ( "Who is shopping?" ) for member in squad: if member.level > 0 : print ( str (counter) + ": " + member.displayName) choices.append(counter) counter += 1 selection = inputAndCheck( "Selection: " , choices) return squad[selection] T...

Explorer() progress

I decided to start with the explorer() method because of how central it is to the program. I quickly realized I'd need new functions for accessing specific pieces of data from the CVSs, so I made a few for detecting what region the part is in, another for fetching the region name and fetching the region z coordinate. Here is what explorer looks like now. def explorer (): global x global y global z global chapter global region global regionDisplay global Lori global Lauren global Julius global Marcus menu = GameMenu() characters = [Lori , Lauren , Julius , Marcus] menu.update(characters) selections = [ 4 , 5 ] #Code goes here print (regionDisplay + ":" ) print (regionDiscribe(region)) # need and area scanner for detecting nearby locations if regionCheck(x+ 1 , y , z) >= 0 and \ (fetchRegionZ(regionCheck(x+ 1 , y , z))-fetchRegionZ(region) <= 5 and fetchRegionZ(region)-fetchRegionZ(regionCheck...

Flow Charts are Born

Flow charts weren't that difficult to make. I honestly already had a decent idea of how my program would run, so this was really taking what was on my mind and putting it into a graphic. For those who don't know, I'm using a common key for software design for all of the flow charts: Source:  https://www.zenflowchart.com/flowchart-symbols First I have the simplest of my flow charts: theInstaller.py Flow chart. Then I made the Flow chart for theMain.py: Finally, I decided to include 2 flow charts for the important subprocess in the game: Explore() and runCombat(). For all of these, I used color codes to help subdivide the pieces of the code into their smaller loops or different paths. I'll be using these flow charts a lot to point out where exactly I'm at in the game as I go along with this blog.