【发布时间】:2013-02-02 09:17:22
【问题描述】:
谁能提出一个干净的方法来做到这一点。我想要一个包含游戏中所有实例化对象的世界。但我不确定如何正确投射。
所有对象都应该在 1 个伞形对象和 1 个字典中,以便于保存/搜索。
//all connected players
private Dictionary<IOClient, string> IOClients = new Dictionary<IOClient, string>();
player = new MObject(new object[]{result.Remove(0,1)}, 1);
public class MObject
{
private Serial m_Serial;
public Serial Serial { get { return m_Serial; } }
public Player player = null;
public Item item = null;
public MObject(object[] obj, int type)
{
// m_Serial = Serial.NewMobile;
if (obj.GetType() == typeof(Player) || type == 1)
{
player = new Player((string)obj[0]);
}
if (obj.GetType() == typeof(Item) || type == 2)
{
// item = new Item();
}
}
}
//Also a World
public static class World
{
private static bool m_Loading;
private static bool m_Loaded;
private static Dictionary<Serial, MObject> m_MObjects;
public static Dictionary<Serial, MObject> MObjects
{ get { return m_MObjects; } }
}
【问题讨论】:
-
请将代码内联到问题中。
-
@AlexeiLevenkov 添加到 OP :)
-
已更新。应该不错。
-
也许你可以真正解释你的问题?
-
一个类型化字典的字典怎么样(每个类型化字典只包含特定(基本)类型的对象)?