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...
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.
Comments
Post a Comment