Last active
November 14, 2016 19:17
-
-
Save dskjal/24ef0f4d3474146efe5ff95a4ddd1adb to your computer and use it in GitHub Desktop.
アイテムの抽象化
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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