コード例 #1
0
        public void SaveRoundHistory(string id)
        {
            if (!File.Exists($"{Path}{id}.json"))
            {
                FileStream stream = File.Create($"{Path}{id}.json");
                stream.Close();
            }

            RoundHistory history = new RoundHistory(_stepsBackCount, _history.ToArray());

            StreamWriter file       = new StreamWriter($"{Path}{id}.json");
            string       jsonString = JsonSerializer.Serialize(history, DataUtils.JsonOptions);

            file.Write(jsonString);
            file.Close();
        }
コード例 #2
0
        private void LoadRoundHistory(string id)
        {
            if (!File.Exists($"{Path}{id}.json"))
            {
                _history        = new List <GameProperties>();
                _stepsBackCount = 5;
                return;
            }

            string       pathToHistory = $"{Path}{id}.json";
            StreamReader file          = new StreamReader(pathToHistory);

            string       jsonString = file.ReadToEnd();
            RoundHistory history    = JsonSerializer.Deserialize <RoundHistory>(jsonString);

            file.Close();

            _history        = history.History.ToList();
            _stepsBackCount = history.StepsBackCount;
        }