Skip to main content

Posts

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...
Recent posts

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...

Shop() is complete!!!!!!

 Now that the big classes are over, we can create the items, and shop for the game. I had all the item’s stats I made beforehand, and I also made the shop() class UML beforehand, but when I began making the shop() class, I realized it was going to big hassle to keep all the items in an array and creating functions that use them because those functions would need to be available not just in shop(), but in PlayableCharacter() as well. Thus I made the Item() class handle all of its functions and made data access easier. I’ll make two posts: shop() breakdown, and Item() breakdown.

combat.combatEndCheck()

def combatEndCheck ( self ): removalList = [] follow = False playerCounter = 0 for figther in self .listing: removeFlag = self .listing[figther].deathCheck() if removeFlag == True : removalList.append(figther) i = 0 for thing in self .order: if thing[ 0 ] == figther: break i += 1 self .order.pop(i) continue if isinstance ( self .listing[figther] , Monster): follow = True if isinstance ( self .listing[figther] , PlayableCharacter) and self .listing[figther].currentHealth > 0 : playerCounter += 1 for body in removalList: self .exp = self .exp + self .listing[body].experience self .listing.pop(body) if playerCounter <= 0 : follow = False return follow This is the final function we need to discuss for Combat() . It takes no parameters and it returns bool depending o...

Combat.safteyRcovery()

def safteyRecovery ( self , ally): luck = int (random.random() * 20 ) friend = self .listing[ally] if isinstance (friend , PlayableCharacter): friend.currentHealth = friend.currentHealth + luck friend.currentEnergy = friend.currentEnergy + luck if friend.currentEnergy > friend.energyValue: friend.currentEnergy = friend.energyValue if friend.currentHealth > friend.health: friend.currentHealth = friend.health self .listing[ally] = friend This one is a lot like rest() from the main line. It takes ally as the name of the character that is being healed. I first fetch the character from listing and save it to friend . I then use a randomly generated number to determine how much health and energy they regain. Finally, the last few ifs are for to make sure the energy and hp didn’t go over max. The I update the copy of the object in listing .

Combat.Saftey()

def saftey ( self , availability= True, Ally= None, Removal= False ): counter = 0 if Removal: self .protected.remove(Ally) return 0 if availability: if len ( self .protected) > 0 : return False for figther in self .listing: if self .listing[figther].currentHealth > 0 : if isinstance ( self .listing[figther] , PlayableCharacter): counter += 1 if counter > 1 : return True else : return False else : self .protected.append(Ally) This function is what does half of the work with my backline battle gimmick. It is multi-purpose, so the bools which are used as parameters merely change which purpose would like to evoke. Thus I will break this function down by parameter. Removal if Removal: self .protected.remove(Ally) return 0 This simply removes the name in Ally from protected . Returns 0 to end the function.   ...

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...