Skip to main content

It seems right but it doesn't allow for as much future-proofing if you decide to add further items that the item can interact with to your game at a later date.

Maybe try something like:

public enum ItemType {Weapon, Tool}

public struct ItemInfo { public ItemType itemType; public int damage; public int speed; }

public class Item { private int durability; private float weight; private List<ItemInfo> _itemInfo = new <itemInfo>(); }

public enum ItemType {Weapon, Tool}

public struct ItemInfo
{
     public ItemType itemType;
     public int damage;
     public int speed;
}

public class Item
{
    private int durability;
    private float weight;
    private List<ItemInfo> _itemInfo = new <itemInfo>();
}

This allows you to keep a simple list of all of the interactions your item may have.

It seems right but it doesn't allow for as much future-proofing if you decide to add further items that the item can interact with to your game at a later date.

Maybe try something like:

public enum ItemType {Weapon, Tool}

public struct ItemInfo { public ItemType itemType; public int damage; public int speed; }

public class Item { private int durability; private float weight; private List<ItemInfo> _itemInfo = new <itemInfo>(); }

This allows you to keep a simple list of all of the interactions your item may have.

It seems right but it doesn't allow for as much future-proofing if you decide to add further items that the item can interact with to your game at a later date.

Maybe try something like:

public enum ItemType {Weapon, Tool}

public struct ItemInfo
{
     public ItemType itemType;
     public int damage;
     public int speed;
}

public class Item
{
    private int durability;
    private float weight;
    private List<ItemInfo> _itemInfo = new <itemInfo>();
}

This allows you to keep a simple list of all of the interactions your item may have.

Source Link
DavidC
  • 281
  • 1
  • 8

It seems right but it doesn't allow for as much future-proofing if you decide to add further items that the item can interact with to your game at a later date.

Maybe try something like:

public enum ItemType {Weapon, Tool}

public struct ItemInfo { public ItemType itemType; public int damage; public int speed; }

public class Item { private int durability; private float weight; private List<ItemInfo> _itemInfo = new <itemInfo>(); }

This allows you to keep a simple list of all of the interactions your item may have.