The idea here is that I got a 3 players which are put inside a list. Screen shows 3 players that are inside this list called "party_members". 1 of these players gets debuffed with lets say poison 2 turns after that happens small icon pops up beside player name with cooldown number 2 inside of a picture.
As I said I did exactly what I wanted in this code example but in a poor way.
So first off I was using my Player class for everything like skill cooldowns, skill images, enemies all that without creating other classes like Skill class Enemy class etc.
Now I'm more interested in writing the code a correct way and doing it right with classes and functions. I want to know how do I connect 2 classes together and attempted to do it in my code but im not sure if I did this correctly?
Second I used to create skill1_duration, skill2_duration etc for every skill i created i used 1 more line in Player class to do so. Now I want actually to define a skill just as I did it with player "default player1 = Player("Player1",100,10)" and actually use that Skill class I created. So no matter what debuff skill is being casted on Player it will always show the right cooldown and right image without me needing to add skill3_duration,skill4_duration etc.
So to make you understand simply what I want is exact same thing I have right now but written in right way.
Code: Select all
init python: class Player(object): def __init__(self,name="NoName",hp=0,en=0,picture="PLAYER",skill1_duration=0,skill_image="SKILL"): self.name = name # Player name self.hp = hp # player hp self.en = en # Player energy self.picture = picture # image of player self.skill1_duration = skill1_duration # MY POOR VERSION OF SKILL COOLDOWNS... self.skill_image = skill_image # THIS IS ALSO WRONG I WANT TO CALL THIS FROM "Skills" Class not in here... init python: class Skills(Player): # I want this and Player object to be connected in code but how do I do this is this the right way? def __init__(self,name="NoName",damage=0,picture="NoImage",duration=0,target=None): Player.__init__(self,name,hp) self.name = name #Name of the skill self.damage = damage #Damage skill will inflict each turn self.picture = picture #Skill image for tooltips 120x120 and effect display 35x35 self.duration = duration # Skill duration -1 per terun self.target = target # Which player will be attacked default player1 = Player("Player1",100,10) default player2 = Player("Player2",150,10) default player3 = Player("Player3",200,10) default party_members = [player1,player2,player3] screen battle_test_screen(): hbox: xalign 0.250 yalign 0.400 spacing 80 for player in party_members: # Always show players pictures on screen if player.hp > 1: add player.picture hbox: xalign 0.250 yalign 0.450 spacing 80 for i, player in enumerate(party_members): if player.skill1_duration >=1 : text "Skill Cooldown [player.skill1_duration]" add player.skill_image # The game starts here. label start: show screen battle_test_screen "Game starts" "Lets add skill duration" $ player1.skill1_duration = 2 "This worked nicely" # Just an example here... # $ player1.skill1_duration -= 1 "Turn 1 decrease skill duration" $ player1.skill1_duration -= 1 "Turn 2 decrease skill duration and debuff skill image is removed as expected..." "Everything here worked as I want it to work only problem is in code that is written very poorly. So please if someone can help me in inproving my code..." return