/
err404
/
GuessTheNumber
Обзор
Документация
Войти
/
err404
/
GuessTheNumber
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
ScoreManager.cs
38 строк
966 B
err404
feat: добавлен полноценный режим «Булкиной мечты» 🍞
10 ноя 2025, 20:12
10 ноя 2025, 20:12
6ab32af
Код
Авторство
О чём код?
using System; using System.IO; using System.Collections.Generic; using System.Text.Json; public class ScoreManager { private static string FilePath => "scores.json"; public static Dictionary<string, int> LoadOrCreate() { if (!File.Exists(FilePath)) { Save(new Dictionary<string, int>()); Console.WriteLine("💾 Создан scores.json (первый запуск)"); } try { var json = File.ReadAllText(FilePath); return JsonSerializer.Deserialize<Dictionary<string, int>>(json) ?? new(); } catch { return new(); } } public static void Save(Dictionary<string, int> scores) { try { var json = JsonSerializer.Serialize(scores, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(FilePath, json); } catch { /* игнор */ } } }