diff --git a/Lotto_Wpf/Lotto_Wpf/LottoProject.cs b/Lotto_Wpf/Lotto_Wpf/LottoProject.cs
new file mode 100644
index 0000000..32c23be
--- /dev/null
+++ b/Lotto_Wpf/Lotto_Wpf/LottoProject.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Linq;
+
+namespace LottoProject
+{
+ public class Lotto
+ {
+ public int[] GezogeneZahlen { get; private set; } = new int[6];
+ public int TrefferAnzahl { get; private set; } = 0;
+
+ public Lotto(int[] userZahlen)
+ {
+ Ziehen();
+ TrefferAnzahl = Treffer(userZahlen, GezogeneZahlen);
+ }
+
+ private void Ziehen()
+ {
+ Random rnd = new();
+ for (int i = 0; i < GezogeneZahlen.Length; i++)
+ {
+ int zahl;
+ do
+ {
+ zahl = rnd.Next(1, 50);
+ }
+ while (GezogeneZahlen.Contains(zahl));
+ GezogeneZahlen[i] = zahl;
+ }
+ }
+
+ public int Treffer(int[] user, int[] gezogen)
+ {
+ return user.Count(gezogen.Contains);
+ }
+ }
+}
+
diff --git a/Lotto_Wpf/Lotto_Wpf/MainWindow.xaml b/Lotto_Wpf/Lotto_Wpf/MainWindow.xaml
index 30857e7..8748e6d 100644
--- a/Lotto_Wpf/Lotto_Wpf/MainWindow.xaml
+++ b/Lotto_Wpf/Lotto_Wpf/MainWindow.xaml
@@ -1,76 +1,21 @@
-
-
+ Title="Lotto Number Board" Height="600" Width="400">
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
diff --git a/Lotto_Wpf/Lotto_Wpf/MainWindow.xaml.cs b/Lotto_Wpf/Lotto_Wpf/MainWindow.xaml.cs
index 80d93e6..fdd2a2a 100644
--- a/Lotto_Wpf/Lotto_Wpf/MainWindow.xaml.cs
+++ b/Lotto_Wpf/Lotto_Wpf/MainWindow.xaml.cs
@@ -1,10 +1,13 @@
-using System.Text;
-using System.Windows;
-using System.Windows.Controls;
+using System;
using System.Collections.Generic;
+using System.Linq;
+using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
+using LottoProject;
+using System.Diagnostics;
+using System.Threading.Tasks;
namespace LottoNumberBoard
{
@@ -15,6 +18,22 @@ namespace LottoNumberBoard
public MainWindow()
{
InitializeComponent();
+ GenerateNumberButtons();
+ }
+
+ private void GenerateNumberButtons()
+ {
+ for (int i = 1; i <= 49; i++)
+ {
+ Button btn = new Button
+ {
+ Content = i.ToString(),
+ Tag = i,
+ Margin = new Thickness(5)
+ };
+ btn.Click += NumberButton_Click;
+ NumberGrid.Children.Add(btn);
+ }
}
private void NumberButton_Click(object sender, RoutedEventArgs e)
@@ -28,6 +47,11 @@ namespace LottoNumberBoard
}
else
{
+ if (selectedNumbers.Count >= 6)
+ {
+ MessageBox.Show("Nur 6 Zahlen erlaubt!", "Hinweis", MessageBoxButton.OK, MessageBoxImage.Information);
+ return;
+ }
selectedNumbers.Add(number);
btn.Background = Brushes.LightGreen;
}
@@ -38,9 +62,82 @@ namespace LottoNumberBoard
private void UpdateResultDisplay()
{
- var sorted = new List(selectedNumbers);
- sorted.Sort();
- ResultTextBlock.Text = string.Join(", ", sorted);
+ var sorted = selectedNumbers.OrderBy(n => n);
+ ResultTextBlock.Text = "Ausgewählt: " + string.Join(", ", sorted);
+ }
+
+ private void DrawButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (selectedNumbers.Count != 6)
+ {
+ MessageBox.Show("Bitte wähle genau 6 Zahlen!", "Warnung", MessageBoxButton.OK, MessageBoxImage.Warning);
+ return;
+ }
+
+ int[] userZahlen = selectedNumbers.ToArray();
+ Lotto lotto = new Lotto(userZahlen);
+
+ string gezogene = string.Join(", ", lotto.GezogeneZahlen.OrderBy(n => n));
+ string getroffene = string.Join(", ", userZahlen.Intersect(lotto.GezogeneZahlen).OrderBy(n => n));
+ int anzahlTreffer = lotto.TrefferAnzahl;
+
+ ResultTextBlock.Text += $"\nGezogene Zahlen: {gezogene}";
+ ResultTextBlock.Text += $"\nTreffer: {anzahlTreffer} ({getroffene})\n";
+ }
+
+ private async void SimulationButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (selectedNumbers.Count != 6)
+ {
+ MessageBox.Show("Bitte wähle genau 6 Zahlen für die Simulation!", "Warnung", MessageBoxButton.OK, MessageBoxImage.Warning);
+ return;
+ }
+
+ int[] meineZahlen = selectedNumbers.ToArray();
+ int[] trefferVerteilung = new int[7];
+ int meinGeld = 2000;
+ int versuche = 1000;
+
+ var stopwatch = new Stopwatch();
+ stopwatch.Start();
+
+ await Task.Run(() =>
+ {
+ Random rnd = new();
+ for (int i = 0; i < versuche; i++)
+ {
+ HashSet zufallsZahlen = new();
+ while (zufallsZahlen.Count < 6)
+ zufallsZahlen.Add(rnd.Next(1, 50));
+
+ Lotto lotto = new Lotto(zufallsZahlen.ToArray());
+ int treffer = lotto.Treffer(meineZahlen, lotto.GezogeneZahlen);
+ trefferVerteilung[treffer]++;
+
+ meinGeld -= 5;
+ switch (treffer)
+ {
+ case 3: meinGeld += 20; break;
+ case 4: meinGeld += 400; break;
+ case 5: meinGeld += 20000; break;
+ case 6: meinGeld += 100000000; break;
+ }
+ }
+ });
+
+ stopwatch.Stop();
+
+ StringBuilder sb = new();
+ sb.AppendLine("\nSimulation abgeschlossen:");
+ for (int i = 0; i < trefferVerteilung.Length; i++)
+ {
+ sb.AppendLine($"{i} Treffer: {trefferVerteilung[i]}x");
+ }
+ sb.AppendLine($"\nDauer: {stopwatch.Elapsed.TotalSeconds:F2} Sekunden");
+ sb.AppendLine($"Kontostand: {meinGeld} €");
+
+ ResultTextBlock.Text += "\n" + sb.ToString();
}
}
}
+