using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
namespace Starcraft
{
internal class App
{
//생성자
public App()
{
Dictionary<int,ItemData> dicI = new Dictionary<int, ItemData> ();
dicI.Add(100, new ItemData(100, "장검", 8));
dicI.Add(101, new ItemData(101, "단검", 5));
dicI.Add(102, new ItemData(102, "활", 6));
dicI.Add(103, new ItemData(103, "도끼", 10));
Inventory inven = new Inventory(3);
inven.AddItem(new Item(dicI[100]));
inven.AddItem(new Item(dicI[101]));
inven.AddItem(new Item(dicI[102]));
Item item = inven.GetItem(100);
Console.WriteLine(item.GetName());
Console.WriteLine(inven.items.Count);
inven.PrintAllItems();
//단검
//활
inven.AddItem(new Item(dicI[100]));
inven.AddItem(new Item(dicI[101]));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Starcraft
{
internal class Item
{
public ItemData data;
//생성자
public Item(ItemData data)
{
this.data = data;
}
public string GetName()
{
//반환값
return this.data.name;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Starcraft
{
//아이템의 정보
internal class ItemData
{
public int id;
public string name;
public int damage;
//생성자
public ItemData(int id, string name, int damage)
{
this.id = id;
this.name = name;
this.damage = damage;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Starcraft
{
internal class Inventory
{
public List<Item> items;
int capacity;
//생성자
public Inventory(int capacity)
{
this.capacity = capacity;
this.items = new List<Item>();
Console.WriteLine("{0}칸짜리 가방이 생성되었습니다. ({1}/{0})", this.capacity,this.items.Count);
}
public void AddItem(Item item)
{
if (this.items.Count < this.capacity)
{
this.items.Add(item);
Console.WriteLine("{0}을 가방에 넣었습니다 ({1}/{2})", item.data.name, this.items.Count, this.capacity);
}
else
{
Console.WriteLine("가방이 가득찼습니다 ({0}/{1})", this.items.Count,this.capacity) ;
}
}
public Item GetItem(int num)
{
foreach (Item item in items)
{
if (item.data.id == num)
{
this.items.Remove(item);
Console.WriteLine("{0}을 가방에서 꺼냈습니다. ({1}/{2})",item.data.name,this.items.Count,this.capacity);
return item;
}
}
return null;
}
public void PrintAllItems()
{
foreach (Item item in this.items)
{
Console.WriteLine(item.data.name);
}
}
}
}