Merge branch 'main' of https://git.bib.de/PBT3H24AFA/Lotto_WPf
This commit is contained in:
		@@ -1,12 +1,132 @@
 | 
			
		||||
<Window x:Class="Lotto_Wpf.MainWindow"
 | 
			
		||||
<Window x:Class="LottoApp.MainWindow"
 | 
			
		||||
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
        xmlns:local="clr-namespace:Lotto_Wpf"
 | 
			
		||||
        mc:Ignorable="d"
 | 
			
		||||
        Title="MainWindow" Height="450" Width="800">
 | 
			
		||||
    <Grid>
 | 
			
		||||
        Title="Lotto App" Height="600" Width="800"
 | 
			
		||||
        Background="#1e1e1e"
 | 
			
		||||
        WindowStartupLocation="CenterScreen"
 | 
			
		||||
        Loaded="Window_Loaded">
 | 
			
		||||
 | 
			
		||||
    <Grid>
 | 
			
		||||
        <Grid.ColumnDefinitions>
 | 
			
		||||
            <ColumnDefinition Width="80"/>
 | 
			
		||||
            <ColumnDefinition Width="*"/>
 | 
			
		||||
        </Grid.ColumnDefinitions>
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
        <StackPanel Grid.Column="0" Background="#111" Orientation="Vertical">
 | 
			
		||||
            <TextBlock Text="LOTTO" FontSize="16" FontWeight="Bold" 
 | 
			
		||||
                       Foreground="White" Margin="0,20,0,20" 
 | 
			
		||||
                       HorizontalAlignment="Center"/>
 | 
			
		||||
            <Button Content="Home" FontSize="12" Margin="10" Background="Transparent" Foreground="White"/>
 | 
			
		||||
            <Button Content="Spiel" FontSize="12" Margin="10" Background="Transparent" Foreground="White"/>
 | 
			
		||||
            <Button Content="Geschichte" FontSize="12" Margin="10" Background="Transparent" Foreground="White"/>
 | 
			
		||||
        </StackPanel>
 | 
			
		||||
 | 
			
		||||
        <!-- Main -->
 | 
			
		||||
        <StackPanel Grid.Column="1" Margin="20">
 | 
			
		||||
            <TextBlock Text="Lotto " FontSize="28" FontWeight="Bold" Foreground="White" Margin="0,0,0,20"/>
 | 
			
		||||
            <UniformGrid x:Name="NumberGrid" Rows="7" Columns="7" Margin="0,0,0,20"/>
 | 
			
		||||
            <TextBlock x:Name="SelectedNumbersText" Foreground="White" FontSize="16" Margin="0,0,0,10"/>
 | 
			
		||||
 | 
			
		||||
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,10,0,0">
 | 
			
		||||
                <Button Content="Wahlen" Width="100" Margin="0,0,10,0" Click="QuickPick_Click"/>
 | 
			
		||||
                <Button Content="Loschen" Width="75" Margin="0,0,10,0" Click="Clear_Click"/>
 | 
			
		||||
            </StackPanel>
 | 
			
		||||
        </StackPanel>
 | 
			
		||||
 | 
			
		||||
        <x:Code>
 | 
			
		||||
            <![CDATA[
 | 
			
		||||
            using System;
 | 
			
		||||
            using System.Collections.Generic;
 | 
			
		||||
            using System.Linq;
 | 
			
		||||
            using System.Windows;
 | 
			
		||||
            using System.Windows.Controls;
 | 
			
		||||
            using System.Windows.Media;
 | 
			
		||||
 | 
			
		||||
            List<int> selectedNumbers = new List<int>();
 | 
			
		||||
 | 
			
		||||
            void Window_Loaded(object sender, RoutedEventArgs e)
 | 
			
		||||
            {
 | 
			
		||||
                for (int i = 1; i <= 49; i++)
 | 
			
		||||
                {
 | 
			
		||||
                    Button btn = new Button
 | 
			
		||||
                    {
 | 
			
		||||
                        Content = i.ToString(),
 | 
			
		||||
                        Margin = new Thickness(5),
 | 
			
		||||
                        Background = Brushes.LightGray,
 | 
			
		||||
                        Foreground = Brushes.Black,
 | 
			
		||||
                        Tag = i
 | 
			
		||||
                    };
 | 
			
		||||
                    btn.Click += NumberButton_Click;
 | 
			
		||||
                    NumberGrid.Children.Add(btn);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            void NumberButton_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
            {
 | 
			
		||||
                Button btn = sender as Button;
 | 
			
		||||
                int number = (int)btn.Tag;
 | 
			
		||||
 | 
			
		||||
                if (selectedNumbers.Contains(number))
 | 
			
		||||
                {
 | 
			
		||||
                    selectedNumbers.Remove(number);
 | 
			
		||||
                    btn.Background = Brushes.LightGray;
 | 
			
		||||
                }
 | 
			
		||||
                else if (selectedNumbers.Count < 6)
 | 
			
		||||
                {
 | 
			
		||||
                    selectedNumbers.Add(number);
 | 
			
		||||
                    btn.Background = Brushes.Orange;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                SelectedNumbersText.Text = string.Join(", ", selectedNumbers.OrderBy(n => n));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            void QuickPick_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
            {
 | 
			
		||||
                Random rand = new Random();
 | 
			
		||||
                selectedNumbers.Clear();
 | 
			
		||||
                var buttons = NumberGrid.Children.OfType<Button>().ToList();
 | 
			
		||||
 | 
			
		||||
                foreach (Button btn in buttons)
 | 
			
		||||
                    btn.Background = Brushes.LightGray;
 | 
			
		||||
 | 
			
		||||
                while (selectedNumbers.Count < 6)
 | 
			
		||||
                {
 | 
			
		||||
                    int n = rand.Next(1, 50);
 | 
			
		||||
                    if (!selectedNumbers.Contains(n))
 | 
			
		||||
                        selectedNumbers.Add(n);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                foreach (Button btn in buttons)
 | 
			
		||||
                {
 | 
			
		||||
                    if (selectedNumbers.Contains((int)btn.Tag))
 | 
			
		||||
                        btn.Background = Brushes.Orange;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                SelectedNumbersText.Text = string.Join(", ", selectedNumbers.OrderBy(n => n));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            void Clear_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
            {
 | 
			
		||||
                selectedNumbers.Clear();
 | 
			
		||||
                foreach (Button btn in NumberGrid.Children.OfType<Button>())
 | 
			
		||||
                    btn.Background = Brushes.LightGray;
 | 
			
		||||
 | 
			
		||||
                SelectedNumbersText.Text = "";
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            void Submit_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
            {
 | 
			
		||||
                if (selectedNumbers.Count != 6)
 | 
			
		||||
                {
 | 
			
		||||
                    MessageBox.Show("Please select exactly 6 numbers.");
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                MessageBox.Show("Numbers submitted: " + string.Join(", ", selectedNumbers.OrderBy(n => n)));
 | 
			
		||||
            }
 | 
			
		||||
        ]]>
 | 
			
		||||
        </x:Code>
 | 
			
		||||
    </Grid>
 | 
			
		||||
</Window>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user