예제 #1
0
        public MapJsonModel Map2JsonModel(Map map)
        {
            MapJsonModel mjson = new MapJsonModel();

            mjson.GameOverCondition = map.GameOverCondition;
            mjson.Name        = map.Name;
            mjson.Description = map.Description;
            mjson.PlayerOwnedChemicalsDescription = SemanticObjectController.GenerateChemicals2Text(map.PlayerOwnedChemicals);
            foreach (var b in map.Blocks.FindAll(m => m.IsActive))
            {
                BlockJsonModel bbj = new BlockJsonModel();
                bbj.StrainsInfo = b.Strains == null ? "" : new StrainController().Strains2Text(b.Strains);
                // b.Strains = null;
                bbj.ChemicalNamesInfo = SemanticObjectController.GenerateChemicals2Text(b.PublicChemicals);
                // b.PublicChemicals = null;

                bbj.BlockType       = b.BlockType;
                bbj.Capacity        = b.Capacity;
                bbj.HexCoor         = ObjectHelper.Clone(b.HexCoor);
                bbj.IsActive        = b.IsActive;
                bbj.StandardCoor    = ObjectHelper.Clone(b.StandardCoor);
                bbj.TotalPopulation = b.TotalPopulation;
                mjson.Blocks.Add(bbj);
            }
            return(mjson);
        }
예제 #2
0
 public Strain JsonModel2Strain_Player(StrainJsonModel s)
 {
     return(new Strain {
         Name = s.Name,
         Owner = s.Owner,
         BasicRace = Local.FindRaceByName(s.BasicRaceName),
         Population = s.Population,
         PlayerSelectedGenes = SemanticObjectController.GenerateText2RegGeneObjects(s.PlayerSelectedGenesName),
         PrivateChemicals = new List <Chemical>()
     });
 }
예제 #3
0
 public Strain JsonModel2Strain_Npc(StrainJsonModel s)
 {
     return(new Strain {
         Name = s.Name,
         Owner = s.Owner,
         BasicRace = Local.FindRaceByName(s.BasicRaceName),
         Population = s.Population,
         PlayerSelectedGenes = SemanticObjectController.GenerateText2RegGeneObjects(s.PlayerSelectedGenesName),
         PrivateChemicals = string.IsNullOrEmpty(s.PrivateChemicalInfos) ? new List <Chemical>() : SemanticObjectController.GenerateText2ChemicalsWithCountInfo(s.PrivateChemicalInfos)
     });
 }
예제 #4
0
 public StrainJsonModel Strain2JsonModel(Strain s)
 {
     return(new StrainJsonModel {
         Name = s.Name,
         Owner = s.Owner,
         BasicRaceName = s.BasicRace.Name,
         // Fix #issue 18
         // https://github.com/bennycui99/Cellwar.Game/issues/18
         Population = 100,
         PlayerSelectedGenesName = SemanticObjectController.GenerateRegGeneObjects2Text(s.PlayerSelectedGenes),
     });
 }
예제 #5
0
        public Map JsonModel2Map(MapJsonModel mapJson)
        {
            Map StageMap = new Map();

            StageMap.Name              = mapJson.Name;
            StageMap.Description       = mapJson.Description;
            StageMap.GameOverCondition = mapJson.GameOverCondition;
            StageMap.Blocks            = new List <Block>();
            // 填充blocks的strains数据
            foreach (var b in mapJson.Blocks)
            {
                var bb = b as Block;
                bb.Strains         = new StrainController().Text2Strains_Npc(b.StrainsInfo);
                bb.PublicChemicals = SemanticObjectController.GenerateText2ChemicalsWithCountInfo(b.ChemicalNamesInfo);
                StageMap.Blocks.Add(b as Block);
            }
            StageMap.PlayerOwnedChemicals = SemanticObjectController.GenerateText2ChemicalsWithCountInfo(mapJson.PlayerOwnedChemicalsDescription);
            return(StageMap);
        }