diff --git a/MemoryGame/Services/GameService.cs b/MemoryGame/Services/GameService.cs index 331446c..6a25581 100644 --- a/MemoryGame/Services/GameService.cs +++ b/MemoryGame/Services/GameService.cs @@ -46,25 +46,20 @@ public sealed class GameService { _availableWords = []; - var commonWords = new[] - { - "ball", "bed", "book", "car", "cat", "chair", "clock", "cup", - "dog", "door", "fork", "hat", "house", "knife", "phone", - "shoe", "spoon", "table", "tree", "window" - }; + var manifest = await _httpClient.GetStringAsync("manifest.txt"); + var imageNames = manifest.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); - var loadTasks = commonWords.Select(async word => + var loadTasks = imageNames.Select(async imageName => { - var imagePath = $"images/{word}.svg"; + var imagePath = $"images/{imageName}"; try { var response = await _httpClient.GetAsync(imagePath, HttpCompletionOption.ResponseHeadersRead); if (response.IsSuccessStatusCode) { - var germanWord = ConvertToGermanWord(word); return new GameWord { - Word = germanWord, + Word = Path.GetFileNameWithoutExtension(imageName), ImagePath = imagePath, CorrectCount = 0, IncorrectCount = 0 @@ -81,34 +76,6 @@ public sealed class GameService _availableWords = results.Where(w => w != null).Cast().ToList(); } - private static string ConvertToGermanWord(string englishWord) - { - return englishWord.ToLower() switch - { - "fork" => "Gabel", - "knife" => "Messer", - "spoon" => "Löffel", - "door" => "Tür", - "window" => "Fenster", - "ball" => "Ball", - "house" => "Haus", - "tree" => "Baum", - "car" => "Auto", - "cat" => "Katze", - "dog" => "Hund", - "chair" => "Stuhl", - "table" => "Tisch", - "cup" => "Tasse", - "book" => "Buch", - "clock" => "Uhr", - "bed" => "Bett", - "phone" => "Telefon", - "shoe" => "Schuh", - "hat" => "Hut", - _ => char.ToUpper(englishWord[0]) + englishWord[1..].ToLower() - }; - } - public GameSession CreateNewGame() { var rounds = new List(); diff --git a/MemoryGame/wwwroot/manifest.txt b/MemoryGame/wwwroot/manifest.txt new file mode 100644 index 0000000..fbdda0c --- /dev/null +++ b/MemoryGame/wwwroot/manifest.txt @@ -0,0 +1,20 @@ +ball.svg +bed.svg +book.svg +car.svg +cat.svg +chair.svg +clock.svg +cup.svg +dog.svg +door.svg +fork.svg +hat.svg +house.svg +knife.svg +phone.svg +shoe.svg +spoon.svg +table.svg +tree.svg +window.svg \ No newline at end of file