From 58683834d5e3e69f4758a1c629847b7788315619 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 26 Sep 2024 21:10:37 +0100 Subject: [PATCH] SpinButton_Clicked fully implemented it sets NumbersLabel.Text to different outputs according to the kind of lottery Thunderball lottery added to list of generators --- Lottery/MainPage.xaml.cs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Lottery/MainPage.xaml.cs b/Lottery/MainPage.xaml.cs index f0b3365..7c76a23 100644 --- a/Lottery/MainPage.xaml.cs +++ b/Lottery/MainPage.xaml.cs @@ -2,7 +2,7 @@ { public partial class MainPage : ContentPage { - readonly List generators = [new UKGenerator(), new EuroGenerator(), new SetForLifeGenerator()]; + readonly List generators = [new UKGenerator(), new EuroGenerator(), new SetForLifeGenerator(), new ThunderBallGenerator()]; IGenerator generator; const KindOfLotto DEFAULT_GENERATOR = KindOfLotto.Uk; @@ -10,7 +10,7 @@ { InitializeComponent(); - List lottos = ["UK", "Euro", "Set For Life"]; + List lottos = ["UK Lotto", "EuroMillions", "Set For Life", "Thunderball"]; LottoPicker.ItemsSource = lottos; LottoPicker.SelectedIndex = (int)DEFAULT_GENERATOR; @@ -19,8 +19,27 @@ private void SpinButton_Clicked(object sender, EventArgs e) { - List numbers = generator.Generate(); - Numbers.Text = $"Numbers: {string.Join(", ", numbers)}"; + Numbers numbers = generator.Generate(); + switch (numbers.Kind) + { + case KindOfLotto.Uk: + NumbersLabel.Text = $"Numbers: {string.Join(", ", numbers.Normal)}"; + break; + 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)}" + ]; + 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)