JinChanChan/Assets/Scripts/Backpack/Backpack.cs

51 lines
1.5 KiB
C#

using System.Collections.Generic;
namespace Backpack
{
public class Backpack : IBackpack<BackpackItem>
{
private List<BackpackItem> _items = new();
public IReadOnlyList<BackpackItem> Items => _items;
public void PutItem(BackpackItem item)
{
var it = _items.Find(a => a.Equals(item));
if (it != null)
{
var count = it.AddCount(item.Count);
_items.Add(new BackpackItem(item.Id, item.Name, item.Description, item.ItemType, count, item.MaxCount));
return;
}
_items.Add(new BackpackItem(item.Id, item.Name, item.Description, item.ItemType, item.Count,
item.MaxCount));
}
public void TakeItem(BackpackItem item, int count)
{
var it = _items.Find(a => a.Id == item.Id);
if (it != null)
{
_items.Remove(new BackpackItem(item.Id, item.Name, item.Description, item.ItemType, count,
item.MaxCount));
return;
}
}
public BackpackItem GetItem(string name)
{
throw new System.NotImplementedException();
}
public bool ChangePosition(BackpackItem item1, BackpackItem item2)
{
throw new System.NotImplementedException();
}
public void DuiDie()
{
throw new System.NotImplementedException();
}
}
}