예제 #1
0
        //This method deserializes a string and puts the information into the instance itself.
        public override void Deserialize(string info)
        {
            base.Deserialize(info);
            Points = Convert.ToInt32(JsonUtils.ExtractValue(info, "points"));

            foreach (string s in JsonUtils.GetObjectsInArray(JsonUtils.ExtractValue(info, "orblist")))
            {
                Orbs.Add(Convert.ToInt32(s));
            }
            GamePowerup = new Powerup();
            var strs = JsonUtils.GetObjectsInArray(JsonUtils.ExtractValue(info, "powerups"));

            for (int i = 0; i < Math.Min(strs.Count, 3); ++i)
            {
                switch (strs[i])
                {
                case "ghost":
                    GamePowerup.CurrentPowerups.Add(Powerup.powerups.ghost);
                    GamePowerup.CarryingGhost = true;
                    break;

                case "destabilize":
                    GamePowerup.CurrentPowerups.Add(Powerup.powerups.destabilize);
                    GamePowerup.CarryingDestabilize = true;
                    break;

                case "neutralize":
                    GamePowerup.CurrentPowerups.Add(Powerup.powerups.neutralize);
                    GamePowerup.CarryingNeutralize = true;
                    break;
                }
            }
        }
예제 #2
0
 //This method deserializes a string and puts the information into the instance itself.
 public override void Deserialize(string info)
 {
     // change the properties
     base.Deserialize(info);
     TicksLeft = Convert.ToInt32(JsonUtils.ExtractValue(info, "ticksleft"));
     Strength  = Convert.ToInt32(JsonUtils.ExtractValue(info, "strength"));
     try
     {
         Orbs     = Convert.ToInt32(JsonUtils.ExtractValue(info, "currentcolor"));
         IsStable = true;
     }
     catch
     {
         IsStable  = false;
         ShockWave = new Shockwave(this);
     }
 }
예제 #3
0
 //This method deserializes a string and puts the information into the instance itself.
 public override void Deserialize(string info)
 {
     base.Deserialize(info); //sets xcoor and ycoor
     Type  = "Orb";
     Color = Convert.ToInt32(JsonUtils.ExtractValue(info, "color"));
 }
예제 #4
0
 //This method deserializes a string to set the coordinates
 public virtual void Deserialize(string info)
 {
     Xcoor = Convert.ToDouble(JsonUtils.ExtractValue(info, "xcoor"));
     Ycoor = Convert.ToDouble(JsonUtils.ExtractValue(info, "ycoor"));
 }
예제 #5
0
        //This method reads a file, deserializes it into a Game, and returns the Game object.
        public static Game Load(string filename, bool isCheatMode)
        {
            string json;

            try
            {
                using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
                {
                    json = sr.ReadToEnd();
                }
            }
            catch
            {
                throw new ArgumentException("The file does not exist");
            }
            string version = JsonUtils.ExtractValue(json, "version");

            if (version != '"' + Version + '"')
            {
                throw new FormatException("Wrong version of saved game file: " + version);
            }
            var game = new Game(isCheatMode);

            game.StableWells   = new List <Well>();
            game.UnstableWells = new List <Well>();
            game.Orbs          = new List <Orb>();


            game.Username                      = JsonUtils.ExtractValue(json, "username");
            game.Ticks                         = Convert.ToInt32(JsonUtils.ExtractValue(json, "ticks"));
            game.Player                        = GameObject.FromJsonFactory <Ship>(JsonUtils.ExtractValue(json, "humanplayer"));
            game.Points                        = game.Player.Points;
            game.Player.ParentGame             = game;
            game.Player.GamePowerup.ParentGame = game;

            foreach (string s in JsonUtils.GetObjectsInArray(JsonUtils.ExtractValue(json, "stablegravitywells")))
            {
                game.StableWells.Add(GameObject.FromJsonFactory <Well>(s));
            }
            foreach (string s in JsonUtils.GetObjectsInArray(JsonUtils.ExtractValue(json, "unstablegravitywells")))
            {
                Well w = GameObject.FromJsonFactory <Well>(s);
                w.ShockWave.ParentGame = game;
                game.UnstableWells.Add(w);
            }
            foreach (string s in JsonUtils.GetObjectsInArray(JsonUtils.ExtractValue(json, "orbs")))
            {
                game.Orbs.Add(GameObject.FromJsonFactory <Orb>(s));
            }
            foreach (string s in JsonUtils.GetObjectsInArray(JsonUtils.ExtractValue(json, "aiplayers")))
            {
                AIShip aIShip = GameObject.FromJsonFactory <AIShip>(s);
                aIShip.ParentGame = game;
                game.AIShips.Add(aIShip);
                aIShip.GamePowerup.ParentGame = game;
                aIShip.InitializeTargets();
            }
            game.GameObjects.AddRange(game.Orbs);
            game.GameObjects.AddRange(game.UnstableWells);
            game.GameObjects.AddRange(game.StableWells);
            game.GameObjects.Add(game.Player);
            return(game);
        }