Compare commits
54
Commits
836f8d6f89
...
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 | ||
|
|
049960d30d | ||
|
|
628a3a49ec | ||
|
|
4b3a1e07b3 | ||
|
|
ae7f645aca | ||
|
|
ed99488c8d | ||
|
|
fb534fb7ee | ||
|
|
65d8ac84b0 | ||
|
|
64828e3d9c | ||
|
|
297dc3f8cb | ||
|
|
4d95dc825a | ||
|
|
70260fe16f | ||
|
|
ca6b46b5c3 | ||
|
|
ba36e82cc0 | ||
|
|
da0b8189d7 | ||
|
|
5069e43993 | ||
|
|
bafeea0f30 | ||
|
|
705f6b4dba | ||
|
|
65b633dcb1 | ||
|
|
bce2f51a7b |
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+96
-19
@@ -4,52 +4,129 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
namespace Casino
|
namespace Casino
|
||||||
{
|
{
|
||||||
class Audioplayer
|
class Audioplayer //ki
|
||||||
{
|
{
|
||||||
private readonly MediaPlayer player = new MediaPlayer();
|
private readonly MediaPlayer player = new MediaPlayer();
|
||||||
|
private readonly MediaPlayer shortplayer = new MediaPlayer();
|
||||||
|
private readonly List<MediaPlayer> activePlayers = new();
|
||||||
|
|
||||||
public void PlaySound(byte[] audioBlob)
|
public Audioplayer() { shortplayer.MediaEnded += Player_MediaEnded; }
|
||||||
|
|
||||||
|
public void PlaySound(byte[] audioBlob, int soundId)
|
||||||
{
|
{
|
||||||
|
if (audioBlob == null || audioBlob.Length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
string tempFile = System.IO.Path.Combine(
|
string tempFile = System.IO.Path.Combine(
|
||||||
System.IO.Path.GetTempPath(),
|
System.IO.Path.GetTempPath(),
|
||||||
Guid.NewGuid() + ".mp3");
|
"casino_" + Guid.NewGuid().ToString("N") + ".mp3");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllBytes(tempFile, audioBlob);
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
player.Position = TimeSpan.Zero;
|
||||||
|
player.Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PlayLoopingSound(byte[] audioBlob)
|
||||||
|
{
|
||||||
|
|
||||||
|
string tempFile = System.IO.Path.Combine(
|
||||||
|
System.IO.Path.GetTempPath(),
|
||||||
|
"Hintergrundmusik.mp3");
|
||||||
|
|
||||||
|
player.Volume = 0.1;
|
||||||
|
|
||||||
File.WriteAllBytes(tempFile, audioBlob);
|
File.WriteAllBytes(tempFile, audioBlob);
|
||||||
|
|
||||||
player.Open(new Uri(tempFile));
|
player.Open(new Uri(tempFile));
|
||||||
|
|
||||||
|
player.MediaEnded -= Player_MediaEnded;
|
||||||
|
player.MediaEnded += Player_MediaEnded;
|
||||||
|
|
||||||
player.Play();
|
player.Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isPlaying = false;
|
|
||||||
private readonly MediaPlayer musicPlayer = new();
|
|
||||||
|
|
||||||
public void PlayMusic(byte[] audioBlob)
|
public void PlayLoopingSound_2(byte[] audioBlob)
|
||||||
{
|
{
|
||||||
if (isPlaying)
|
|
||||||
return;
|
|
||||||
|
|
||||||
isPlaying = true;
|
|
||||||
|
|
||||||
string tempFile = System.IO.Path.Combine(
|
string tempFile = System.IO.Path.Combine(
|
||||||
System.IO.Path.GetTempPath(),
|
System.IO.Path.GetTempPath(),
|
||||||
Guid.NewGuid() + ".mp3");
|
"Hintergrundmusik_Bus.mp3");
|
||||||
|
|
||||||
System.IO.File.WriteAllBytes(tempFile, audioBlob);
|
player.Volume = 0.1;
|
||||||
|
|
||||||
musicPlayer.MediaEnded += (s, e) =>
|
File.WriteAllBytes(tempFile, audioBlob);
|
||||||
{
|
|
||||||
isPlaying = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
musicPlayer.Open(new Uri(tempFile));
|
player.Open(new Uri(tempFile));
|
||||||
musicPlayer.Play();
|
|
||||||
|
player.MediaEnded -= Player_MediaEnded;
|
||||||
|
player.MediaEnded += Player_MediaEnded;
|
||||||
|
|
||||||
|
player.Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
player.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 Grid.Column="4" HorizontalAlignment="Left" Height="101" Margin="10,169,0,0" Grid.Row="2" TextWrapping="Wrap" Text="Einsatz" VerticalAlignment="Top" Width="193" Background="Blue" PreviewTextInput="TextBox_OnPreviewTextInput" PreviewKeyDown="TextBox_OnPreviewKeyDown" DataObject.Pasting="TextBox_Pasting" Grid.ColumnSpan="2"/>
|
|
||||||
</Grid>
|
|
||||||
</Window>
|
|
||||||
@@ -1,95 +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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+269
-19
@@ -5,39 +5,289 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:Casino"
|
xmlns:local="clr-namespace:Casino"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Busfahrer" Height="1080" Width="1960">
|
Title="Bus Fahrer"
|
||||||
|
Height="1080"
|
||||||
|
Width="1800"
|
||||||
|
WindowState="Maximized"
|
||||||
|
WindowStyle="None"
|
||||||
|
Background="#195925">
|
||||||
|
<!-- Lenard Gerdes -->
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="100"></ColumnDefinition>
|
<ColumnDefinition Width="1*"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
<ColumnDefinition Width="20"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="200"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="100"></ColumnDefinition>
|
<ColumnDefinition Width="1*"></ColumnDefinition>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="70"></RowDefinition>
|
<RowDefinition Height="1*"></RowDefinition>
|
||||||
<RowDefinition Height="270"></RowDefinition>
|
|
||||||
<RowDefinition Height="270"></RowDefinition>
|
|
||||||
<RowDefinition Height="270"></RowDefinition>
|
|
||||||
<RowDefinition Height="200"></RowDefinition>
|
<RowDefinition Height="200"></RowDefinition>
|
||||||
|
<RowDefinition Height="200"></RowDefinition>
|
||||||
|
<RowDefinition Height="200"></RowDefinition>
|
||||||
|
<RowDefinition Height="1*"></RowDefinition>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<Button Grid.Column="0"
|
||||||
|
Grid.Row="0"
|
||||||
|
Content="Main Menu"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Click="Hauptmenue"
|
||||||
|
Width="100"
|
||||||
|
Height="40"/>
|
||||||
|
|
||||||
<Image Grid.Column="3" Grid.Row="2" x:Name="Bild_1"/>
|
<!-- Karten -->
|
||||||
<Image Grid.Column="5" Grid.Row="2" x:Name="Bild_2"/>
|
<Image Grid.Column="3" Grid.Row="2" x:Name="Bild_1" Margin="5" Stretch="Uniform"/>
|
||||||
<Image Grid.Column="7" Grid.Row="2" x:Name="Bild_3"/>
|
<Image Grid.Column="5" Grid.Row="2" x:Name="Bild_2" Margin="5" Stretch="Uniform"/>
|
||||||
<Image Grid.Column="9" Grid.Row="2" x:Name="Bild_4"/>
|
<Image Grid.Column="7" Grid.Row="2" x:Name="Bild_3" Margin="5" Stretch="Uniform"/>
|
||||||
<Button Grid.Row="0" Content="Hauptmenü" HorizontalAlignment="Center" Click="Hauptmenue" Width="100"/>
|
<Image Grid.Column="9" Grid.Row="2" x:Name="Bild_4" Margin="5" Stretch="Uniform"/>
|
||||||
<TextBox Grid.Column="5" HorizontalAlignment="Left" Height="51" Grid.Row="1" Width="193" Background="DimGray" PreviewTextInput="TextBox_PreviewTextInput" PreviewKeyDown="TextBox_PreviewKeyDown" DataObject.Pasting="TextBox_Pasting"/>
|
|
||||||
|
|
||||||
|
<!-- 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>
|
||||||
|
|
||||||
|
<!-- 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>
|
||||||
|
|
||||||
|
<!-- 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>
|
||||||
|
|
||||||
|
<!-- 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 -->
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<!-- 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>
|
||||||
|
|
||||||
|
<!-- 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>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
+539
-45
@@ -1,48 +1,552 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Casino
|
namespace Casino
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Interaktionslogik für Busfahrer.xaml
|
|
||||||
/// </summary>
|
|
||||||
public partial class Busfahrer : Window
|
public partial class Busfahrer : Window
|
||||||
{
|
{
|
||||||
|
public class Card //Colin Langer
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string WertRaw { get; set; } = string.Empty;
|
||||||
|
public string FarbeRaw { get; set; } = string.Empty;
|
||||||
|
public ImageSource Image { get; set; } = null!;
|
||||||
|
public int NumericValue { get; set; }
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Colin Langer
|
||||||
|
//verwandelt den textwert in punktwert um
|
||||||
|
private static int ParseValue(string wert)
|
||||||
|
{
|
||||||
|
return wert.Trim() switch
|
||||||
|
{
|
||||||
|
"Jack" => 11,
|
||||||
|
"Queen" => 12,
|
||||||
|
"King" => 13,
|
||||||
|
"Ace" => 14,
|
||||||
|
_ => 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();
|
||||||
|
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
image.StreamSource = ms;
|
||||||
|
image.EndInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
image.Freeze();
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Database db = new Database();
|
||||||
|
private ObservableCollection<User> users;
|
||||||
|
|
||||||
|
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 bool roundRunning = false;
|
||||||
|
|
||||||
public Busfahrer()
|
public Busfahrer()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
LoadCard(8);
|
users = db.GetUser();
|
||||||
|
UpdateAccountDisplay();
|
||||||
|
|
||||||
|
ShowWaitingState();
|
||||||
|
music.PlayLoopingSound_2(db.GetSound(20));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadCard(int Bild)
|
private User CurrentUser => users[MainWindow.currentUser];
|
||||||
|
|
||||||
|
// Lenard Gerdes
|
||||||
|
private void UpdateAccountDisplay()
|
||||||
{
|
{
|
||||||
Database db = new Database();
|
Konto.Text = CurrentUser.Geld.ToString();
|
||||||
byte[] img = db.GetCardImage(Bild);
|
}
|
||||||
|
// Lenard Gerdes
|
||||||
|
private void SaveAccount()
|
||||||
|
{
|
||||||
|
db.UpdateGeld(CurrentUser.ID, CurrentUser.Geld);
|
||||||
|
UpdateAccountDisplay();
|
||||||
|
}
|
||||||
|
//Colin Langer
|
||||||
|
private void BtnStart_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
Bild_4.Source = ByteArrayToImage(img);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bet > CurrentUser.Geld)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
"Du hast nicht genug Geld für diesen Einsatz.",
|
||||||
|
"Zu wenig Geld",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Warning);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentBet = bet;
|
||||||
|
StartRound();
|
||||||
|
}
|
||||||
|
//Colin Langer
|
||||||
|
private void StartRound()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (currentBet <= 0 || currentBet > CurrentUser.Geld)
|
||||||
|
{
|
||||||
|
ShowWaitingState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentUser.Geld -= Convert.ToInt32(currentBet);
|
||||||
|
SaveAccount();
|
||||||
|
|
||||||
|
currentProfit = 0;
|
||||||
|
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();
|
||||||
|
|
||||||
|
byte[] backBytes = db.GetCardBackImage();
|
||||||
|
|
||||||
|
if (backBytes != null && backBytes.Length > 0)
|
||||||
|
{
|
||||||
|
cardBackImage = ByteArrayToImage(backBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
handCards.Clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < 4 && deck.Count > 0; i++)
|
||||||
|
{
|
||||||
|
handCards.Add(DrawCard());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Colin Langer
|
||||||
|
// nimmt die oberste karte
|
||||||
|
private Card DrawCard()
|
||||||
|
{
|
||||||
|
Card card = deck[0];
|
||||||
|
deck.RemoveAt(0);
|
||||||
|
return card;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BitmapImage ByteArrayToImage(byte[] bytes)
|
//Colin Langer
|
||||||
|
private void UpdateHandUI()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lenard Gerdes
|
||||||
|
private async Task ProcessGuessAsync(bool success)
|
||||||
|
{
|
||||||
|
if (!roundRunning)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RevealCurrentCard();
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
roundRunning = false;
|
||||||
|
currentProfit = 0;
|
||||||
|
UpdateWinDisplay();
|
||||||
|
SetPhaseUI();
|
||||||
|
|
||||||
|
await Task.Delay(100);
|
||||||
|
|
||||||
|
// Nächste Runde mit demselben Einsatz
|
||||||
|
if (currentBet <= CurrentUser.Geld)
|
||||||
|
{
|
||||||
|
StartRound();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowWaitingState();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPhase++;
|
||||||
|
currentProfit = CalculateCurrentProfit();
|
||||||
|
|
||||||
|
UpdateHandUI();
|
||||||
|
UpdateWinDisplay();
|
||||||
|
SetPhaseUI();
|
||||||
|
|
||||||
|
if (currentPhase == 4)
|
||||||
|
{
|
||||||
|
roundRunning = false;
|
||||||
|
|
||||||
|
PayoutCurrentProfit();
|
||||||
|
|
||||||
|
await Task.Delay(100);
|
||||||
|
|
||||||
|
if (currentBet <= CurrentUser.Geld)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (!roundRunning || currentProfit <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
roundRunning = false;
|
||||||
|
|
||||||
|
decimal payout = currentProfit;
|
||||||
|
PayoutCurrentProfit();
|
||||||
|
|
||||||
|
MessageBox.Show(
|
||||||
|
$"Du hast ${payout:F2} ausgezahlt bekommen!",
|
||||||
|
"Cash Out",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Information);
|
||||||
|
|
||||||
|
ShowWaitingState();
|
||||||
|
}
|
||||||
|
//Colin Langer
|
||||||
|
private void PayoutCurrentProfit()
|
||||||
|
{
|
||||||
|
if (currentProfit <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentUser.Geld += Convert.ToInt32(currentProfit);
|
||||||
|
SaveAccount();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Colin Langer
|
||||||
|
// blendet die buttons der jewaligen runde ein
|
||||||
|
private void SetPhaseUI()
|
||||||
|
{
|
||||||
|
PanelRedBlack.Visibility = Visibility.Collapsed;
|
||||||
|
PanelHigherLower.Visibility = Visibility.Collapsed;
|
||||||
|
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;
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
BitmapImage image = new BitmapImage();
|
BitmapImage image = new BitmapImage();
|
||||||
|
|
||||||
using (MemoryStream ms = new MemoryStream(bytes))
|
using (MemoryStream ms = new MemoryStream(bytes))
|
||||||
{
|
{
|
||||||
image.BeginInit();
|
image.BeginInit();
|
||||||
@@ -51,35 +555,23 @@ namespace Casino
|
|||||||
image.EndInit();
|
image.EndInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
image.Freeze();
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int rand()
|
// =========================
|
||||||
{
|
// EINSATZFELD Colin Langer
|
||||||
Random ran = new Random();
|
// =========================
|
||||||
int temp = ran.Next(13, 66);
|
// In Slots ist die erklärung drin
|
||||||
Console.WriteLine(temp);
|
|
||||||
|
|
||||||
return 0;
|
private static readonly Regex NumberRegex = new Regex("^[0-9]+$");
|
||||||
|
|
||||||
|
private void TxtBet_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||||
|
{
|
||||||
|
e.Handled = !NumberRegex.IsMatch(e.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Hauptmenue(object sender, RoutedEventArgs e)
|
private void TxtBet_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Numberfield
|
|
||||||
private static readonly Regex _regex = new Regex("^[0-9]"); // Regex to match non-numeric input
|
|
||||||
|
|
||||||
//nur nummern
|
|
||||||
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
||||||
{
|
|
||||||
e.Handled = !_regex.IsMatch(e.Text);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keine Spaces
|
|
||||||
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
|
|
||||||
{
|
{
|
||||||
if (e.Key == Key.Space)
|
if (e.Key == Key.Space)
|
||||||
{
|
{
|
||||||
@@ -87,18 +579,20 @@ namespace Casino
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//das man nichts reinkopieren kann außer Zahlen
|
private void TxtBet_Pasting(object sender, DataObjectPastingEventArgs e)
|
||||||
private void TextBox_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)));
|
e.CancelCommand();
|
||||||
if (!_regex.IsMatch((string)text))
|
return;
|
||||||
{
|
}
|
||||||
e.CancelCommand();
|
|
||||||
}
|
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
+213
-1
@@ -5,6 +5,7 @@ using System.Data;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
namespace Casino
|
namespace Casino
|
||||||
@@ -16,6 +17,7 @@ namespace Casino
|
|||||||
{
|
{
|
||||||
ObservableCollection<User> user = new ObservableCollection<User>();
|
ObservableCollection<User> user = new ObservableCollection<User>();
|
||||||
|
|
||||||
|
//Lenard Gerdes
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MySql.Data.MySqlClient.MySqlConnection myConnection;
|
MySql.Data.MySqlClient.MySqlConnection myConnection;
|
||||||
@@ -40,7 +42,8 @@ namespace Casino
|
|||||||
Name = myReader.GetString("name"),
|
Name = myReader.GetString("name"),
|
||||||
Alter = myReader.GetInt32("age"),
|
Alter = myReader.GetInt32("age"),
|
||||||
Passwort = myReader.GetString("passwort"),
|
Passwort = myReader.GetString("passwort"),
|
||||||
Geld = myReader.GetInt32("geld")
|
Geld = myReader.GetDecimal("geld"),
|
||||||
|
Rolle = myReader.GetString("Rolle")
|
||||||
};
|
};
|
||||||
|
|
||||||
user.Add(u);
|
user.Add(u);
|
||||||
@@ -57,6 +60,32 @@ namespace Casino
|
|||||||
return user;
|
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)
|
public byte[] GetCardImage(int id)
|
||||||
{
|
{
|
||||||
byte[] imageBytes = null;
|
byte[] imageBytes = null;
|
||||||
@@ -80,6 +109,59 @@ namespace Casino
|
|||||||
|
|
||||||
return imageBytes;
|
return imageBytes;
|
||||||
}
|
}
|
||||||
|
//Cloin Langer
|
||||||
|
public List<Busfahrer.Card> GetAllCards()
|
||||||
|
{
|
||||||
|
var cards = new List<Busfahrer.Card>();
|
||||||
|
|
||||||
|
using (MySqlConnection conn = new MySqlConnection(myConnectionString))
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
// Lädt alle echten Karten aus der Tabelle (schließt Rückseite 'Back' aus)
|
||||||
|
string query = "SELECT kartenid, wert, farbe, bild FROM Karten WHERE wert != 'Back' AND deckid != 'Slots'";
|
||||||
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
int id = reader.GetInt32("kartenid");
|
||||||
|
string wert = reader.GetString("wert");
|
||||||
|
string farbe = reader.GetString("farbe");
|
||||||
|
byte[] img = (byte[])reader["bild"];
|
||||||
|
|
||||||
|
cards.Add(new Busfahrer.Card(id, wert, farbe, img));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cards;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Holt das Bild der Kartenrückseite Colin Langer
|
||||||
|
public byte[] GetCardBackImage()
|
||||||
|
{
|
||||||
|
byte[] imageBytes = null;
|
||||||
|
|
||||||
|
using (MySqlConnection conn = new MySqlConnection(myConnectionString))
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
string query = "SELECT bild FROM Karten WHERE wert = 'Back' OR deckid = 'Back' LIMIT 1";
|
||||||
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
imageBytes = (byte[])reader["bild"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageBytes;
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] GetSound(int id)
|
public byte[] GetSound(int id)
|
||||||
{
|
{
|
||||||
@@ -104,6 +186,136 @@ namespace Casino
|
|||||||
|
|
||||||
return soundBytes;
|
return soundBytes;
|
||||||
}
|
}
|
||||||
|
public void UpdateGeld(string id, decimal geld)
|
||||||
|
{
|
||||||
|
using (MySqlConnection conn = new MySqlConnection(myConnectionString))
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
using (MySqlCommand cmd = new MySqlCommand(
|
||||||
|
"UPDATE Nutzer SET Geld = @geld WHERE id = @id", conn))
|
||||||
|
{
|
||||||
|
cmd.Parameters.AddWithValue("@geld", geld);
|
||||||
|
cmd.Parameters.AddWithValue("@id", id);
|
||||||
|
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-3
@@ -12,8 +12,9 @@
|
|||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
AllowsTransparency="True"
|
AllowsTransparency="True"
|
||||||
MouseDown="Window_MouseDown">
|
MouseDown="Window_MouseDown">
|
||||||
|
<!-- Lenard Gerdes -->
|
||||||
|
|
||||||
<Border CornerRadius="50"
|
<Border CornerRadius="20"
|
||||||
Background="#590D00"
|
Background="#590D00"
|
||||||
BorderBrush="Gold"
|
BorderBrush="Gold"
|
||||||
BorderThickness="5">
|
BorderThickness="5">
|
||||||
@@ -29,10 +30,12 @@
|
|||||||
<Label Content="Name" Margin="0,30,0,0" FontSize="18" FontWeight="SemiBold" FontFamily="Palatino Linotype" Foreground="DarkGray"/>
|
<Label Content="Name" Margin="0,30,0,0" FontSize="18" FontWeight="SemiBold" FontFamily="Palatino Linotype" Foreground="DarkGray"/>
|
||||||
<TextBox x:Name="TxtName" Margin="0,0,0,30" Background="#BD9208"/>
|
<TextBox x:Name="TxtName" Margin="0,0,0,30" Background="#BD9208"/>
|
||||||
<Label Content="Passwort" FontSize="18" FontWeight="SemiBold" FontFamily="Palatino Linotype" Foreground="DarkGray"/>
|
<Label Content="Passwort" FontSize="18" FontWeight="SemiBold" FontFamily="Palatino Linotype" Foreground="DarkGray"/>
|
||||||
<TextBox x:Name="TxtPasswort" Margin="0,0,0,10" Background="#BD9208" />
|
<PasswordBox x:Name="TxtPasswort" Margin="0,0,0,10" Background="#BD9208" />
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
<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"/>
|
<Button Content="Anmelden" Width="80" Click="Anmelden_Click" Background="#BD9208" FontFamily="Palatino Linotype" FontWeight="SemiBold"/>
|
||||||
</StackPanel>
|
|
||||||
|
</StackPanel>
|
||||||
<MediaElement Name="player"
|
<MediaElement Name="player"
|
||||||
LoadedBehavior="Manual"
|
LoadedBehavior="Manual"
|
||||||
UnloadedBehavior="Manual" />
|
UnloadedBehavior="Manual" />
|
||||||
|
|||||||
+64
-6
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Security.Policy;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -13,8 +15,10 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using System.Xml.Linq;
|
||||||
using Mysqlx.Cursor;
|
using Mysqlx.Cursor;
|
||||||
|
|
||||||
|
|
||||||
namespace Casino
|
namespace Casino
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -22,22 +26,36 @@ namespace Casino
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Login : Window
|
public partial class Login : Window
|
||||||
{
|
{
|
||||||
|
//Alles von Lenard Gerdes
|
||||||
|
Database db = new Database();
|
||||||
|
ObservableCollection<User> users = new ObservableCollection<User>();
|
||||||
|
|
||||||
|
|
||||||
public Login()
|
public Login()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
users = db.GetUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void Anmelden_Click(object sender, RoutedEventArgs e)
|
private void Anmelden_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (checkLogin(TxtName.Text, TxtPasswort.Text))
|
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 mainWindow = new MainWindow();
|
||||||
mainWindow.Show();
|
mainWindow.Show();
|
||||||
Close();
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -48,14 +66,14 @@ namespace Casino
|
|||||||
|
|
||||||
private bool checkLogin(string name, string passwort)
|
private bool checkLogin(string name, string passwort)
|
||||||
{
|
{
|
||||||
Database db = new Database();
|
|
||||||
ObservableCollection<User> users = new ObservableCollection<User>();
|
string hash = HashPassword(passwort);
|
||||||
users = db.GetUser();
|
|
||||||
for (int i = 0; i < users.Count(); i++)
|
for (int i = 0; i < users.Count(); i++)
|
||||||
{
|
{
|
||||||
if (name.Equals(users[i].Name))
|
if (name.Equals(users[i].Name))
|
||||||
{
|
{
|
||||||
if(passwort.Equals(users[i].Passwort)) {
|
if(hash.Equals(users[i].Passwort)) {
|
||||||
MainWindow.currentUser = i;
|
MainWindow.currentUser = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -70,5 +88,45 @@ namespace Casino
|
|||||||
if (e.LeftButton == MouseButtonState.Pressed)
|
if (e.LeftButton == MouseButtonState.Pressed)
|
||||||
DragMove();
|
DragMove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public string HashPassword(string password)
|
||||||
|
{
|
||||||
|
using (SHA256 sha256 = SHA256.Create())
|
||||||
|
{
|
||||||
|
byte[] bytes = Encoding.UTF8.GetBytes(password);
|
||||||
|
byte[] hash = sha256.ComputeHash(bytes);
|
||||||
|
|
||||||
|
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
-6
@@ -7,8 +7,8 @@
|
|||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="MainWindow" Height="450" Width="800"
|
Title="MainWindow" Height="450" Width="800"
|
||||||
WindowStartupLocation="CenterScreen"
|
WindowStartupLocation="CenterScreen"
|
||||||
Background="Transparent">
|
>
|
||||||
|
<!-- Lenard Gerdes -->
|
||||||
|
|
||||||
<Border
|
<Border
|
||||||
|
|
||||||
@@ -17,11 +17,25 @@
|
|||||||
BorderThickness="5">
|
BorderThickness="5">
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Button Content="Slots" HorizontalAlignment="Left" Height="39" Margin="65,114,0,0" VerticalAlignment="Top" Width="93" Click="Slots_Click"/>
|
|
||||||
<Button Content="sound" HorizontalAlignment="Left" Height="39" Margin="65,193,0,0" VerticalAlignment="Top" Width="93" Click="Sound_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>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
+17
-14
@@ -1,4 +1,5 @@
|
|||||||
using System.Text;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
@@ -16,11 +17,18 @@ namespace Casino
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
|
// Alles von Lenard Gerdes
|
||||||
public static int currentUser;
|
public static int currentUser;
|
||||||
|
ObservableCollection<User> users = new ObservableCollection<User>();
|
||||||
|
Database db = new Database();
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
users = db.GetUser();
|
||||||
|
setup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Slots_Click(object sender, RoutedEventArgs e)
|
private void Slots_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -28,24 +36,19 @@ namespace Casino
|
|||||||
slotsWindow.Show();
|
slotsWindow.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Sound_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
Database data = new Database();
|
|
||||||
byte[] blobData = data.GetSound(1);
|
|
||||||
var audioService = new Audioplayer();
|
|
||||||
audioService.PlayMusic(blobData);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Blackjack_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
Blackjack slotsWindow = new Blackjack();
|
|
||||||
slotsWindow.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Busfahrer_Click(object sender, RoutedEventArgs e)
|
private void Busfahrer_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Busfahrer slotsWindow = new Busfahrer();
|
Busfahrer slotsWindow = new Busfahrer();
|
||||||
slotsWindow.Show();
|
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
@@ -1,44 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.CodeDom.Compiler;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Casino
|
|
||||||
{
|
|
||||||
public class Slot_System
|
|
||||||
{
|
|
||||||
int[,] slots = new int[3, 6];
|
|
||||||
bool fertig = false;
|
|
||||||
|
|
||||||
public bool getFertig () { return fertig; }
|
|
||||||
|
|
||||||
public async Task roll()
|
|
||||||
{
|
|
||||||
int counter =0;
|
|
||||||
while (counter<15) {
|
|
||||||
for (int i = 0; i < slots.GetLength(1); i++)
|
|
||||||
{
|
|
||||||
slots[2, i] = slots[1, i];
|
|
||||||
slots[1, i] = slots[0, i];
|
|
||||||
slots[0, i] = randomize();
|
|
||||||
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
await Task.Delay(1000);
|
|
||||||
}
|
|
||||||
fertig = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private int randomize()
|
|
||||||
{
|
|
||||||
Random ran = new Random();
|
|
||||||
int temp = ran.Next(2, 11);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+7
-4
@@ -9,12 +9,13 @@
|
|||||||
WindowState="Maximized"
|
WindowState="Maximized"
|
||||||
WindowStyle="None"
|
WindowStyle="None"
|
||||||
Background="Transparent">
|
Background="Transparent">
|
||||||
|
<!-- Lenard Gerdes -->
|
||||||
|
|
||||||
<Border
|
<Border
|
||||||
|
|
||||||
Background="#590D00"
|
Background="#590D00"
|
||||||
BorderBrush="Gold"
|
BorderBrush="Gold"
|
||||||
BorderThickness="5">
|
BorderThickness="5">
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
@@ -62,7 +63,9 @@
|
|||||||
|
|
||||||
<Button Content="Spin" HorizontalAlignment="Center" Grid.Row="4" Grid.Column="0" Height="50" Width="100" Click="Spin" Margin="0,100,0,0" Background="DarkRed" Foreground="Silver"/>
|
<Button Content="Spin" HorizontalAlignment="Center" Grid.Row="4" Grid.Column="0" Height="50" Width="100" Click="Spin" Margin="0,100,0,0" Background="DarkRed" Foreground="Silver"/>
|
||||||
<Button Grid.Row="0" Content="Hauptmenü" HorizontalAlignment="Center" Click="Hauptmenue" Width="100" Height="50"/>
|
<Button Grid.Row="0" Content="Hauptmenü" HorizontalAlignment="Center" Click="Hauptmenue" Width="100" Height="50"/>
|
||||||
<TextBlock x:Name="Konto" Grid.Column="12" Grid.Row="4" Height="30" Width="100" Margin="0,100,0,0" Background="DarkRed" Foreground="Silver" TextAlignment="Right" FontSize="25"/>
|
<TextBlock x:Name="Konto" Grid.Column="12" Grid.Row="4" Height="30" Width="100" Margin="0,100,0,0" Background="DarkRed" Foreground="Silver" TextAlignment="Right" FontSize="25" Text="{Binding Path=Geld }"/>
|
||||||
|
<TextBox Name="einsatzFeld" Grid.Column="5" HorizontalAlignment="Left" Height="51" Grid.Row="6" Margin="0,100,0,0" Width="193" Background="DimGray" PreviewTextInput="TextBox_PreviewTextInput" PreviewKeyDown="TextBox_PreviewKeyDown" DataObject.Pasting="TextBox_Pasting" FontSize="30" TextAlignment="Center"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
+353
-13
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
@@ -21,13 +22,32 @@ namespace Casino
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Slots : Window
|
public partial class Slots : Window
|
||||||
{
|
{
|
||||||
|
// Lenard Gerdes
|
||||||
private List<Image> _bilder;
|
private List<Image> _bilder;
|
||||||
private Random _random = new Random();
|
private Random _random = new Random();
|
||||||
Database db = new Database();
|
Database db = new Database();
|
||||||
private List<Byte[]> AlleBilder;
|
private List<Byte[]> AlleBilder;
|
||||||
ObservableCollection<User> users = new ObservableCollection<User>();
|
ObservableCollection<User> users = new ObservableCollection<User>();
|
||||||
|
Audioplayer music = new Audioplayer();
|
||||||
|
Audioplayer audio = new Audioplayer();
|
||||||
|
private int[,] currentSlot = new int[3, 6];
|
||||||
|
|
||||||
|
|
||||||
|
const decimal DREI = 1.25m;
|
||||||
|
const decimal VIER = 0.75m;
|
||||||
|
const decimal FUENF = 2.25m;
|
||||||
|
const decimal SECHS = 6.75m;
|
||||||
|
|
||||||
|
const decimal X_MUSTER = 13.00m;
|
||||||
|
const decimal RAND = 18.00m;
|
||||||
|
const decimal X_UND_RAND = 25.00m;
|
||||||
|
const decimal FULLBOARD = 50.00m;
|
||||||
|
|
||||||
|
|
||||||
|
private int highestWin = 5;
|
||||||
|
private int bestSoundId;
|
||||||
|
|
||||||
|
// Lenard Gerdes
|
||||||
public Slots()
|
public Slots()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -42,13 +62,14 @@ namespace Casino
|
|||||||
};
|
};
|
||||||
AlleBilder = new List<Byte[]>
|
AlleBilder = new List<Byte[]>
|
||||||
{
|
{
|
||||||
db.GetCardImage(2),db.GetCardImage(3),db.GetCardImage(4),
|
db.GetCardImage(2),db.GetCardImage(3),
|
||||||
db.GetCardImage(5),db.GetCardImage(6),db.GetCardImage(7),
|
db.GetCardImage(4),/*db.GetCardImage(5),
|
||||||
db.GetCardImage(8),db.GetCardImage(9),db.GetCardImage(10),
|
db.GetCardImage(6),db.GetCardImage(7),
|
||||||
|
db.GetCardImage(8),db.GetCardImage(9), db.GetCardImage(10)*/
|
||||||
|
|
||||||
};
|
};
|
||||||
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||||
|
music.PlayLoopingSound(db.GetSound(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -70,31 +91,350 @@ namespace Casino
|
|||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
// Lenard Gerdes
|
||||||
private async Task Spin()
|
private async Task Spin()
|
||||||
{
|
{
|
||||||
users[MainWindow.currentUser].Geld += 100;
|
for (int i = 0; i < 15; i++)
|
||||||
for (int i = 0; i < 50; i++)
|
|
||||||
{
|
{
|
||||||
foreach (var image in _bilder)
|
|
||||||
|
for (int j = 5; j>=0;j--)
|
||||||
{
|
{
|
||||||
int randomBild = _random.Next(0, AlleBilder.Count);
|
int randomBild = _random.Next(0, AlleBilder.Count);
|
||||||
|
|
||||||
LoadCard(image, randomBild);
|
if (i == 0)
|
||||||
|
{
|
||||||
|
currentSlot[0,j] = randomBild;
|
||||||
|
LoadCard(_bilder[j], randomBild);
|
||||||
|
}
|
||||||
|
else if (i == 1)
|
||||||
|
{
|
||||||
|
currentSlot[1, j] = currentSlot[0, j];
|
||||||
|
LoadCard(_bilder[j + 6], currentSlot[0,j]);
|
||||||
|
currentSlot[0, j] = randomBild;
|
||||||
|
LoadCard(_bilder[j], randomBild);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentSlot[2, j] = currentSlot[1, j];
|
||||||
|
LoadCard(_bilder[j + 12], currentSlot[1, j]);
|
||||||
|
currentSlot[1, j] = currentSlot[0, j];
|
||||||
|
LoadCard(_bilder[j + 6], currentSlot[0, j]);
|
||||||
|
currentSlot[0, j] = randomBild;
|
||||||
|
LoadCard(_bilder[j], randomBild);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
await Task.Delay(150);
|
||||||
await Task.Delay(70);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lenard Gerdes
|
||||||
private async void Spin(object sender, RoutedEventArgs e)
|
private async void Spin(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
await Spin();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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)
|
private void Hauptmenue(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
music.Stop();
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Lenard Gerdes
|
||||||
|
public decimal CheckWin(int[,] board, decimal einsatz)
|
||||||
|
{
|
||||||
|
decimal multiplikator = 0m;
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// WAAGERECHT
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
for (int row = 0; row < 3; row++)
|
||||||
|
{
|
||||||
|
multiplikator += CheckLine(
|
||||||
|
board[row, 0],
|
||||||
|
board[row, 1],
|
||||||
|
board[row, 2],
|
||||||
|
board[row, 3],
|
||||||
|
board[row, 4],
|
||||||
|
board[row, 5]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// SENKRECHT
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
for (int col = 0; col < 6; col++)
|
||||||
|
{
|
||||||
|
multiplikator += CheckLine(
|
||||||
|
board[0, col],
|
||||||
|
board[1, col],
|
||||||
|
board[2, col]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// X-MUSTER
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
bool x1 =
|
||||||
|
board[0, 0] == board[1, 1] &&
|
||||||
|
board[1, 1] == board[2, 2];
|
||||||
|
|
||||||
|
bool x2 =
|
||||||
|
board[0, 5] == board[1, 4] &&
|
||||||
|
board[1, 4] == board[2, 3];
|
||||||
|
|
||||||
|
bool xMuster =
|
||||||
|
x1 &&
|
||||||
|
x2 &&
|
||||||
|
board[0, 0] == board[0, 5];
|
||||||
|
|
||||||
|
if (xMuster)
|
||||||
|
{
|
||||||
|
multiplikator += X_MUSTER;
|
||||||
|
|
||||||
|
// Sound-ID für X-Muster
|
||||||
|
highestWin = Math.Max(highestWin, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// RAND
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
int randId = board[0, 0];
|
||||||
|
|
||||||
|
bool randGleich =
|
||||||
|
board[0, 0] == randId &&
|
||||||
|
board[0, 1] == randId &&
|
||||||
|
board[0, 2] == randId &&
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Sound-ID für Rand
|
||||||
|
highestWin = Math.Max(highestWin, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// X + RAND
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
if (randGleich && xMuster)
|
||||||
|
{
|
||||||
|
multiplikator += X_UND_RAND;
|
||||||
|
|
||||||
|
// Sound-ID für X + Rand
|
||||||
|
highestWin = Math.Max(highestWin, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// FULLBOARD
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
int first = board[0, 0];
|
||||||
|
|
||||||
|
bool fullBoard = true;
|
||||||
|
|
||||||
|
for (int row = 0; row < 3; row++)
|
||||||
|
{
|
||||||
|
for (int col = 0; col < 6; col++)
|
||||||
|
{
|
||||||
|
if (board[row, col] != first)
|
||||||
|
{
|
||||||
|
fullBoard = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fullBoard)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fullBoard)
|
||||||
|
{
|
||||||
|
multiplikator += FULLBOARD;
|
||||||
|
|
||||||
|
// Fullboard = Sound-ID 12
|
||||||
|
highestWin = 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// SOUND
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
if (multiplikator > 0)
|
||||||
|
{
|
||||||
|
PlayWinSound();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// AUSZAHLUNG
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
return einsatz * multiplikator;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =========================================================
|
||||||
|
// CHECK LINE
|
||||||
|
// =========================================================
|
||||||
|
|
||||||
|
private decimal CheckLine(params int[] werte)
|
||||||
|
{
|
||||||
|
if (werte.Length < 3)
|
||||||
|
return 0m;
|
||||||
|
|
||||||
|
decimal gewinn = 0m;
|
||||||
|
|
||||||
|
int start = 0;
|
||||||
|
|
||||||
|
while (start < werte.Length)
|
||||||
|
{
|
||||||
|
int gleiche = 1;
|
||||||
|
|
||||||
|
while (start + gleiche < werte.Length &&
|
||||||
|
werte[start + gleiche] == werte[start])
|
||||||
|
{
|
||||||
|
gleiche++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// =========================================================
|
||||||
|
|
||||||
|
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 Colin Langer
|
||||||
|
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||||
|
{
|
||||||
|
e.Handled = !_regex.IsMatch(e.Text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keine Spaces Colin Langer
|
||||||
|
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Key == Key.Space)
|
||||||
|
{
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//das man nichts reinkopieren kann außer Zahlen Colin Langer
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+15
-11
@@ -1,33 +1,37 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Casino
|
namespace Casino
|
||||||
{
|
{
|
||||||
public class User
|
public class User // Lenard Gerdes
|
||||||
{
|
{
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public int Alter { get; set; }
|
public int Alter { get; set; }
|
||||||
public string Passwort { get; set; }
|
public string Passwort { get; set; }
|
||||||
public int Geld { 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();
|
ID = ID_Generation();
|
||||||
Name = n;
|
Name = name;
|
||||||
Alter = a;
|
Alter = age;
|
||||||
Passwort = p;
|
Passwort = passwort;
|
||||||
Geld = 1000;
|
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;
|
ID = id;
|
||||||
Name = n;
|
Name = name;
|
||||||
Alter = a;
|
Alter = age;
|
||||||
Passwort = p;
|
Passwort = passwort;
|
||||||
Geld = g;
|
Geld = geld;
|
||||||
|
Rolle = rolle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ID_Generation()
|
private string ID_Generation()
|
||||||
|
|||||||
Reference in New Issue
Block a user