Пример #1
0
        public Dictionary <string, object> ToDictionary()
        {
            //Dictionary<string, object> dictionary = new Dictionary<string, object>();
            //dictionary.Add(@"ObjType", ToString());
            //foreach (var atr in this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public))
            //{
            //    object value;
            //    if (atr == null || (value = atr.GetValue(this)) == null)
            //        continue;
            //    string name = atr.Name;

            //    if (typeof(IFormattable).IsAssignableFrom(atr.FieldType))
            //        dictionary.Add(name, value);
            //    else if (name == "universeMatrix")
            //    {
            //        List<Dictionary<string, object>> dictList = new List<Dictionary<string, object>>();
            //        foreach (UniverseObject unObj in universeMatrix)
            //            dictList.Add(unObj.ToDictionary());
            //        dictionary.Add(name, dictList);
            //    }
            //}
            //return dictionary;
            object[] ignoreList = new object[] { cellList };
            return(CBFHandler.ToDictionaryDefault(this, ignoreList));
        }
Пример #2
0
        public override Dictionary <string, object> ToDictionary()
        {
            //Dictionary<string, object> dictionary = new Dictionary<string, object>();
            //dictionary.Add(@"ObjType", ToString());
            //foreach (var atr in this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public))
            //{
            //    object value;
            //    if (atr == null || (value = atr.GetValue(this)) == null)
            //        continue;
            //    string name = atr.Name;

            //    if (typeof(IFormattable).IsAssignableFrom(atr.FieldType))
            //        dictionary.Add(name, value);
            //}
            object[] ignoreList = new object[] { universe };
            Dictionary <string, object> dictionary = CBFHandler.ToDictionaryDefault(this, ignoreList);

            dictionary.Add(@"aggression", genome.Aggression);
            dictionary.Add(@"friendly", genome.Friendly);
            dictionary.Add(@"hunger", genome.Hunger);
            dictionary.Add(@"poisonAddiction", genome.PoisonAddiction);
            dictionary.Add(@"reproduction", genome.Reproduction);

            return(dictionary);
        }
Пример #3
0
        void InitializeDict(Dictionary <string, object> dictionary)
        {
            FieldInfo[] ignoreList = new FieldInfo[]
            {
                GetType().GetField("universeMatrix", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public)
            };
            CBFHandler.InitFromDictionaryDef(this, dictionary, ignoreList);

            IEnumerable <Dictionary <string, object> > dictNumerable = (dictionary["universeMatrix"] as IEnumerable <Dictionary <string, object> >);
            int index = 0;

            foreach (Dictionary <string, object> newDict in dictNumerable)
            {
                string         type = Convert.ToString(newDict["ObjType"]);
                UniverseObject newUO;
                if (type == typeof(EmptySpace).ToString())
                {
                    newUO = new EmptySpace(ConstsUniverse, dictionary);
                }
                else if (type == typeof(Food).ToString())
                {
                    newUO = new Food(ConstsUniverse, dictionary);
                }
                else if (type == typeof(Cell).ToString())
                {
                    newUO = new Cell(ConstsUniverse, dictionary);
                }
                else
                {
                    throw new Exception(@"Unknown UniverseObject type!");
                }

                AddUniverseObject(newUO.GetX(), newUO.GetY(), newUO, true);
                if (newUO is Cell)
                {
                    cellList.Add(newUO as Cell);
                }
                index++;
            }
        }
Пример #4
0
 public Dictionary <string, object> ToDictionary()
 {
     return(CBFHandler.ToDictionaryDefault(this));
 }