add player name prompt and adding to the leaderboard

This commit is contained in:
Slavasil 2025-03-23 23:29:04 +03:00
parent 82ed5fb784
commit be6c25c35d
3 changed files with 8 additions and 0 deletions

View File

@ -14,6 +14,7 @@
}
public static List<(string, int)> ReadScores() {
if (!File.Exists("leaders.txt")) return new List<(string, int)>();
using StreamReader rd = new StreamReader("leaders.txt");
List<(string, int)> scores = new List<(string, int)>();
string? line = null;

View File

@ -18,6 +18,7 @@ namespace Game {
"Cannot read/create the game config file because of an unknown error",
"Game rules: <no translation> press any key to continue...",
"Game is over. You gave {0} correct answers out of {1}!",
"Enter your name: ",
}},
{"ru-RU", new string[] {
"Не указано ни одного варианта ответа на вопрос",
@ -34,6 +35,7 @@ namespace Game {
"Произошла неизвестная ошибка при чтении/создании файла настроек",
"Правила игры: Вам будет предложено ответить на вопросы. Отвечайте на них правильно и всё будет в шоколаде. Удачи xD! Нажмите любую клавишу, чтобы продолжить",
"Игра окончена. Вы ответили правильно на {0} вопросов из {1}!",
"Введите ваше имя: ",
}}
};
@ -56,6 +58,7 @@ namespace Game {
ERROR_READ_CONFIG_UNKNOWN,
RULES,
GAME_OVER,
ENTER_NAME,
}
}
}

View File

@ -108,6 +108,10 @@ namespace Game {
display.ShowMainGameScreenBase();
display.DrawText(TextDisplay.HAlignment.Center, TextDisplay.VAlignment.Center, display.windowHeight / 4, display.windowWidth / 2 + 1, String.Format(I18n.GetMessage(I18n.Message.GAME_OVER), correntAnswers, questions.Count), 0xffffff, 0x5e61ed);
display.SetCursor(display.windowHeight / 2 + 1, display.windowWidth / 4);
display.WriteColored(I18n.GetMessage(I18n.Message.ENTER_NAME), 0, 0x5e61ed);
Leaderboard.WriteScore(Console.ReadLine(), correntAnswers);
Console.ReadKey();
display.ResetWindow();