From 1241070a3041ebfe524bfb1473d0a1d4789b6387 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 26 Sep 2024 23:00:14 +0100 Subject: [PATCH] update special identifiers --- Lottery/MainPage.xaml.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Lottery/MainPage.xaml.cs b/Lottery/MainPage.xaml.cs index 7c76a23..5b492e3 100644 --- a/Lottery/MainPage.xaml.cs +++ b/Lottery/MainPage.xaml.cs @@ -2,9 +2,14 @@ { public partial class MainPage : ContentPage { - readonly List generators = [new UKGenerator(), new EuroGenerator(), new SetForLifeGenerator(), new ThunderBallGenerator()]; - IGenerator generator; + readonly List Generators = [new UKGenerator(), new EuroGenerator(), new SetForLifeGenerator(), new ThunderBallGenerator()]; + IGenerator Generator; const KindOfLotto DEFAULT_GENERATOR = KindOfLotto.Uk; + Dictionary SpecialIdentifiers = new() { + { KindOfLotto.Euro, "Lucky Stars" }, + { KindOfLotto.SetForLife, "Life Ball" }, + { KindOfLotto.Thunderball, "Thunderball" } + }; public MainPage() { @@ -14,37 +19,37 @@ LottoPicker.ItemsSource = lottos; LottoPicker.SelectedIndex = (int)DEFAULT_GENERATOR; - generator = generators[LottoPicker.SelectedIndex]; + Generator = Generators[LottoPicker.SelectedIndex]; } private void SpinButton_Clicked(object sender, EventArgs e) { - Numbers numbers = generator.Generate(); + Numbers numbers = Generator.Generate(); switch (numbers.Kind) { case KindOfLotto.Uk: NumbersLabel.Text = $"Numbers: {string.Join(", ", numbers.Normal)}"; break; - case KindOfLotto.Euro: + case KindOfLotto.Euro: case KindOfLotto.SetForLife: case KindOfLotto.Thunderball: if (numbers is NumbersWithSpecial numbersWithSpecial) { List output = [ - $"Normal: {string.Join(", ", numbersWithSpecial.Normal)}", - $"Special: {string.Join(", ", numbersWithSpecial.Special)}" + $"Numbers: {string.Join(", ", numbersWithSpecial.Normal)}", + $"{SpecialIdentifiers[numbers.Kind]}: {string.Join(", ", numbersWithSpecial.Special)}" ]; NumbersLabel.Text = string.Join("\t", output); } break; default: throw new LottoPickerException($"no NumbersLabel output defined for {numbers.Kind}"); - } + }; } private void LottoPicker_SelectedIndexChanged(object sender, EventArgs e) { - generator = generators[LottoPicker.SelectedIndex]; + Generator = Generators[LottoPicker.SelectedIndex]; } } }