From 83c471d588ee5a9a788758d404c706eae39b0483 Mon Sep 17 00:00:00 2001 From: David Pine Date: Thu, 31 Mar 2022 19:02:27 -0500 Subject: [PATCH] Update Index.razor A bit of clean up for a friend. --- .../BlazorMatchGame/Pages/Index.razor | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Code/Chapter_1/BlazorMatchGame/BlazorMatchGame/Pages/Index.razor b/Code/Chapter_1/BlazorMatchGame/BlazorMatchGame/Pages/Index.razor index 174a701..791295b 100644 --- a/Code/Chapter_1/BlazorMatchGame/BlazorMatchGame/Pages/Index.razor +++ b/Code/Chapter_1/BlazorMatchGame/BlazorMatchGame/Pages/Index.razor @@ -36,8 +36,8 @@ @code { - List animalEmoji = new List() -{ + List animalEmoji = new() + { "🐶","🐶", "🐺","🐺", "🐮","🐮", @@ -48,12 +48,14 @@ "🐹","🐹", }; - List shuffledAnimals = new List(); + List shuffledAnimals = new(); int matchesFound = 0; Timer timer; int tenthsOfSecondsElapsed = 0; string timeDisplay; - + string lastAnimalFound = string.Empty; + string lastDescription = string.Empty; + protected override void OnInitialized() { timer = new Timer(100); @@ -64,7 +66,7 @@ private void SetUpGame() { - Random random = new Random(); + Random random = Random.Shared; shuffledAnimals = animalEmoji .OrderBy(item => random.Next()) .ToList(); @@ -72,9 +74,6 @@ tenthsOfSecondsElapsed = 0; } - string lastAnimalFound = string.Empty; - string lastDescription = string.Empty; - private void ButtonClick(string animal, string animalDescription) { if (lastAnimalFound == string.Empty) @@ -96,7 +95,7 @@ .ToList(); matchesFound++; - if (matchesFound == 8) + if (matchesFound == shuffledAnimals.Count / 2) { timer.Stop(); timeDisplay += " - Play Again?"; @@ -122,4 +121,4 @@ StateHasChanged(); }); } -} \ No newline at end of file +}