Compare commits
35
Commits
049960d30d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
539a79a262 | ||
|
|
a071b93d46 | ||
|
|
1d89b1440a | ||
|
|
c19fca22d2 | ||
|
|
bb0552ba5a | ||
|
|
ca62b656b8 | ||
|
|
74adefe0aa | ||
|
|
94453ea9d2 | ||
|
|
d873e5d099 | ||
|
|
97a78428bb | ||
|
|
0a89009a93 | ||
|
|
78a22d9c0e | ||
|
|
571367ca8c | ||
|
|
e336e6369d | ||
|
|
205126d724 | ||
|
|
09a4d0cd40 | ||
|
|
1a02e3003f | ||
|
|
d8df625bac | ||
|
|
81550cf1bb | ||
|
|
20bf9eb37b | ||
|
|
fbc37f3e2b | ||
|
|
b42d119397 | ||
|
|
6735e1fcc2 | ||
|
|
4d2b5c7700 | ||
|
|
bf0f703f28 | ||
|
|
abd23b4909 | ||
|
|
4594ae9bb5 | ||
|
|
bd09cbf6bb | ||
|
|
a7bcf80935 | ||
|
|
edde0a522a | ||
|
|
51f22f4155 | ||
|
|
cf90775bad | ||
|
|
471aadf272 | ||
|
|
370616d573 | ||
|
|
5986e5b584 |
@@ -0,0 +1,102 @@
|
||||
<Window x:Class="Casino.AdminView"
|
||||
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:Casino"
|
||||
mc:Ignorable="d"
|
||||
Title="Adminbereich"
|
||||
Height="700"
|
||||
Width="1100"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<!-- Lenard Gerdes -->
|
||||
|
||||
|
||||
<Grid Margin="20">
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="Adminbereich"
|
||||
FontSize="30"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,20"/>
|
||||
|
||||
<!-- Nutzerliste -->
|
||||
<DataGrid x:Name="UserDataGrid"
|
||||
Grid.Row="1"
|
||||
AutoGenerateColumns="False"
|
||||
IsReadOnly="True"
|
||||
SelectionMode="Single"
|
||||
CanUserAddRows="False"
|
||||
Margin="0,0,0,20">
|
||||
|
||||
<DataGrid.Columns>
|
||||
|
||||
<DataGridTextColumn Header="ID"
|
||||
Binding="{Binding ID}"
|
||||
Width="220"/>
|
||||
|
||||
<DataGridTextColumn Header="Name"
|
||||
Binding="{Binding Name}"
|
||||
Width="150"/>
|
||||
|
||||
<DataGridTextColumn Header="Alter"
|
||||
Binding="{Binding Age}"
|
||||
Width="80"/>
|
||||
|
||||
<DataGridTextColumn Header="Passwort"
|
||||
Binding="{Binding Passwort}"
|
||||
Width="280"/>
|
||||
|
||||
<DataGridTextColumn Header="Geld"
|
||||
Binding="{Binding Geld}"
|
||||
Width="100"/>
|
||||
|
||||
<DataGridTextColumn Header="Rolle"
|
||||
Binding="{Binding Rolle}"
|
||||
Width="100"/>
|
||||
|
||||
</DataGrid.Columns>
|
||||
|
||||
</DataGrid>
|
||||
|
||||
<StackPanel Grid.Row="2"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center">
|
||||
|
||||
<Button x:Name="BtnBearbeiten"
|
||||
Content="Bearbeiten"
|
||||
Width="150"
|
||||
Height="45"
|
||||
Margin="10"
|
||||
Click="BtnBearbeiten_Click"/>
|
||||
|
||||
<Button x:Name="BtnLoeschen"
|
||||
Content="Löschen"
|
||||
Width="150"
|
||||
Height="45"
|
||||
Margin="10"
|
||||
Click="BtnLoeschen_Click"/>
|
||||
|
||||
<Button Content="Aktualisieren"
|
||||
Width="150"
|
||||
Height="45"
|
||||
Margin="10"
|
||||
Click="BtnAktualisieren_Click"/>
|
||||
|
||||
<Button Content="Schließen"
|
||||
Width="150"
|
||||
Height="45"
|
||||
Margin="10"
|
||||
Click="BtnSchliessen_Click"/>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,130 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
|
||||
namespace Casino
|
||||
{
|
||||
public partial class AdminView : Window
|
||||
{
|
||||
private readonly Database db = new Database();
|
||||
|
||||
private ObservableCollection<User> users;
|
||||
|
||||
public AdminView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// Prüfen, ob der aktuell eingeloggte Benutzer Admin ist
|
||||
if (MainWindow.currentUser < 0)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Es ist kein Benutzer eingeloggt.",
|
||||
"Fehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
users = db.GetUser();
|
||||
|
||||
// Sicherheitsprüfung über die Datenbank
|
||||
if (MainWindow.currentUser >= users.Count ||
|
||||
!db.SelectAdmin(users[MainWindow.currentUser].ID))
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Du hast keine Admin-Rechte.",
|
||||
"Zugriff verweigert",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
UserDataGrid.ItemsSource = users;
|
||||
}
|
||||
|
||||
private void BtnBearbeiten_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (UserDataGrid.SelectedItem is not User selectedUser)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Bitte wähle zuerst einen Benutzer aus.",
|
||||
"Kein Benutzer ausgewählt",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
EditUserView editView = new EditUserView(selectedUser);
|
||||
|
||||
editView.ShowDialog();
|
||||
|
||||
// Nach dem Schließen Daten neu laden
|
||||
users = db.GetUser();
|
||||
UserDataGrid.ItemsSource = users;
|
||||
}
|
||||
|
||||
private void BtnLoeschen_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (UserDataGrid.SelectedItem is not User selectedUser)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Bitte wähle zuerst einen Benutzer aus.",
|
||||
"Kein Benutzer ausgewählt",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Sicherheitsabfrage
|
||||
MessageBoxResult result = MessageBox.Show(
|
||||
$"Möchtest du den Benutzer '{selectedUser.Name}' wirklich löschen?",
|
||||
"Benutzer löschen",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
if (result != MessageBoxResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Benutzer aus Datenbank löschen
|
||||
bool success = db.DeleteUser(selectedUser.ID);
|
||||
|
||||
if (success)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Benutzer wurde erfolgreich gelöscht.",
|
||||
"Erfolgreich",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
|
||||
users = db.GetUser();
|
||||
UserDataGrid.ItemsSource = users;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Der Benutzer konnte nicht gelöscht werden.",
|
||||
"Fehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnAktualisieren_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
users = db.GetUser();
|
||||
UserDataGrid.ItemsSource = users;
|
||||
}
|
||||
|
||||
private void BtnSchliessen_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
+80
-8
@@ -4,30 +4,79 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Casino
|
||||
{
|
||||
class Audioplayer
|
||||
class Audioplayer //ki
|
||||
{
|
||||
private readonly MediaPlayer player = new MediaPlayer();
|
||||
private readonly MediaPlayer shortplayer = new MediaPlayer();
|
||||
private readonly List<MediaPlayer> activePlayers = new();
|
||||
|
||||
public Audioplayer() { shortplayer.MediaEnded += Player_MediaEnded; }
|
||||
|
||||
public void PlaySound(byte[] audioBlob)
|
||||
public void PlaySound(byte[] audioBlob, int soundId)
|
||||
{
|
||||
if (audioBlob == null || audioBlob.Length == 0)
|
||||
return;
|
||||
|
||||
string tempFile = System.IO.Path.Combine(
|
||||
System.IO.Path.GetTempPath(),
|
||||
Guid.NewGuid() + ".mp3");
|
||||
|
||||
|
||||
"casino_" + Guid.NewGuid().ToString("N") + ".mp3");
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes(tempFile, audioBlob);
|
||||
|
||||
shortplayer.Open(new Uri(tempFile));
|
||||
shortplayer.Play();
|
||||
MediaPlayer player = new MediaPlayer();
|
||||
|
||||
activePlayers.Add(player);
|
||||
|
||||
player.MediaEnded += (sender, e) =>
|
||||
{
|
||||
player.Close();
|
||||
activePlayers.Remove(player);
|
||||
|
||||
try
|
||||
{
|
||||
if (File.Exists(tempFile))
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Datei wird eventuell noch kurz von Windows verwendet.
|
||||
}
|
||||
};
|
||||
|
||||
player.MediaFailed += (sender, e) =>
|
||||
{
|
||||
player.Close();
|
||||
activePlayers.Remove(player);
|
||||
|
||||
try
|
||||
{
|
||||
if (File.Exists(tempFile))
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
player.Open(new Uri(tempFile));
|
||||
player.Play();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Fehler beim Abspielen des Sounds:\n" + ex.Message,
|
||||
"Soundfehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void Player_MediaEnded(object? sender, EventArgs e)
|
||||
@@ -38,9 +87,32 @@ namespace Casino
|
||||
|
||||
public void PlayLoopingSound(byte[] audioBlob)
|
||||
{
|
||||
|
||||
string tempFile = System.IO.Path.Combine(
|
||||
System.IO.Path.GetTempPath(),
|
||||
"background.mp3");
|
||||
"Hintergrundmusik.mp3");
|
||||
|
||||
player.Volume = 0.1;
|
||||
|
||||
File.WriteAllBytes(tempFile, audioBlob);
|
||||
|
||||
player.Open(new Uri(tempFile));
|
||||
|
||||
player.MediaEnded -= Player_MediaEnded;
|
||||
player.MediaEnded += Player_MediaEnded;
|
||||
|
||||
player.Play();
|
||||
}
|
||||
|
||||
|
||||
public void PlayLoopingSound_2(byte[] audioBlob)
|
||||
{
|
||||
|
||||
string tempFile = System.IO.Path.Combine(
|
||||
System.IO.Path.GetTempPath(),
|
||||
"Hintergrundmusik_Bus.mp3");
|
||||
|
||||
player.Volume = 0.1;
|
||||
|
||||
File.WriteAllBytes(tempFile, audioBlob);
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<Window x:Class="Casino.Blackjack"
|
||||
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:Casino"
|
||||
mc:Ignorable="d"
|
||||
Title="Blackjack" Height="1080" Width="1980">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"></ColumnDefinition>
|
||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
||||
<ColumnDefinition Width="100"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="70"></RowDefinition>
|
||||
<RowDefinition Height="270"></RowDefinition>
|
||||
<RowDefinition Height="270"></RowDefinition>
|
||||
<RowDefinition Height="270"></RowDefinition>
|
||||
<RowDefinition Height="200"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
||||
<Image Grid.Column="5" Grid.Row="1" x:Name="Dealer_Bild_1"/>
|
||||
<Image Grid.Column="7" Grid.Row="1" x:Name="Dealer_Bild_2"/>
|
||||
|
||||
<Button Grid.Row="0" Content="Hauptmenü" HorizontalAlignment="Center" Click="Hauptmenue" Width="100"/>
|
||||
<TextBox HorizontalAlignment="Right" Height="100" Grid.Row="4" TextWrapping="Wrap" Text="Einsatz" VerticalAlignment="Center" Width="192" PreviewTextInput="TextBox_OnPreviewTextInput" PreviewKeyDown="TextBox_OnPreviewKeyDown" DataObject.Pasting="TextBox_Pasting" Grid.Column="5" Grid.ColumnSpan="3" Margin="0,0,194,0"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -1,96 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Casino
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für Blackjack.xaml
|
||||
/// </summary>
|
||||
public partial class Blackjack : Window
|
||||
{
|
||||
public Blackjack()
|
||||
{
|
||||
InitializeComponent();
|
||||
rand();
|
||||
LoadCard(55);
|
||||
}
|
||||
|
||||
private void LoadCard(int Bild)
|
||||
{
|
||||
Database db = new Database();
|
||||
byte[] img = db.GetCardImage(Bild);//2-10
|
||||
|
||||
Dealer_Bild_1.Source = ByteArrayToImage(img);
|
||||
}
|
||||
|
||||
private BitmapImage ByteArrayToImage(byte[] bytes)
|
||||
{
|
||||
BitmapImage image = new BitmapImage();
|
||||
using (MemoryStream ms = new MemoryStream(bytes))
|
||||
{
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
image.StreamSource = ms;
|
||||
image.EndInit();
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
private int rand()
|
||||
{
|
||||
Random ran = new Random();
|
||||
int temp = ran.Next(13, 66);
|
||||
Console.WriteLine(temp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
private void Hauptmenue(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
//Numberfeld
|
||||
private static readonly Regex _regex = new Regex("[^0-9]"); // Regex to match non-numeric input
|
||||
|
||||
//nur nummern
|
||||
private void TextBox_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
e.Handled = !_regex.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
// Keine Spaces
|
||||
private void TextBox_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Space)
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
//das man nichts reinkopieren kann außer Zahlen
|
||||
private void TextBox_Pasting(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
if (e.DataObject.GetDataPresent(typeof(String)))
|
||||
{
|
||||
var text = (String)e.DataObject.GetData((typeof(String)));
|
||||
if (!_regex.IsMatch((string)text))
|
||||
{
|
||||
e.CancelCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+257
-55
@@ -5,87 +5,289 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Casino"
|
||||
mc:Ignorable="d"
|
||||
Title="Bus Driver" Height="1080" Width="1960"
|
||||
Title="Bus Fahrer"
|
||||
Height="1080"
|
||||
Width="1800"
|
||||
WindowState="Maximized"
|
||||
WindowStyle="None"
|
||||
Background="#2C3E50">
|
||||
Background="#195925">
|
||||
<!-- Lenard Gerdes -->
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="280"/>
|
||||
<ColumnDefinition Width="20"/>
|
||||
<ColumnDefinition Width="280"/>
|
||||
<ColumnDefinition Width="20"/>
|
||||
<ColumnDefinition Width="280"/>
|
||||
<ColumnDefinition Width="20"/>
|
||||
<ColumnDefinition Width="280"/>
|
||||
<ColumnDefinition Width="20"/>
|
||||
<ColumnDefinition Width="280"/>
|
||||
<ColumnDefinition Width="20"/>
|
||||
<ColumnDefinition Width="280"/>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="1*"></ColumnDefinition>
|
||||
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||
<ColumnDefinition Width="1*"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="70"/>
|
||||
<RowDefinition Height="270"/>
|
||||
<RowDefinition Height="270"/>
|
||||
<!-- Cards row -->
|
||||
<RowDefinition Height="270"/>
|
||||
<!-- Buttons row -->
|
||||
<RowDefinition Height="200"/>
|
||||
<RowDefinition Height="1*"></RowDefinition>
|
||||
<RowDefinition Height="200"></RowDefinition>
|
||||
<RowDefinition Height="200"></RowDefinition>
|
||||
<RowDefinition Height="200"></RowDefinition>
|
||||
<RowDefinition Height="1*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Main Menu Button top left -->
|
||||
<Button Grid.Column="0" Grid.Row="0" Content="Main Menu" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Hauptmenue" Width="100" Height="40"/>
|
||||
<Button Grid.Column="0"
|
||||
Grid.Row="0"
|
||||
Content="Main Menu"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Click="Hauptmenue"
|
||||
Width="100"
|
||||
Height="40"/>
|
||||
|
||||
<!-- CARDS (Row 2) -->
|
||||
<!-- Karten -->
|
||||
<Image Grid.Column="3" Grid.Row="2" x:Name="Bild_1" Margin="5" Stretch="Uniform"/>
|
||||
<Image Grid.Column="5" Grid.Row="2" x:Name="Bild_2" Margin="5" Stretch="Uniform"/>
|
||||
<Image Grid.Column="7" Grid.Row="2" x:Name="Bild_3" Margin="5" Stretch="Uniform"/>
|
||||
<Image Grid.Column="9" Grid.Row="2" x:Name="Bild_4" Margin="5" Stretch="Uniform"/>
|
||||
|
||||
<!-- BUTTONS BELOW CARDS (Row 3) -->
|
||||
<!-- Round 1: Red / Black -->
|
||||
<StackPanel x:Name="PanelRedBlack" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="7" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,20,0,0">
|
||||
<Button x:Name="BtnRed" Content="Red" Width="120" Height="50" Margin="10" Background="#E74C3C" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnRed_Click"/>
|
||||
<Button x:Name="BtnBlack" Content="Black" Width="120" Height="50" Margin="10" Background="#2C3E50" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnBlack_Click"/>
|
||||
<!-- Rot / Schwarz -->
|
||||
<StackPanel x:Name="PanelRedBlack"
|
||||
Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="7"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,20,0,0">
|
||||
|
||||
<Button Content="Red"
|
||||
Width="120"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#E74C3C"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="ColorButton_Click"
|
||||
Tag="Red"/>
|
||||
|
||||
<Button Content="Black"
|
||||
Width="120"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#2C3E50"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="ColorButton_Click"
|
||||
Tag="Black"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Round 2: Higher / Lower -->
|
||||
<StackPanel x:Name="PanelHigherLower" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="7" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,20,0,0" Visibility="Collapsed">
|
||||
<Button x:Name="BtnHigher" Content="Higher" Width="120" Height="50" Margin="10" Background="#2ECC71" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnHigher_Click"/>
|
||||
<Button x:Name="BtnLower" Content="Lower" Width="120" Height="50" Margin="10" Background="#E67E22" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnLower_Click"/>
|
||||
<!-- Höher / Niedriger -->
|
||||
<StackPanel x:Name="PanelHigherLower"
|
||||
Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="7"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,20,0,0"
|
||||
Visibility="Collapsed">
|
||||
|
||||
<Button Content="Higher"
|
||||
Width="120"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#2ECC71"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="HigherLowerButton_Click"
|
||||
Tag="Higher"/>
|
||||
|
||||
<Button Content="Lower"
|
||||
Width="120"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#E67E22"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="HigherLowerButton_Click"
|
||||
Tag="Lower"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Round 3: Inside / Outside -->
|
||||
<StackPanel x:Name="PanelInsideOutside" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="7" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,20,0,0" Visibility="Collapsed">
|
||||
<Button x:Name="BtnInside" Content="Inside" Width="130" Height="50" Margin="10" Background="#9B59B6" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnInside_Click"/>
|
||||
<Button x:Name="BtnOutside" Content="Outside" Width="130" Height="50" Margin="10" Background="#3498DB" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnOutside_Click"/>
|
||||
<!-- Innen / Außen -->
|
||||
<StackPanel x:Name="PanelInsideOutside"
|
||||
Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="7"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,20,0,0"
|
||||
Visibility="Collapsed">
|
||||
|
||||
<Button Content="Inside"
|
||||
Width="130"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#9B59B6"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="InsideOutsideButton_Click"
|
||||
Tag="Inside"/>
|
||||
|
||||
<Button Content="Outside"
|
||||
Width="130"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#3498DB"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="InsideOutsideButton_Click"
|
||||
Tag="Outside"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Round 4: Suit selection -->
|
||||
<StackPanel x:Name="PanelSuit" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="7" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,20,0,0" Visibility="Collapsed">
|
||||
<Button x:Name="BtnHearts" Content="♥ Hearts" Width="110" Height="50" Margin="5" Background="#E74C3C" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnSuit_Click" Tag="Hearts"/>
|
||||
<Button x:Name="BtnDiamonds" Content="♦ Diamonds" Width="110" Height="50" Margin="5" Background="#E74C3C" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnSuit_Click" Tag="Diamonds"/>
|
||||
<Button x:Name="BtnSpades" Content="♠ Spades" Width="110" Height="50" Margin="5" Background="#2C3E50" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnSuit_Click" Tag="Spades"/>
|
||||
<Button x:Name="BtnClubs" Content="♣ Clubs" Width="110" Height="50" Margin="5" Background="#2C3E50" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnSuit_Click" Tag="Clubs"/>
|
||||
<!-- Symbol -->
|
||||
<StackPanel x:Name="PanelSuit"
|
||||
Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="7"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,20,0,0"
|
||||
Visibility="Collapsed">
|
||||
|
||||
<Button Content="♥ Hearts"
|
||||
Width="110"
|
||||
Height="50"
|
||||
Margin="5"
|
||||
Background="#E74C3C"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnSuit_Click"
|
||||
Tag="Hearts"/>
|
||||
|
||||
<Button Content="♦ Diamonds"
|
||||
Width="110"
|
||||
Height="50"
|
||||
Margin="5"
|
||||
Background="#E74C3C"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnSuit_Click"
|
||||
Tag="Diamonds"/>
|
||||
|
||||
<Button Content="♠ Spades"
|
||||
Width="110"
|
||||
Height="50"
|
||||
Margin="5"
|
||||
Background="#2C3E50"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnSuit_Click"
|
||||
Tag="Spades"/>
|
||||
|
||||
<Button Content="♣ Clubs"
|
||||
Width="110"
|
||||
Height="50"
|
||||
Margin="5"
|
||||
Background="#2C3E50"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnSuit_Click"
|
||||
Tag="Clubs"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Cash Out / Start / Next Buttons -->
|
||||
<StackPanel Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="7" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,20">
|
||||
<Button x:Name="BtnCashOut" Content="Cash Out (0.00)" Width="180" Height="50" Margin="10" Background="#27AE60" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnCashOut_Click" Visibility="Collapsed"/>
|
||||
<Button x:Name="BtnStart" Content="Start New Game" Width="180" Height="50" Margin="10" Background="#1ABC9C" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnStart_Click"/>
|
||||
<!-- Cash Out / Start -->
|
||||
<StackPanel Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="7"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="0,0,0,20">
|
||||
|
||||
<Button x:Name="BtnCashOut"
|
||||
Content="Cash Out ($0.00)"
|
||||
Width="180"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#27AE60"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnCashOut_Click"
|
||||
Visibility="Collapsed"/>
|
||||
|
||||
<Button x:Name="BtnStart"
|
||||
Content="Start New Game"
|
||||
Width="180"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#1ABC9C"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnStart_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Bet Input and Current Win Text Display -->
|
||||
<StackPanel Grid.Column="5" Grid.ColumnSpan="3" Grid.Row="4" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock x:Name="Txteinsatztext" Text="Einsatz" Foreground="White" FontSize="14" HorizontalAlignment="Center" Margin="0,0,0,5"/>
|
||||
<TextBox x:Name="TxtBet" Height="40" Width="192" Background="DimGray" Foreground="White" FontSize="18" TextAlignment="Center" VerticalContentAlignment="Center" PreviewTextInput="TxtBet_PreviewTextInput" PreviewKeyDown="TxtBet_PreviewKeyDown" DataObject.Pasting="TxtBet_Pasting"/>
|
||||
<!-- Einsatz -->
|
||||
<StackPanel Grid.Column="5"
|
||||
Grid.ColumnSpan="3"
|
||||
Grid.Row="4"
|
||||
Orientation="Vertical"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
|
||||
<TextBlock x:Name="Txteinsatztext"
|
||||
Text="Einsatz"
|
||||
Foreground="White"
|
||||
FontSize="14"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,5"/>
|
||||
|
||||
<TextBox x:Name="TxtBet"
|
||||
Height="40"
|
||||
Width="192"
|
||||
Background="DimGray"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
TextAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
PreviewTextInput="TxtBet_PreviewTextInput"
|
||||
PreviewKeyDown="TxtBet_PreviewKeyDown"
|
||||
DataObject.Pasting="TxtBet_Pasting"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Column="11" Grid.Row="4" Text="Konto" Margin="0,108,0,-8" Foreground="White" FontSize="14" HorizontalAlignment="Center"/>
|
||||
<TextBlock x:Name="Konto" Grid.Column="11" Grid.Row="4" Height="30" Width="100" Margin="90,133,90,37" Background="DarkRed" Foreground="Silver" TextAlignment="Right" FontSize="25"/>
|
||||
|
||||
<!-- Konto -->
|
||||
<TextBlock Grid.Column="11"
|
||||
Grid.Row="4"
|
||||
Text="Konto"
|
||||
Margin="0,108,0,-8"
|
||||
Foreground="White"
|
||||
FontSize="14"
|
||||
HorizontalAlignment="Center"/>
|
||||
|
||||
<TextBlock x:Name="Konto"
|
||||
Grid.Column="11"
|
||||
Grid.Row="4"
|
||||
Height="30"
|
||||
Width="100"
|
||||
Background="DarkRed"
|
||||
Foreground="Silver"
|
||||
TextAlignment="Right"
|
||||
FontSize="25"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
+397
-155
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
@@ -14,7 +15,7 @@ namespace Casino
|
||||
{
|
||||
public partial class Busfahrer : Window
|
||||
{
|
||||
public class Card
|
||||
public class Card //Colin Langer
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string WertRaw { get; set; } = string.Empty;
|
||||
@@ -22,43 +23,42 @@ namespace Casino
|
||||
public ImageSource Image { get; set; } = null!;
|
||||
public int NumericValue { get; set; }
|
||||
|
||||
public bool IsRed => FarbeRaw.Equals("Hearts", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Diamonds", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Diamond", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Herz", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Karo", StringComparison.OrdinalIgnoreCase);
|
||||
public bool IsRed =>
|
||||
FarbeRaw.Equals("Hearts", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Diamond", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
//Colin Langer
|
||||
public Card(int id, string wert, string farbe, byte[] imgBytes)
|
||||
{
|
||||
Id = id;
|
||||
WertRaw = wert;
|
||||
FarbeRaw = farbe;
|
||||
NumericValue = ParseValue(wert);
|
||||
|
||||
if (imgBytes != null && imgBytes.Length > 0)
|
||||
{
|
||||
Image = ByteArrayToImage(imgBytes);
|
||||
}
|
||||
}
|
||||
|
||||
private int ParseValue(string wert)
|
||||
//Colin Langer
|
||||
//verwandelt den textwert in punktwert um
|
||||
private static int ParseValue(string wert)
|
||||
{
|
||||
return wert.Trim() switch
|
||||
{
|
||||
"Jack" => 11,
|
||||
"Bube" => 11,
|
||||
"Queen" => 12,
|
||||
"Dame" => 12,
|
||||
"King" => 13,
|
||||
"König" => 13,
|
||||
"Ace" => 14,
|
||||
"Ass" => 14,
|
||||
_ => int.TryParse(wert, out int v) ? v : 0
|
||||
_ => int.TryParse(wert, out int value) ? value : 0
|
||||
};
|
||||
}
|
||||
|
||||
//Colin Langer
|
||||
//konvertiert das Bild von der Datenbank um
|
||||
private static BitmapImage ByteArrayToImage(byte[] bytes)
|
||||
{
|
||||
BitmapImage image = new BitmapImage();
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(bytes))
|
||||
{
|
||||
image.BeginInit();
|
||||
@@ -66,224 +66,419 @@ namespace Casino
|
||||
image.StreamSource = ms;
|
||||
image.EndInit();
|
||||
}
|
||||
|
||||
image.Freeze();
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
public enum CardColor { Red, Black }
|
||||
private readonly Database db = new Database();
|
||||
private ObservableCollection<User> users;
|
||||
|
||||
private List<Card> deck = new();
|
||||
private List<Card> handCards = new();
|
||||
private List<Card> deck = new List<Card>();
|
||||
private List<Card> handCards = new List<Card>();
|
||||
private ImageSource cardBackImage = null!;
|
||||
Audioplayer music = new Audioplayer();
|
||||
|
||||
private int currentPhase = 0;
|
||||
private decimal currentBet = 0;
|
||||
private decimal currentProfit = 0;
|
||||
|
||||
private Database db = new Database();
|
||||
private ObservableCollection<User> users;
|
||||
private bool roundRunning = false;
|
||||
|
||||
public Busfahrer()
|
||||
{
|
||||
InitializeComponent();
|
||||
users = db.GetUser();
|
||||
|
||||
users = db.GetUser();
|
||||
UpdateAccountDisplay();
|
||||
StartNewGame();
|
||||
|
||||
ShowWaitingState();
|
||||
music.PlayLoopingSound_2(db.GetSound(20));
|
||||
}
|
||||
|
||||
private User CurrentUser => users[MainWindow.currentUser];
|
||||
|
||||
// Lenard Gerdes
|
||||
private void UpdateAccountDisplay()
|
||||
{
|
||||
users = db.GetUser();
|
||||
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||
Konto.Text = CurrentUser.Geld.ToString();
|
||||
}
|
||||
|
||||
// Lenard Gerdes
|
||||
private void SaveAccount()
|
||||
{
|
||||
db.UpdateGeld(CurrentUser.ID, CurrentUser.Geld);
|
||||
UpdateAccountDisplay();
|
||||
}
|
||||
//Colin Langer
|
||||
private void BtnStart_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
StartNewGame();
|
||||
StartGameFromInput();
|
||||
}
|
||||
//Colin Langer
|
||||
private void StartGameFromInput()
|
||||
{
|
||||
if (roundRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//Prüfen die eingabe
|
||||
if (!int.TryParse(TxtBet.Text, out int bet) || bet <= 0)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Bitte gib einen gültigen Einsatz ein.",
|
||||
"Ungültiger Einsatz",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void StartNewGame()
|
||||
if (bet > CurrentUser.Geld)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Du hast nicht genug Geld für diesen Einsatz.",
|
||||
"Zu wenig Geld",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
decimal currentgeld = users[MainWindow.currentUser].Geld;
|
||||
return;
|
||||
}
|
||||
|
||||
currentBet = bet;
|
||||
StartRound();
|
||||
}
|
||||
//Colin Langer
|
||||
private void StartRound()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (currentBet <= 0 || currentBet > CurrentUser.Geld)
|
||||
{
|
||||
ShowWaitingState();
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. Einsatz sofort auf dem Konto abziehen & in der Datenbank speichern
|
||||
currentgeld -= Convert.ToInt32(currentBet);
|
||||
db.UpdateGeld(users[MainWindow.currentUser].ID, currentgeld);
|
||||
UpdateAccountDisplay();
|
||||
CurrentUser.Geld -= Convert.ToInt32(currentBet);
|
||||
SaveAccount();
|
||||
|
||||
currentProfit = 0;
|
||||
UpdateWinDisplay();
|
||||
currentPhase = 0;
|
||||
roundRunning = true;
|
||||
TxtBet.IsEnabled = false;
|
||||
|
||||
LoadCards();
|
||||
UpdateHandUI();
|
||||
UpdateWinDisplay();
|
||||
SetPhaseUI();
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Bitte ein Betrag eingeben",
|
||||
"Fehlermeldung 101",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
//Colin Langer
|
||||
// lädt und mischt die karten aus der datenbank
|
||||
private void LoadCards()
|
||||
{
|
||||
deck = db.GetAllCards()
|
||||
.OrderBy(_ => Random.Shared.Next())
|
||||
.ToList();
|
||||
|
||||
deck = db.GetAllCards();
|
||||
byte[] backBytes = db.GetCardBackImage();
|
||||
|
||||
if (backBytes != null)
|
||||
if (backBytes != null && backBytes.Length > 0)
|
||||
{
|
||||
cardBackImage = ByteArrayToImage(backBytes);
|
||||
}
|
||||
|
||||
Random ran = new Random();
|
||||
deck = deck.OrderBy(_ => ran.Next()).ToList();
|
||||
|
||||
handCards.Clear();
|
||||
currentPhase = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (deck.Count > 0)
|
||||
for (int i = 0; i < 4 && deck.Count > 0; i++)
|
||||
{
|
||||
handCards.Add(DrawCard());
|
||||
}
|
||||
}
|
||||
|
||||
UpdateHandUI();
|
||||
SetPhaseUI();
|
||||
}
|
||||
|
||||
//Colin Langer
|
||||
// nimmt die oberste karte
|
||||
private Card DrawCard()
|
||||
{
|
||||
var card = deck[0];
|
||||
Card card = deck[0];
|
||||
deck.RemoveAt(0);
|
||||
return card;
|
||||
}
|
||||
|
||||
//Colin Langer
|
||||
private void UpdateHandUI()
|
||||
{
|
||||
Bild_1.Source = (currentPhase > 0) ? handCards[0].Image : cardBackImage;
|
||||
Bild_2.Source = (currentPhase > 1) ? handCards[1].Image : cardBackImage;
|
||||
Bild_3.Source = (currentPhase > 2) ? handCards[2].Image : cardBackImage;
|
||||
Bild_4.Source = (currentPhase > 3) ? handCards[3].Image : cardBackImage;
|
||||
Bild_1.Source = cardBackImage;
|
||||
Bild_2.Source = cardBackImage;
|
||||
Bild_3.Source = cardBackImage;
|
||||
Bild_4.Source = cardBackImage;
|
||||
|
||||
if (handCards.Count < 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentPhase >= 1)
|
||||
{
|
||||
Bild_1.Source = handCards[0].Image;
|
||||
}
|
||||
|
||||
if (currentPhase >= 2)
|
||||
{
|
||||
Bild_2.Source = handCards[1].Image;
|
||||
}
|
||||
|
||||
if (currentPhase >= 3)
|
||||
{
|
||||
Bild_3.Source = handCards[2].Image;
|
||||
}
|
||||
|
||||
if (currentPhase >= 4)
|
||||
{
|
||||
Bild_4.Source = handCards[3].Image;
|
||||
}
|
||||
}
|
||||
//Colin Langer
|
||||
// dreht die karten je nach runde um
|
||||
private void RevealCurrentCard()
|
||||
{
|
||||
if (handCards.Count < 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (currentPhase)
|
||||
{
|
||||
case 0: Bild_1.Source = handCards[0].Image; break;
|
||||
case 1: Bild_2.Source = handCards[1].Image; break;
|
||||
case 2: Bild_3.Source = handCards[2].Image; break;
|
||||
case 3: Bild_4.Source = handCards[3].Image; break;
|
||||
case 0:
|
||||
Bild_1.Source = handCards[0].Image;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
Bild_2.Source = handCards[1].Image;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
Bild_3.Source = handCards[2].Image;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
Bild_4.Source = handCards[3].Image;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessGuess(bool success)
|
||||
// Lenard Gerdes
|
||||
private async Task ProcessGuessAsync(bool success)
|
||||
{
|
||||
if (!roundRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RevealCurrentCard();
|
||||
|
||||
if (!success)
|
||||
{
|
||||
RevealCurrentCard();
|
||||
roundRunning = false;
|
||||
currentProfit = 0;
|
||||
UpdateWinDisplay();
|
||||
SetPhaseUI();
|
||||
StartNewGame();
|
||||
|
||||
await Task.Delay(100);
|
||||
|
||||
// Nächste Runde mit demselben Einsatz
|
||||
if (currentBet <= CurrentUser.Geld)
|
||||
{
|
||||
StartRound();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowWaitingState();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
currentPhase++;
|
||||
switch (currentPhase)
|
||||
{
|
||||
case 1: currentProfit = currentBet * 1.75m; break;
|
||||
case 2: currentProfit = currentBet * 2.5m; break;
|
||||
case 3: currentProfit = currentBet * 5.0m; break;
|
||||
case 4: currentProfit = currentBet * 20.0m; break;
|
||||
}
|
||||
currentProfit = CalculateCurrentProfit();
|
||||
|
||||
UpdateWinDisplay();
|
||||
UpdateHandUI();
|
||||
UpdateWinDisplay();
|
||||
SetPhaseUI();
|
||||
|
||||
// Automatische Auszahlung bei Gewinn von Runde 4
|
||||
if (currentPhase == 4)
|
||||
{
|
||||
var currentUser = users[MainWindow.currentUser];
|
||||
currentUser.Geld += Convert.ToInt32(currentProfit);
|
||||
db.UpdateGeld(currentUser.ID, currentUser.Geld);
|
||||
UpdateAccountDisplay();
|
||||
roundRunning = false;
|
||||
|
||||
}
|
||||
}
|
||||
PayoutCurrentProfit();
|
||||
|
||||
private void UpdateWinDisplay()
|
||||
await Task.Delay(100);
|
||||
|
||||
if (currentBet <= CurrentUser.Geld)
|
||||
{
|
||||
BtnCashOut.Content = $"Cash Out (${currentProfit:F2})";
|
||||
StartRound();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowWaitingState();
|
||||
}
|
||||
}
|
||||
}
|
||||
//Colin Langer
|
||||
private decimal CalculateCurrentProfit()
|
||||
{
|
||||
return currentPhase switch
|
||||
{
|
||||
1 => currentBet * 1.75m,
|
||||
2 => currentBet * 2.5m,
|
||||
3 => currentBet * 5.0m,
|
||||
4 => currentBet * 20.0m,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
//Colin Langer
|
||||
// passt die buttons an je nach runde
|
||||
private async void ColorButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button button)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// CASH OUT BUTTON
|
||||
CardColor chosenColor =
|
||||
button.Tag?.ToString() == "Red"
|
||||
? CardColor.Red
|
||||
: CardColor.Black;
|
||||
|
||||
Card card = handCards[0];
|
||||
|
||||
bool success =
|
||||
chosenColor == CardColor.Red
|
||||
? card.IsRed
|
||||
: !card.IsRed;
|
||||
|
||||
await ProcessGuessAsync(success);
|
||||
}
|
||||
//Colin Langer
|
||||
private async void HigherLowerButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button button)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool higher = button.Tag?.ToString() == "Higher";
|
||||
|
||||
Card firstCard = handCards[0];
|
||||
Card secondCard = handCards[1];
|
||||
|
||||
bool success = higher
|
||||
? secondCard.NumericValue > firstCard.NumericValue
|
||||
: secondCard.NumericValue < firstCard.NumericValue;
|
||||
|
||||
await ProcessGuessAsync(success);
|
||||
}
|
||||
//Colin Langer
|
||||
private async void InsideOutsideButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button button)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool inside = button.Tag?.ToString() == "Inside";
|
||||
|
||||
int firstValue = handCards[0].NumericValue;
|
||||
int secondValue = handCards[1].NumericValue;
|
||||
int thirdValue = handCards[2].NumericValue;
|
||||
|
||||
int min = Math.Min(firstValue, secondValue);
|
||||
int max = Math.Max(firstValue, secondValue);
|
||||
|
||||
bool isBetween = thirdValue > min && thirdValue < max;
|
||||
bool success = inside ? isBetween : !isBetween;
|
||||
|
||||
await ProcessGuessAsync(success);
|
||||
}
|
||||
//Colin Langer
|
||||
private async void BtnSuit_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button button || button.Tag == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string chosenSuit = button.Tag.ToString()!;
|
||||
Card card = handCards[3];
|
||||
|
||||
bool success = IsSameSuit(card.FarbeRaw, chosenSuit);
|
||||
|
||||
await ProcessGuessAsync(success);
|
||||
}
|
||||
//Colin Langer
|
||||
private static bool IsSameSuit(string cardSuit, string chosenSuit)
|
||||
{
|
||||
if (cardSuit.Equals(chosenSuit, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return chosenSuit switch
|
||||
{
|
||||
"Hearts" => cardSuit.Equals("Hearts", StringComparison.OrdinalIgnoreCase),
|
||||
"Diamonds" => cardSuit.Equals("Diamond", StringComparison.OrdinalIgnoreCase),
|
||||
"Spades" => cardSuit.Equals("Spades", StringComparison.OrdinalIgnoreCase),
|
||||
"Clubs" => cardSuit.Equals("Clubs", StringComparison.OrdinalIgnoreCase),
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
//Colin Langer
|
||||
private enum CardColor
|
||||
{
|
||||
Red,
|
||||
Black
|
||||
}
|
||||
//Colin Langer
|
||||
private void BtnCashOut_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (currentProfit > 0)
|
||||
if (!roundRunning || currentProfit <= 0)
|
||||
{
|
||||
var currentUser = users[MainWindow.currentUser];
|
||||
currentUser.Geld += Convert.ToInt32(currentProfit);
|
||||
db.UpdateGeld(currentUser.ID, currentUser.Geld);
|
||||
UpdateAccountDisplay();
|
||||
|
||||
MessageBox.Show($"Du hast dir ${currentProfit:F2} auszahlen lassen!", "Cash Out", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
currentProfit = 0;
|
||||
UpdateWinDisplay();
|
||||
SetPhaseUI();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// RUNDEN BUTTONS
|
||||
private void BtnRed_Click(object sender, RoutedEventArgs e) => GuessColor(CardColor.Red);
|
||||
private void BtnBlack_Click(object sender, RoutedEventArgs e) => GuessColor(CardColor.Black);
|
||||
roundRunning = false;
|
||||
|
||||
private void GuessColor(CardColor chosenColor)
|
||||
decimal payout = currentProfit;
|
||||
PayoutCurrentProfit();
|
||||
|
||||
MessageBox.Show(
|
||||
$"Du hast ${payout:F2} ausgezahlt bekommen!",
|
||||
"Cash Out",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
|
||||
ShowWaitingState();
|
||||
}
|
||||
//Colin Langer
|
||||
private void PayoutCurrentProfit()
|
||||
{
|
||||
Card targetCard = handCards[0];
|
||||
bool ok = (chosenColor == CardColor.Red && targetCard.IsRed) ||
|
||||
(chosenColor == CardColor.Black && !targetCard.IsRed);
|
||||
ProcessGuess(ok);
|
||||
}
|
||||
|
||||
private void BtnHigher_Click(object sender, RoutedEventArgs e) => GuessHigherLower(true);
|
||||
private void BtnLower_Click(object sender, RoutedEventArgs e) => GuessHigherLower(false);
|
||||
|
||||
private void GuessHigherLower(bool higher)
|
||||
if (currentProfit <= 0)
|
||||
{
|
||||
Card card1 = handCards[0];
|
||||
Card card2 = handCards[1];
|
||||
|
||||
bool ok = higher ? card2.NumericValue > card1.NumericValue : card2.NumericValue < card1.NumericValue;
|
||||
ProcessGuess(ok);
|
||||
return;
|
||||
}
|
||||
|
||||
private void BtnInside_Click(object sender, RoutedEventArgs e) => GuessInside(true);
|
||||
private void BtnOutside_Click(object sender, RoutedEventArgs e) => GuessInside(false);
|
||||
|
||||
private void GuessInside(bool inside)
|
||||
{
|
||||
Card card3 = handCards[2];
|
||||
int min = Math.Min(handCards[0].NumericValue, handCards[1].NumericValue);
|
||||
int max = Math.Max(handCards[0].NumericValue, handCards[1].NumericValue);
|
||||
|
||||
bool isBetween = card3.NumericValue > min && card3.NumericValue < max;
|
||||
bool ok = inside ? isBetween : !isBetween;
|
||||
ProcessGuess(ok);
|
||||
}
|
||||
|
||||
private void BtnSuit_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button btn && btn.Tag != null)
|
||||
{
|
||||
string chosenSuit = btn.Tag.ToString()!;
|
||||
Card card4 = handCards[3];
|
||||
|
||||
bool ok = card4.FarbeRaw.Equals(chosenSuit, StringComparison.OrdinalIgnoreCase) ||
|
||||
(chosenSuit.Equals("Hearts", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Herz", StringComparison.OrdinalIgnoreCase)) ||
|
||||
(chosenSuit.Equals("Diamonds", StringComparison.OrdinalIgnoreCase) && (card4.FarbeRaw.Equals("Karo", StringComparison.OrdinalIgnoreCase) || card4.FarbeRaw.Equals("Diamond", StringComparison.OrdinalIgnoreCase))) ||
|
||||
(chosenSuit.Equals("Spades", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Pik", StringComparison.OrdinalIgnoreCase)) ||
|
||||
(chosenSuit.Equals("Clubs", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Kreuz", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
ProcessGuess(ok);
|
||||
}
|
||||
CurrentUser.Geld += Convert.ToInt32(currentProfit);
|
||||
SaveAccount();
|
||||
}
|
||||
|
||||
//Colin Langer
|
||||
// blendet die buttons der jewaligen runde ein
|
||||
private void SetPhaseUI()
|
||||
{
|
||||
PanelRedBlack.Visibility = Visibility.Collapsed;
|
||||
@@ -291,27 +486,67 @@ namespace Casino
|
||||
PanelInsideOutside.Visibility = Visibility.Collapsed;
|
||||
PanelSuit.Visibility = Visibility.Collapsed;
|
||||
|
||||
BtnCashOut.Visibility = Visibility.Collapsed;
|
||||
BtnStart.Visibility = Visibility.Collapsed;
|
||||
|
||||
if (!roundRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (currentPhase)
|
||||
{
|
||||
case 0: PanelRedBlack.Visibility = Visibility.Visible; break;
|
||||
case 1: PanelHigherLower.Visibility = Visibility.Visible; BtnCashOut.Visibility = Visibility.Visible;break;
|
||||
case 2: PanelInsideOutside.Visibility = Visibility.Visible; break;
|
||||
case 3: PanelSuit.Visibility = Visibility.Visible; break;
|
||||
}
|
||||
}
|
||||
case 0:
|
||||
PanelRedBlack.Visibility = Visibility.Visible;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
PanelHigherLower.Visibility = Visibility.Visible;
|
||||
BtnCashOut.Visibility = Visibility.Visible;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
PanelInsideOutside.Visibility = Visibility.Visible;
|
||||
BtnCashOut.Visibility = Visibility.Visible;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
PanelSuit.Visibility = Visibility.Visible;
|
||||
BtnCashOut.Visibility = Visibility.Visible;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Colin Langer
|
||||
// wartet kurz falls ein neuer einsatz eingegeben wird
|
||||
private void ShowWaitingState()
|
||||
{
|
||||
roundRunning = false;
|
||||
currentPhase = 0;
|
||||
currentProfit = 0;
|
||||
|
||||
UpdateWinDisplay();
|
||||
SetPhaseUI();
|
||||
|
||||
BtnStart.Visibility = Visibility.Visible;
|
||||
TxtBet.IsEnabled = true;
|
||||
}
|
||||
//Colin Langer
|
||||
private void UpdateWinDisplay()
|
||||
{
|
||||
BtnCashOut.Content = $"Cash Out (${currentProfit:F2})";
|
||||
}
|
||||
//Colin Langer
|
||||
private void Hauptmenue(object sender, RoutedEventArgs e)
|
||||
{
|
||||
music.Stop();
|
||||
Close();
|
||||
}
|
||||
|
||||
//Colin Langer
|
||||
// verwandelt das bild aus der datenbank um in eine bild für die oberfläche
|
||||
private static BitmapImage ByteArrayToImage(byte[] bytes)
|
||||
{
|
||||
if (bytes == null || bytes.Length == 0) return null!;
|
||||
|
||||
BitmapImage image = new BitmapImage();
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(bytes))
|
||||
{
|
||||
image.BeginInit();
|
||||
@@ -319,18 +554,21 @@ namespace Casino
|
||||
image.StreamSource = ms;
|
||||
image.EndInit();
|
||||
}
|
||||
|
||||
image.Freeze();
|
||||
return image;
|
||||
}
|
||||
// =======================
|
||||
// NUMBER FIELD VALIDATION
|
||||
// =======================
|
||||
|
||||
private static readonly Regex _regex = new Regex("^[0-9]");
|
||||
// =========================
|
||||
// EINSATZFELD Colin Langer
|
||||
// =========================
|
||||
// In Slots ist die erklärung drin
|
||||
|
||||
private static readonly Regex NumberRegex = new Regex("^[0-9]+$");
|
||||
|
||||
private void TxtBet_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
e.Handled = !_regex.IsMatch(e.Text);
|
||||
e.Handled = !NumberRegex.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
private void TxtBet_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||
@@ -343,14 +581,18 @@ namespace Casino
|
||||
|
||||
private void TxtBet_Pasting(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
if (e.DataObject.GetDataPresent(typeof(String)))
|
||||
if (!e.DataObject.GetDataPresent(typeof(string)))
|
||||
{
|
||||
var text = (String)e.DataObject.GetData(typeof(String));
|
||||
if (!_regex.IsMatch((string)text))
|
||||
e.CancelCommand();
|
||||
return;
|
||||
}
|
||||
|
||||
string text = (string)e.DataObject.GetData(typeof(string));
|
||||
|
||||
if (!NumberRegex.IsMatch(text))
|
||||
{
|
||||
e.CancelCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
+146
-3
@@ -5,6 +5,7 @@ using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace Casino
|
||||
@@ -16,6 +17,7 @@ namespace Casino
|
||||
{
|
||||
ObservableCollection<User> user = new ObservableCollection<User>();
|
||||
|
||||
//Lenard Gerdes
|
||||
try
|
||||
{
|
||||
MySql.Data.MySqlClient.MySqlConnection myConnection;
|
||||
@@ -40,7 +42,8 @@ namespace Casino
|
||||
Name = myReader.GetString("name"),
|
||||
Alter = myReader.GetInt32("age"),
|
||||
Passwort = myReader.GetString("passwort"),
|
||||
Geld = myReader.GetInt32("geld")
|
||||
Geld = myReader.GetDecimal("geld"),
|
||||
Rolle = myReader.GetString("Rolle")
|
||||
};
|
||||
|
||||
user.Add(u);
|
||||
@@ -57,6 +60,32 @@ namespace Casino
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
public void InsertUser(User user)
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(myConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand(
|
||||
@"INSERT INTO Nutzer
|
||||
(id, name, age, passwort, geld)
|
||||
VALUES
|
||||
(@id, @name, @alter, @passwort, @geld)",
|
||||
conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@id", user.ID);
|
||||
cmd.Parameters.AddWithValue("@name", user.Name);
|
||||
cmd.Parameters.AddWithValue("@alter", user.Alter);
|
||||
cmd.Parameters.AddWithValue("@passwort", user.Passwort);
|
||||
cmd.Parameters.AddWithValue("@geld", user.Geld);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Colin Langer
|
||||
public byte[] GetCardImage(int id)
|
||||
{
|
||||
byte[] imageBytes = null;
|
||||
@@ -80,7 +109,7 @@ namespace Casino
|
||||
|
||||
return imageBytes;
|
||||
}
|
||||
|
||||
//Cloin Langer
|
||||
public List<Busfahrer.Card> GetAllCards()
|
||||
{
|
||||
var cards = new List<Busfahrer.Card>();
|
||||
@@ -110,7 +139,7 @@ namespace Casino
|
||||
return cards;
|
||||
}
|
||||
|
||||
// NEU: Holt das Bild der Kartenrückseite
|
||||
// Holt das Bild der Kartenrückseite Colin Langer
|
||||
public byte[] GetCardBackImage()
|
||||
{
|
||||
byte[] imageBytes = null;
|
||||
@@ -174,5 +203,119 @@ namespace Casino
|
||||
}
|
||||
}
|
||||
|
||||
public bool SelectAdmin(string userId)
|
||||
{
|
||||
using MySqlConnection connection = new MySqlConnection(myConnectionString);
|
||||
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
string sql = @"
|
||||
SELECT COUNT(*)
|
||||
FROM Nutzer
|
||||
WHERE id = @id
|
||||
AND Rolle = 'Admin'";
|
||||
|
||||
using MySqlCommand command = new MySqlCommand(sql, connection);
|
||||
|
||||
command.Parameters.AddWithValue("@id", userId);
|
||||
|
||||
int count = Convert.ToInt32(command.ExecuteScalar());
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Fehler bei der Admin-Abfrage:\n" + ex.Message,
|
||||
"Datenbankfehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DeleteUser(string userId)
|
||||
{
|
||||
using MySqlConnection connection = new MySqlConnection(myConnectionString);
|
||||
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
string sql = @"
|
||||
DELETE FROM Nutzer
|
||||
WHERE id = @id";
|
||||
|
||||
using MySqlCommand command = new MySqlCommand(sql, connection);
|
||||
|
||||
command.Parameters.AddWithValue("@id", userId);
|
||||
|
||||
int affectedRows = command.ExecuteNonQuery();
|
||||
|
||||
return affectedRows > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Fehler beim Löschen des Benutzers:\n" + ex.Message,
|
||||
"Datenbankfehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdateUser(
|
||||
string userId,
|
||||
string name,
|
||||
int age,
|
||||
string passwort,
|
||||
decimal geld,
|
||||
string rolle)
|
||||
{
|
||||
using MySqlConnection connection = new MySqlConnection(myConnectionString);
|
||||
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
string sql = @"
|
||||
UPDATE Nutzer
|
||||
SET name = @name,
|
||||
age = @age,
|
||||
passwort = @passwort,
|
||||
geld = @geld,
|
||||
Rolle = @rolle
|
||||
WHERE id = @id";
|
||||
|
||||
using MySqlCommand command = new MySqlCommand(sql, connection);
|
||||
|
||||
command.Parameters.AddWithValue("@name", name);
|
||||
command.Parameters.AddWithValue("@age", age);
|
||||
command.Parameters.AddWithValue("@passwort", passwort);
|
||||
command.Parameters.AddWithValue("@geld", geld);
|
||||
command.Parameters.AddWithValue("@rolle", rolle);
|
||||
command.Parameters.AddWithValue("@id", userId);
|
||||
|
||||
int affectedRows = command.ExecuteNonQuery();
|
||||
|
||||
return affectedRows > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Fehler beim Aktualisieren des Benutzers:\n" + ex.Message,
|
||||
"Datenbankfehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Casino
|
||||
{
|
||||
internal class Decks
|
||||
{
|
||||
int Deckid { get; set; }
|
||||
int Kartenid { get; set; }
|
||||
string name { get; set; }
|
||||
|
||||
public Decks(int d, int k, string n)
|
||||
{
|
||||
Deckid = d;
|
||||
Kartenid = k;
|
||||
name = n;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<Window x:Class="Casino.EditUserView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Benutzer bearbeiten"
|
||||
Height="550"
|
||||
Width="500"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<!-- Lenard Gerdes -->
|
||||
|
||||
<Grid Margin="25">
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="Benutzer bearbeiten"
|
||||
FontSize="28"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,25"/>
|
||||
|
||||
<StackPanel Grid.Row="1"
|
||||
Margin="0,5">
|
||||
|
||||
<TextBlock Text="Name"
|
||||
FontWeight="Bold"/>
|
||||
|
||||
<TextBox x:Name="TxtName"
|
||||
Height="35"/>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="2"
|
||||
Margin="0,5">
|
||||
|
||||
<TextBlock Text="Alter"
|
||||
FontWeight="Bold"/>
|
||||
|
||||
<TextBox x:Name="TxtAge"
|
||||
Height="35"/>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="3"
|
||||
Margin="0,5">
|
||||
|
||||
<TextBlock Text="Neues Passwort"
|
||||
FontWeight="Bold"/>
|
||||
|
||||
<PasswordBox x:Name="TxtPasswort"
|
||||
Height="35"/>
|
||||
|
||||
<TextBlock Text="Leer lassen = Passwort nicht ändern"
|
||||
FontSize="12"
|
||||
Foreground="Gray"/>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="4"
|
||||
Margin="0,5">
|
||||
|
||||
<TextBlock Text="Geld"
|
||||
FontWeight="Bold"/>
|
||||
|
||||
<TextBox x:Name="TxtGeld"
|
||||
Height="35"/>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="5"
|
||||
Margin="0,5">
|
||||
|
||||
<TextBlock Text="Rolle"
|
||||
FontWeight="Bold"/>
|
||||
|
||||
<ComboBox x:Name="CmbRolle"
|
||||
Height="35">
|
||||
|
||||
<ComboBoxItem Content="User"/>
|
||||
<ComboBoxItem Content="Admin"/>
|
||||
|
||||
</ComboBox>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="6"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="0,25,0,0">
|
||||
|
||||
<Button Content="Speichern"
|
||||
Width="140"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="BtnSpeichern_Click"/>
|
||||
|
||||
<Button Content="Abbrechen"
|
||||
Width="140"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="BtnAbbrechen_Click"/>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Casino
|
||||
{
|
||||
public partial class EditUserView : Window
|
||||
{
|
||||
private readonly Database db = new Database();
|
||||
|
||||
private readonly User selectedUser;
|
||||
|
||||
public EditUserView(User user)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
selectedUser = user;
|
||||
|
||||
// Bestehende Werte anzeigen
|
||||
TxtName.Text = selectedUser.Name;
|
||||
TxtAge.Text = selectedUser.Alter.ToString();
|
||||
TxtGeld.Text = selectedUser.Geld.ToString();
|
||||
|
||||
// Rolle auswählen
|
||||
foreach (ComboBoxItem item in CmbRolle.Items)
|
||||
{
|
||||
if (item.Content?.ToString() == selectedUser.Rolle)
|
||||
{
|
||||
CmbRolle.SelectedItem = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnSpeichern_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(TxtName.Text))
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Bitte gib einen Namen ein.",
|
||||
"Fehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Alter prüfen
|
||||
if (!int.TryParse(TxtAge.Text, out int age) ||
|
||||
age < 0 ||
|
||||
age > 150)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Bitte gib ein gültiges Alter ein.",
|
||||
"Fehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Geld prüfen
|
||||
if (!decimal.TryParse(TxtGeld.Text, out decimal geld))
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Bitte gib einen gültigen Geldbetrag ein.",
|
||||
"Fehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (CmbRolle.SelectedItem is not ComboBoxItem selectedRoleItem)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Bitte wähle eine Rolle aus.",
|
||||
"Fehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
string rolle = selectedRoleItem.Content?.ToString() ?? "User";
|
||||
|
||||
// Passwort:
|
||||
// leer = altes Passwort behalten
|
||||
string passwort = selectedUser.Passwort;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(TxtPasswort.Password))
|
||||
{
|
||||
passwort = HashPassword(TxtPasswort.Password);
|
||||
}
|
||||
|
||||
// Datenbank aktualisieren
|
||||
bool success = db.UpdateUser(
|
||||
selectedUser.ID,
|
||||
TxtName.Text.Trim(),
|
||||
age,
|
||||
passwort,
|
||||
geld,
|
||||
rolle);
|
||||
|
||||
if (success)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Benutzer wurde erfolgreich aktualisiert.",
|
||||
"Erfolgreich",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Die Änderungen konnten nicht gespeichert werden.",
|
||||
"Fehler",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnAbbrechen_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private static string HashPassword(string password)
|
||||
{
|
||||
using SHA256 sha256 = SHA256.Create();
|
||||
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(password);
|
||||
byte[] hash = sha256.ComputeHash(bytes);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
foreach (byte b in hash)
|
||||
{
|
||||
builder.Append(b.ToString("X2"));
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -12,8 +12,9 @@
|
||||
Background="Transparent"
|
||||
AllowsTransparency="True"
|
||||
MouseDown="Window_MouseDown">
|
||||
<!-- Lenard Gerdes -->
|
||||
|
||||
<Border CornerRadius="50"
|
||||
<Border CornerRadius="20"
|
||||
Background="#590D00"
|
||||
BorderBrush="Gold"
|
||||
BorderThickness="5">
|
||||
@@ -31,7 +32,9 @@
|
||||
<Label Content="Passwort" FontSize="18" FontWeight="SemiBold" FontFamily="Palatino Linotype" Foreground="DarkGray"/>
|
||||
<PasswordBox x:Name="TxtPasswort" Margin="0,0,0,10" Background="#BD9208" />
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Content="Neues Konto" Width="80" Click="Erstellen_Click" Background="#BD9208" FontFamily="Palatino Linotype" FontWeight="SemiBold" Margin="0,0,100,0"/>
|
||||
<Button Content="Anmelden" Width="80" Click="Anmelden_Click" Background="#BD9208" FontFamily="Palatino Linotype" FontWeight="SemiBold"/>
|
||||
|
||||
</StackPanel>
|
||||
<MediaElement Name="player"
|
||||
LoadedBehavior="Manual"
|
||||
|
||||
+45
-6
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@@ -13,8 +15,8 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Xml.Linq;
|
||||
using Mysqlx.Cursor;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
|
||||
namespace Casino
|
||||
@@ -24,11 +26,15 @@ namespace Casino
|
||||
/// </summary>
|
||||
public partial class Login : Window
|
||||
{
|
||||
//Alles von Lenard Gerdes
|
||||
Database db = new Database();
|
||||
ObservableCollection<User> users = new ObservableCollection<User>();
|
||||
|
||||
|
||||
public Login()
|
||||
{
|
||||
InitializeComponent();
|
||||
Console.WriteLine(HashPassword("Mast"));
|
||||
users = db.GetUser();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +43,19 @@ namespace Casino
|
||||
{
|
||||
if (checkLogin(TxtName.Text, TxtPasswort.Password))
|
||||
{
|
||||
|
||||
Console.WriteLine(users[MainWindow.currentUser].Rolle);
|
||||
if (users[MainWindow.currentUser].Rolle.Equals("Admin"))
|
||||
{
|
||||
AdminView adminView = new AdminView();
|
||||
adminView.Show();
|
||||
Close();
|
||||
}else
|
||||
{
|
||||
MainWindow mainWindow = new MainWindow();
|
||||
mainWindow.Show();
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
@@ -51,9 +66,7 @@ namespace Casino
|
||||
|
||||
private bool checkLogin(string name, string passwort)
|
||||
{
|
||||
Database db = new Database();
|
||||
ObservableCollection<User> users = new ObservableCollection<User>();
|
||||
users = db.GetUser();
|
||||
|
||||
string hash = HashPassword(passwort);
|
||||
|
||||
for (int i = 0; i < users.Count(); i++)
|
||||
@@ -89,5 +102,31 @@ namespace Casino
|
||||
return Convert.ToHexString(hash);
|
||||
}
|
||||
}
|
||||
|
||||
private void Erstellen_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Database db = new Database();
|
||||
ObservableCollection<User> users = new ObservableCollection<User>();
|
||||
users = db.GetUser();
|
||||
string hash = HashPassword(TxtPasswort.Password);
|
||||
|
||||
for (int i = 0; i < users.Count(); i++)
|
||||
{
|
||||
if (users[i].Name.Equals(TxtName))
|
||||
{
|
||||
return;
|
||||
} else
|
||||
{
|
||||
User NewUser = new User(TxtName.Text, 18, hash);
|
||||
db.InsertUser(NewUser);
|
||||
TxtName.Text = "";
|
||||
TxtPasswort.Password = "";
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
-5
@@ -7,8 +7,8 @@
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Background="Transparent">
|
||||
|
||||
>
|
||||
<!-- Lenard Gerdes -->
|
||||
|
||||
<Border
|
||||
|
||||
@@ -17,10 +17,25 @@
|
||||
BorderThickness="5">
|
||||
|
||||
<Grid>
|
||||
<Button Content="Slots" HorizontalAlignment="Left" Height="39" Margin="65,114,0,0" VerticalAlignment="Top" Width="93" Click="Slots_Click"/>
|
||||
<Button Content="Blackjack" HorizontalAlignment="Left" Margin="221,114,0,0" VerticalAlignment="Top" Height="40" Width="79" Click="Blackjack_Click"/>
|
||||
<Button Content="Busfahrer" HorizontalAlignment="Left" Margin="221,193,0,0" VerticalAlignment="Top" Height="40" Width="79" Click="Busfahrer_Click"/>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
|
||||
</Grid.RowDefinitions>
|
||||
<Button Content="Slots" HorizontalAlignment="Center" Grid.Column="3" Grid.Row="2" VerticalAlignment="Center" Width="79" Height="40" Click="Slots_Click" Background="Silver"/>
|
||||
<Button Content="Busfahrer" HorizontalAlignment="Center" Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" Height="40" Width="79" Click="Busfahrer_Click" Background="Silver"/>
|
||||
<TextBlock Name="TxtName" VerticalAlignment="Top" Grid.Column="2" Height="30" Margin="0,10,0,0" Foreground="Gold"/>
|
||||
<TextBlock Name="TxtKonto" VerticalAlignment="Top" Grid.Column="3" Height="30" Margin="0,10,0,0" Foreground="Gold"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Window>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
@@ -16,11 +17,18 @@ namespace Casino
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
// Alles von Lenard Gerdes
|
||||
public static int currentUser;
|
||||
ObservableCollection<User> users = new ObservableCollection<User>();
|
||||
Database db = new Database();
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
users = db.GetUser();
|
||||
setup();
|
||||
|
||||
}
|
||||
|
||||
private void Slots_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -29,16 +37,18 @@ namespace Casino
|
||||
}
|
||||
|
||||
|
||||
private void Blackjack_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Blackjack slotsWindow = new Blackjack();
|
||||
slotsWindow.Show();
|
||||
}
|
||||
|
||||
private void Busfahrer_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Busfahrer slotsWindow = new Busfahrer();
|
||||
slotsWindow.Show();
|
||||
}
|
||||
|
||||
private void setup()
|
||||
{
|
||||
|
||||
TxtName.Text = "User: " + users[currentUser].Name.ToString();
|
||||
TxtKonto.Text = "Konto: " + users[currentUser].Geld.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
Name/Passwort
|
||||
Test User:
|
||||
(Günter/123)
|
||||
(Nutzer/Test)
|
||||
(Gerdi/Mast)
|
||||
|
||||
|
||||
Admin:
|
||||
(Admin/test)
|
||||
|
||||
Webseiten:
|
||||
https://oneuptime.com/blog/post/2026-03-31-mysql-to-base64-from-base64-functions/view
|
||||
https://learn.microsoft.com/en-za/answers/questions/476098/retrieving-image-from-binary-data-ole-object-acces
|
||||
https://kenney.nl/assets/boardgame-pack (Karten)
|
||||
https://wiki.selfhtml.org/wiki/JavaScript/DOM/HTMLElement/innerHTML
|
||||
wiki.selfhtml.org
|
||||
stackoverflow.com
|
||||
File diff suppressed because one or more lines are too long
@@ -9,6 +9,7 @@
|
||||
WindowState="Maximized"
|
||||
WindowStyle="None"
|
||||
Background="Transparent">
|
||||
<!-- Lenard Gerdes -->
|
||||
|
||||
<Border
|
||||
|
||||
|
||||
+166
-70
@@ -22,7 +22,7 @@ namespace Casino
|
||||
/// </summary>
|
||||
public partial class Slots : Window
|
||||
{
|
||||
|
||||
// Lenard Gerdes
|
||||
private List<Image> _bilder;
|
||||
private Random _random = new Random();
|
||||
Database db = new Database();
|
||||
@@ -45,8 +45,9 @@ namespace Casino
|
||||
|
||||
|
||||
private int highestWin = 5;
|
||||
private int bestSoundId;
|
||||
|
||||
|
||||
// Lenard Gerdes
|
||||
public Slots()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -61,9 +62,10 @@ namespace Casino
|
||||
};
|
||||
AlleBilder = new List<Byte[]>
|
||||
{
|
||||
db.GetCardImage(2),db.GetCardImage(3),db.GetCardImage(4),
|
||||
db.GetCardImage(5),db.GetCardImage(6),db.GetCardImage(7),
|
||||
db.GetCardImage(8),db.GetCardImage(9),db.GetCardImage(10),
|
||||
db.GetCardImage(2),db.GetCardImage(3),
|
||||
db.GetCardImage(4),/*db.GetCardImage(5),
|
||||
db.GetCardImage(6),db.GetCardImage(7),
|
||||
db.GetCardImage(8),db.GetCardImage(9), db.GetCardImage(10)*/
|
||||
|
||||
};
|
||||
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||
@@ -89,6 +91,7 @@ namespace Casino
|
||||
}
|
||||
return image;
|
||||
}
|
||||
// Lenard Gerdes
|
||||
private async Task Spin()
|
||||
{
|
||||
for (int i = 0; i < 15; i++)
|
||||
@@ -119,29 +122,45 @@ namespace Casino
|
||||
currentSlot[0, j] = randomBild;
|
||||
LoadCard(_bilder[j], randomBild);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
await Task.Delay(150);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Lenard Gerdes
|
||||
private async void Spin(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
// Versucht das Textfeld auszulesen und zu konvertieren
|
||||
if (string.IsNullOrWhiteSpace(einsatzFeld.Text))
|
||||
{
|
||||
MessageBox.Show("Bitte gib einen Einsatz ein.", "Eingabe fehlt", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
int einsatz = Convert.ToInt32(einsatzFeld.Text);
|
||||
|
||||
if (einsatz <= 0)
|
||||
{
|
||||
MessageBox.Show("Der Einsatz muss größer als 0 sein.", "Ungültiger Einsatz", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
users[MainWindow.currentUser].Geld -= einsatz;
|
||||
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||
|
||||
await Spin();
|
||||
|
||||
users[MainWindow.currentUser].Geld += CheckWin(currentSlot, einsatz);
|
||||
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||
|
||||
db.UpdateGeld(
|
||||
users[MainWindow.currentUser].ID,
|
||||
users[MainWindow.currentUser].Geld);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// Lenard Gerdes
|
||||
private void Hauptmenue(object sender, RoutedEventArgs e)
|
||||
{
|
||||
music.Stop();
|
||||
@@ -149,12 +168,15 @@ namespace Casino
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Lenard Gerdes
|
||||
public decimal CheckWin(int[,] board, decimal einsatz)
|
||||
{
|
||||
decimal multiplikator = 0m;
|
||||
|
||||
// Waagerecht
|
||||
// ==========================================
|
||||
// WAAGERECHT
|
||||
// ==========================================
|
||||
|
||||
for (int row = 0; row < 3; row++)
|
||||
{
|
||||
multiplikator += CheckLine(
|
||||
@@ -163,19 +185,29 @@ namespace Casino
|
||||
board[row, 2],
|
||||
board[row, 3],
|
||||
board[row, 4],
|
||||
board[row, 5]);
|
||||
board[row, 5]
|
||||
);
|
||||
}
|
||||
|
||||
// Senkrecht
|
||||
|
||||
// ==========================================
|
||||
// SENKRECHT
|
||||
// ==========================================
|
||||
|
||||
for (int col = 0; col < 6; col++)
|
||||
{
|
||||
multiplikator += CheckLine(
|
||||
board[0, col],
|
||||
board[1, col],
|
||||
board[2, col]);
|
||||
board[2, col]
|
||||
);
|
||||
}
|
||||
|
||||
// X Muster
|
||||
|
||||
// ==========================================
|
||||
// X-MUSTER
|
||||
// ==========================================
|
||||
|
||||
bool x1 =
|
||||
board[0, 0] == board[1, 1] &&
|
||||
board[1, 1] == board[2, 2];
|
||||
@@ -184,14 +216,24 @@ namespace Casino
|
||||
board[0, 5] == board[1, 4] &&
|
||||
board[1, 4] == board[2, 3];
|
||||
|
||||
if (x1 && x2 &&
|
||||
board[0, 0] == board[0, 5])
|
||||
bool xMuster =
|
||||
x1 &&
|
||||
x2 &&
|
||||
board[0, 0] == board[0, 5];
|
||||
|
||||
if (xMuster)
|
||||
{
|
||||
multiplikator += X_MUSTER;
|
||||
highestWin++;
|
||||
|
||||
// Sound-ID für X-Muster
|
||||
highestWin = Math.Max(highestWin, 7);
|
||||
}
|
||||
|
||||
// Rand
|
||||
|
||||
// ==========================================
|
||||
// RAND
|
||||
// ==========================================
|
||||
|
||||
int randId = board[0, 0];
|
||||
|
||||
bool randGleich =
|
||||
@@ -201,117 +243,179 @@ namespace Casino
|
||||
board[0, 3] == randId &&
|
||||
board[0, 4] == randId &&
|
||||
board[0, 5] == randId &&
|
||||
|
||||
board[2, 0] == randId &&
|
||||
board[2, 1] == randId &&
|
||||
board[2, 2] == randId &&
|
||||
board[2, 3] == randId &&
|
||||
board[2, 4] == randId &&
|
||||
board[2, 5] == randId &&
|
||||
|
||||
board[1, 0] == randId &&
|
||||
board[1, 5] == randId;
|
||||
|
||||
if (randGleich)
|
||||
{
|
||||
multiplikator += RAND;
|
||||
highestWin++;
|
||||
|
||||
// Sound-ID für Rand
|
||||
highestWin = Math.Max(highestWin, 8);
|
||||
}
|
||||
|
||||
// X + Rand Bonus
|
||||
if (
|
||||
randGleich &&
|
||||
x1 && x2 &&
|
||||
board[0, 0] == board[0, 5]
|
||||
)
|
||||
|
||||
// ==========================================
|
||||
// X + RAND
|
||||
// ==========================================
|
||||
|
||||
if (randGleich && xMuster)
|
||||
{
|
||||
multiplikator += X_UND_RAND;
|
||||
highestWin++;
|
||||
|
||||
// Sound-ID für X + Rand
|
||||
highestWin = Math.Max(highestWin, 9);
|
||||
}
|
||||
|
||||
// Fullboard
|
||||
|
||||
// ==========================================
|
||||
// FULLBOARD
|
||||
// ==========================================
|
||||
|
||||
int first = board[0, 0];
|
||||
|
||||
bool fullBoard = true;
|
||||
|
||||
for (int r = 0; r < 3; r++)
|
||||
for (int row = 0; row < 3; row++)
|
||||
{
|
||||
for (int c = 0; c < 6; c++)
|
||||
for (int col = 0; col < 6; col++)
|
||||
{
|
||||
if (board[r, c] != first)
|
||||
if (board[row, col] != first)
|
||||
{
|
||||
fullBoard = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fullBoard)
|
||||
break;
|
||||
}
|
||||
|
||||
if (fullBoard)
|
||||
{
|
||||
multiplikator += FULLBOARD;
|
||||
highestWin++;
|
||||
|
||||
// Fullboard = Sound-ID 12
|
||||
highestWin = 12;
|
||||
}
|
||||
|
||||
if (multiplikator != 0) PlayWinSound();
|
||||
|
||||
// ==========================================
|
||||
// SOUND
|
||||
// ==========================================
|
||||
|
||||
if (multiplikator > 0)
|
||||
{
|
||||
PlayWinSound();
|
||||
}
|
||||
|
||||
|
||||
// ==========================================
|
||||
// AUSZAHLUNG
|
||||
// ==========================================
|
||||
|
||||
return einsatz * multiplikator;
|
||||
}
|
||||
|
||||
|
||||
// =========================================================
|
||||
// CHECK LINE
|
||||
// =========================================================
|
||||
|
||||
private decimal CheckLine(params int[] werte)
|
||||
{
|
||||
decimal gewinn = 0;
|
||||
if (werte.Length < 3)
|
||||
return 0m;
|
||||
|
||||
int laenge = werte.Length;
|
||||
decimal gewinn = 0m;
|
||||
|
||||
for (int start = 0; start < laenge; start++)
|
||||
int start = 0;
|
||||
|
||||
while (start < werte.Length)
|
||||
{
|
||||
int gleiche = 1;
|
||||
|
||||
for (int next = start + 1; next < laenge; next++)
|
||||
while (start + gleiche < werte.Length &&
|
||||
werte[start + gleiche] == werte[start])
|
||||
{
|
||||
if (werte[next] == werte[start])
|
||||
gleiche++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (gleiche >= 3)
|
||||
gewinn += DREI;
|
||||
|
||||
if (gleiche >= 4)
|
||||
{
|
||||
gewinn += VIER;
|
||||
highestWin++;
|
||||
}
|
||||
|
||||
if (gleiche >= 5)
|
||||
{
|
||||
gewinn += FUENF;
|
||||
highestWin++;
|
||||
}
|
||||
|
||||
// Nur den höchsten passenden Gewinn dieser Reihe geben
|
||||
if (gleiche >= 6)
|
||||
{
|
||||
gewinn += SECHS;
|
||||
|
||||
if (8 > bestSoundId)
|
||||
bestSoundId = 8;
|
||||
|
||||
highestWin++;
|
||||
}
|
||||
else if (gleiche >= 5)
|
||||
{
|
||||
gewinn += FUENF;
|
||||
|
||||
if (7 > bestSoundId)
|
||||
bestSoundId = 7;
|
||||
|
||||
highestWin++;
|
||||
}
|
||||
else if (gleiche >= 4)
|
||||
{
|
||||
gewinn += VIER;
|
||||
|
||||
if (6 > bestSoundId)
|
||||
bestSoundId = 6;
|
||||
|
||||
highestWin++;
|
||||
}
|
||||
else if (gleiche >= 3)
|
||||
{
|
||||
gewinn += DREI;
|
||||
|
||||
if (5 > bestSoundId)
|
||||
bestSoundId = 5;
|
||||
}
|
||||
|
||||
|
||||
start += gleiche;
|
||||
}
|
||||
|
||||
return gewinn;
|
||||
}
|
||||
|
||||
|
||||
// =========================================================
|
||||
// WIN SOUND AUS DATENBANK
|
||||
// =========================================================
|
||||
|
||||
//Numberfield
|
||||
void PlayWinSound()
|
||||
{
|
||||
bestSoundId = highestWin+1;
|
||||
if (bestSoundId > 0)
|
||||
audio.PlaySound(db.GetSound(bestSoundId), bestSoundId);
|
||||
|
||||
bestSoundId = 0; // fehlte komplett
|
||||
highestWin = 5;
|
||||
}
|
||||
|
||||
//Numberfield Colin Langer
|
||||
private static readonly Regex _regex = new Regex("^[0-9]"); // Regex to match non-numeric input
|
||||
|
||||
//nur nummern
|
||||
//nur nummern Colin Langer
|
||||
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
e.Handled = !_regex.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
// Keine Spaces
|
||||
// Keine Spaces Colin Langer
|
||||
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Space)
|
||||
@@ -320,7 +424,7 @@ namespace Casino
|
||||
}
|
||||
}
|
||||
|
||||
//das man nichts reinkopieren kann außer Zahlen
|
||||
//das man nichts reinkopieren kann außer Zahlen Colin Langer
|
||||
private void TextBox_Pasting(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
if (e.DataObject.GetDataPresent(typeof(String)))
|
||||
@@ -332,13 +436,5 @@ namespace Casino
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayWinSound()
|
||||
{
|
||||
audio.PlaySound(db.GetSound(highestWin));
|
||||
highestWin = 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Casino
|
||||
{
|
||||
public class Spiele
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int MinBetrag { get; set; }
|
||||
|
||||
public Spiele(string n, int m)
|
||||
{
|
||||
Name = n;
|
||||
MinBetrag = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-10
@@ -1,33 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Casino
|
||||
{
|
||||
public class User
|
||||
public class User // Lenard Gerdes
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Alter { get; set; }
|
||||
public string Passwort { get; set; }
|
||||
public decimal Geld { get; set; }
|
||||
public User(string n, int a, string p)
|
||||
public string Rolle { get; set; }
|
||||
public User(string name, int age, string passwort)
|
||||
{
|
||||
ID = ID_Generation();
|
||||
Name = n;
|
||||
Alter = a;
|
||||
Passwort = p;
|
||||
Name = name;
|
||||
Alter = age;
|
||||
Passwort = passwort;
|
||||
Geld = 1000;
|
||||
Rolle = "User";
|
||||
}
|
||||
public User(string id, string n, int a,string p, int g)
|
||||
public User(string id, string name, int age,string passwort, int geld, string rolle)
|
||||
{
|
||||
ID = id;
|
||||
Name = n;
|
||||
Alter = a;
|
||||
Passwort = p;
|
||||
Geld = g;
|
||||
Name = name;
|
||||
Alter = age;
|
||||
Passwort = passwort;
|
||||
Geld = geld;
|
||||
Rolle = rolle;
|
||||
}
|
||||
|
||||
private string ID_Generation()
|
||||
|
||||
Reference in New Issue
Block a user