Esempio n. 1
0
        /// <summary>
        /// Upload everything specified as parameters
        /// </summary>
        /// <param name="queue">New queue</param>
        /// <param name="id">New global game ID</param>
        /// <param name="settings">New game settings</param>
        private void Upload(List <double> queue, int id = -1, string settings = "")
        {
            string queueStr = "[";

            foreach (var _id in queue)
            {
                queueStr += $"{_id},";
            }
            queueStr = queueStr.Trim(',') + ']';

            AwaitTask(Firebase.Put(queueStr, "queue"));
            if (id >= 0)
            {
                AwaitTask(Firebase.Put((id + 1).ToString(), "game_id"));
                if (settings != "")
                {
                    using (Json gameSettings = SplashKit.CreateJson())
                    {
                        // adding settings to the game
                        gameSettings.AddObject("settings", SplashKit.CreateJson(settings));
                        AwaitTask(Firebase.Put(gameSettings, $"{Constants.GAMENAME}{id}"));
                    }
                }
            }
        }
        public string ToJsonString()
        {
            var json = SplashKit.CreateJson();

            json.AddString("host", Host.ToJsonString());
            json.AddString("guest", Guest.ToJsonString());
            json.AddString("settings", GameSettings.ToJsonString());
            return(SplashKit.JsonToString(json));
        }
        public string ToJsonString()
        {
            var json = SplashKit.CreateJson();

            json.AddNumber("boardWidth", BoardWidth);
            json.AddNumber("boardHeight", BoardHeight);
            json.AddNumber("bombNumber", Bomb);
            return(SplashKit.JsonToString(json));
        }
 public void FromJson(string jsonString)
 {
     try
     {
         FromJson(SplashKit.CreateJson(jsonString));
     }
     finally
     {
         // empty block here, just to catch the exception without much penalty
     }
 }
Esempio n. 5
0
        public string ToJsonString()
        {
            // take a chance to update Flag
            Flag = (Board as MinesweeperBoard).Flag;

            var json = SplashKit.CreateJson();

            json.AddNumber("time", Time);
            json.AddNumber("flag", Flag);
            json.AddArray("board", new List <string>(Board.DrawableBoard));
            return(SplashKit.JsonToString(json));
        }
 /// <summary>
 /// Merge with current multiplayer data object with a json string
 /// </summary>
 /// <param name="jsonString">JSON string with expected fields for player data</param>
 /// <param name="role">Role of multiplayer game connection (host vs guest)</param>
 public void Merge(string jsonString, MultiplayerRole role) => Merge(SplashKit.CreateJson(jsonString), role);
 public void FromJson(string jsonString) => FromJson(SplashKit.CreateJson(jsonString));
 public GameSettings(string jsonString, int gameId)
     : this(SplashKit.CreateJson(jsonString), gameId)
 {
 }