Skip to content

Instantly share code, notes, and snippets.

@dskjal
Last active November 14, 2016 19:17
Show Gist options
  • Save dskjal/24ef0f4d3474146efe5ff95a4ddd1adb to your computer and use it in GitHub Desktop.
Save dskjal/24ef0f4d3474146efe5ff95a4ddd1adb to your computer and use it in GitHub Desktop.
アイテムの抽象化
enum ItemStatus{
Delete,
CannotUse
}
interface IItem{
ItemStatus Use();
//そのほかの GetName() のような便利なメソッド
}
class ItemDB{
public IItem IDtoItem(int itemID){
switch(itemID){
// アイテムを作成
}
// IItem が Clone() を実装していれば配列も使える
// return items[itemID].Clone();
}
}
class Inventory{
List<IItem> items;
public void Use(int idx){
if(items[idx].Use() == ItemStatus.Delete){
// アイテムを削除
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment