namespace RogueBase.Classes
{
public class Player
{
public Iitem[] inventory { get; set; }
private int _hp;
public int hp
{
get { return _hp; }
set
{
if (value <= 0) _hp = 0;
else if (value > 100) _hp = 100;
else _hp = value;
}
}
public Player()
{
hp = 100;
}
}
}
using RogueBase.Interfaces;
namespace RogueBase.Classes
{
public class Storage
{
public Iitem[] inventory { get; set; }
public Storage(int capacity)
{
inventory = new Iitem[capacity];
}
public bool Add(Iitem newItem)
{
for (int i = 0; i < inventory.Length; i++) // check each slot
{
if (inventory[i] as Iitem != null) { continue; } // skip items
inventory[i] = newItem; // assign item to empty slot
return true; // report success
}
return false; // inventory full
}
public bool Remove(Iitem targetItem)
{
for (int i = 0; i < inventory.Length; i++) // check each slot
{
if(inventory[i] == targetItem) // when match is found
{
inventory[i] = null; // remove it
return true; // report success
}
}
return false; // no item found
}
}
}
Edit; Specified question:
How can I access Iitem[] inventory in class Player to be used in class Storage's methods?