Skip to main content
grammar and punctuation; removed blacklisted engine tag
Source Link
Gnemlock
  • 5.3k
  • 5
  • 30
  • 60

Choosing How should I handle functions, where to put engine elementstwo classes have equal use?

I'm working on a few features offor a strategy engine I'm making. I'm trying to figure out the best spots to separate the components, as either option will provide the same amount of coupling, with the same effectiveness.

 

AnFor example. All, all players have a DamageDamage component, a PlayerPlayer component, and a HealthBarHealthBar component:

abstract class Damage
{
    protected abstract void sendDamage(Player targetPlayer, int rawDamage);
    public abstract int calculateRawDamage(Attack attackUsed);
    public abstract void receiveDamage(int rawDamage);
}

class Player
{
    List<Armor> equippedArmor;
    List<Buffs> currentBuffs;
    public Damage damageComponent;
    public List<HealthBars> healthBarComponents;
}

abstract class HealthBar //can be inherited for mana or health bar
{
    protected Color color;
    public float percent; //0.0 - 1.0
}

So, my problem. When a player recieves damage, I need to show a red number floating up from their head indicating the amount of damage. This can either be implemented in HealthBar or in Damage. It fits damage better, but then again heals work the same way and wouldn't be cast from damage. So I could abstract damage into something like ChangeValue which would change mana, health, etc in any direction. Or I could use the abstract HealthBar class to show this number being changed. Thoughts? When a player receives damage, I need to show a red number floating up from their head, indicating the amount of damage. This can either be implemented in HealthBar, or in Damage. It fits damage better, but then healing works in the same way, and wouldn't be called from damage. I could abstract damage into something like ChangeValue, which would change mana, health, etc in any direction, or I could use the abstract HealthBar class to show this number being changed.

 

I'm trying to think of a general rule that would solve this and other problems, where two classes use the same function equally. Note: This is an oversimplified version of my classes, but it makes more sense this way. Ignore small errors as this isn't the actual code.

How should I handle functions, where two classes have equal use?

Choosing where to put engine elements

I'm working on a few features of a strategy engine I'm making. I'm trying to figure out the best spots to separate the components as either option will provide the same amount of coupling with the same effectiveness.

An example. All players have a Damage component, a Player component, and a HealthBar

abstract class Damage
{
    protected abstract void sendDamage(Player targetPlayer, int rawDamage);
    public abstract int calculateRawDamage(Attack attackUsed);
    public abstract void receiveDamage(int rawDamage);
}

class Player
{
    List<Armor> equippedArmor;
    List<Buffs> currentBuffs;
    public Damage damageComponent;
    public List<HealthBars> healthBarComponents;
}

abstract class HealthBar //can be inherited for mana or health bar
{
    protected Color color;
    public float percent; //0.0 - 1.0
}

So, my problem. When a player recieves damage, I need to show a red number floating up from their head indicating the amount of damage. This can either be implemented in HealthBar or in Damage. It fits damage better, but then again heals work the same way and wouldn't be cast from damage. So I could abstract damage into something like ChangeValue which would change mana, health, etc in any direction. Or I could use the abstract HealthBar class to show this number being changed. Thoughts?

I'm trying to think of a general rule that would solve this and other problems where two classes use the same function equally. Note: This is an oversimplified version of my classes, but it makes more sense this way. Ignore small errors as this isn't the actual code.

How should I handle functions, where two classes have equal use?

I'm working on a few features for a strategy engine I'm making. I'm trying to figure out the best spots to separate the components, as either option will provide the same amount of coupling, with the same effectiveness.

 

For example, all players have a Damage component, a Player component, and a HealthBar component:

abstract class Damage
{
    protected abstract void sendDamage(Player targetPlayer, int rawDamage);
    public abstract int calculateRawDamage(Attack attackUsed);
    public abstract void receiveDamage(int rawDamage);
}

class Player
{
    List<Armor> equippedArmor;
    List<Buffs> currentBuffs;
    public Damage damageComponent;
    public List<HealthBars> healthBarComponents;
}

abstract class HealthBar //can be inherited for mana or health bar
{
    protected Color color;
    public float percent; //0.0 - 1.0
}

When a player receives damage, I need to show a red number floating up from their head, indicating the amount of damage. This can either be implemented in HealthBar, or in Damage. It fits damage better, but then healing works in the same way, and wouldn't be called from damage. I could abstract damage into something like ChangeValue, which would change mana, health, etc in any direction, or I could use the abstract HealthBar class to show this number being changed.

 

I'm trying to think of a general rule that would solve this and other problems, where two classes use the same function equally. This is an oversimplified version of my classes, but it makes more sense this way.

How should I handle functions, where two classes have equal use?

added 131 characters in body; edited title
Source Link
brandon
  • 3.9k
  • 1
  • 27
  • 33

Component based Choosing where to put engine designelements

I'm working on a few features of a strategy engine I'm making. I'm trying to figure out the best spots to separate the components as either option will provide the same amount of coupling with the same effectiveness.

An example. All players have a Damage component, a Player component, and a HealthBar

abstract class Damage
{
    protected abstract void sendDamage(Player targetPlayer, int rawDamage);
    public abstract int calculateRawDamage(Attack attackUsed);
    public abstract void receiveDamage(int rawDamage);
}

class Player
{
    List<Armor> equippedArmor;
    List<Buffs> currentBuffs;
    public Damage damageComponent;
    public List<HealthBars> healthBarComponents;
}

abstract class HealthBar //can be inherited for mana or health bar
{
    protected Color color;
    public float percent; //0.0 - 1.0
}

So, my problem. When a player recieves damage, I need to show a red number floating up from their head indicating the amount of damage. This can either be implemented in HealthBar or in Damage. It fits damage better, but then again heals work the same way and wouldn't be cast from damage. So I could abstract damage into something like ChangeValue which would change mana, health, etc in any direction. Or I could use the abstract HealthBar class to show this number being changed. Thoughts?

NoteI'm trying to think of a general rule that would solve this and other problems where two classes use the same function equally. Note: This is an oversimplified version of my classes, but it makes more sense this way. Ignore small errors as this isn't the actual code.

Component based engine design

I'm working on a few features of a strategy engine I'm making. I'm trying to figure out the best spots to separate the components as either option will provide the same amount of coupling with the same effectiveness.

An example. All players have a Damage component, a Player component, and a HealthBar

abstract class Damage
{
    protected abstract void sendDamage(Player targetPlayer, int rawDamage);
    public abstract int calculateRawDamage(Attack attackUsed);
    public abstract void receiveDamage(int rawDamage);
}

class Player
{
    List<Armor> equippedArmor;
    List<Buffs> currentBuffs;
    public Damage damageComponent;
    public List<HealthBars> healthBarComponents;
}

abstract class HealthBar //can be inherited for mana or health bar
{
    protected Color color;
    public float percent; //0.0 - 1.0
}

So, my problem. When a player recieves damage, I need to show a red number floating up from their head indicating the amount of damage. This can either be implemented in HealthBar or in Damage. It fits damage better, but then again heals work the same way and wouldn't be cast from damage. So I could abstract damage into something like ChangeValue which would change mana, health, etc in any direction. Or I could use the abstract HealthBar class to show this number being changed. Thoughts?

Note: This is an oversimplified version of my classes, but it makes more sense this way. Ignore small errors as this isn't the actual code.

Choosing where to put engine elements

I'm working on a few features of a strategy engine I'm making. I'm trying to figure out the best spots to separate the components as either option will provide the same amount of coupling with the same effectiveness.

An example. All players have a Damage component, a Player component, and a HealthBar

abstract class Damage
{
    protected abstract void sendDamage(Player targetPlayer, int rawDamage);
    public abstract int calculateRawDamage(Attack attackUsed);
    public abstract void receiveDamage(int rawDamage);
}

class Player
{
    List<Armor> equippedArmor;
    List<Buffs> currentBuffs;
    public Damage damageComponent;
    public List<HealthBars> healthBarComponents;
}

abstract class HealthBar //can be inherited for mana or health bar
{
    protected Color color;
    public float percent; //0.0 - 1.0
}

So, my problem. When a player recieves damage, I need to show a red number floating up from their head indicating the amount of damage. This can either be implemented in HealthBar or in Damage. It fits damage better, but then again heals work the same way and wouldn't be cast from damage. So I could abstract damage into something like ChangeValue which would change mana, health, etc in any direction. Or I could use the abstract HealthBar class to show this number being changed. Thoughts?

I'm trying to think of a general rule that would solve this and other problems where two classes use the same function equally. Note: This is an oversimplified version of my classes, but it makes more sense this way. Ignore small errors as this isn't the actual code.

Source Link
brandon
  • 3.9k
  • 1
  • 27
  • 33

Component based engine design

I'm working on a few features of a strategy engine I'm making. I'm trying to figure out the best spots to separate the components as either option will provide the same amount of coupling with the same effectiveness.

An example. All players have a Damage component, a Player component, and a HealthBar

abstract class Damage
{
    protected abstract void sendDamage(Player targetPlayer, int rawDamage);
    public abstract int calculateRawDamage(Attack attackUsed);
    public abstract void receiveDamage(int rawDamage);
}

class Player
{
    List<Armor> equippedArmor;
    List<Buffs> currentBuffs;
    public Damage damageComponent;
    public List<HealthBars> healthBarComponents;
}

abstract class HealthBar //can be inherited for mana or health bar
{
    protected Color color;
    public float percent; //0.0 - 1.0
}

So, my problem. When a player recieves damage, I need to show a red number floating up from their head indicating the amount of damage. This can either be implemented in HealthBar or in Damage. It fits damage better, but then again heals work the same way and wouldn't be cast from damage. So I could abstract damage into something like ChangeValue which would change mana, health, etc in any direction. Or I could use the abstract HealthBar class to show this number being changed. Thoughts?

Note: This is an oversimplified version of my classes, but it makes more sense this way. Ignore small errors as this isn't the actual code.