Пример #1
0
        private static void RecordResult(bool humanWon, string humanName, int cPlayerCount)
        {
            GameRecordEntry re = new GameRecordEntry();

            re.Username = humanName;
            var desc  = $"VS {cPlayerCount} Computer Players";
            var tDict = re.LossesPerType;

            if (humanWon)
            {
                tDict = re.WinsPerType;
            }
            tDict.Add(desc, 1);
            GameRecords stats = new GameRecords();

            if (File.Exists(fname))
            {
                var txt = File.ReadAllText(fname);
                stats = JsonConvert.DeserializeObject <GameRecords>(txt);
            }

            stats.AddEntry(re);


            var save = JsonConvert.SerializeObject(stats);

            File.WriteAllText(fname, save);
        }
Пример #2
0
        public void AddEntry(GameRecordEntry newEntry)
        {
            var rec = Records.FirstOrDefault(x => x.Username == newEntry.Username);

            if (rec == null)
            {
                Records.Add(newEntry);
                return;
            }

            CombineDictEntry(newEntry.LossesPerType, rec.LossesPerType);
            CombineDictEntry(newEntry.WinsPerType, rec.WinsPerType);
        }