Busfahrer bitte letztes mal überarbeitet ich hasse das alles hier bitte erschiest mich
This commit is contained in:
+239
-36
@@ -5,10 +5,13 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Casino"
|
||||
mc:Ignorable="d"
|
||||
Title="Bus Driver" Height="1080" Width="1960"
|
||||
Title="Bus Driver"
|
||||
Height="1080"
|
||||
Width="1960"
|
||||
WindowState="Maximized"
|
||||
WindowStyle="None"
|
||||
Background="#2C3E50">
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
@@ -25,67 +28,267 @@
|
||||
<ColumnDefinition Width="280"/>
|
||||
<ColumnDefinition Width="100"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="70"/>
|
||||
<RowDefinition Height="270"/>
|
||||
<RowDefinition Height="270"/>
|
||||
<!-- Cards row -->
|
||||
<RowDefinition Height="270"/>
|
||||
<!-- Buttons row -->
|
||||
<RowDefinition Height="200"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Main Menu Button top left -->
|
||||
<Button Grid.Column="0" Grid.Row="0" Content="Main Menu" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Hauptmenue" Width="100" Height="40"/>
|
||||
<!-- Main Menu -->
|
||||
<Button Grid.Column="0"
|
||||
Grid.Row="0"
|
||||
Content="Main Menu"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Click="Hauptmenue"
|
||||
Width="100"
|
||||
Height="40"/>
|
||||
|
||||
<!-- CARDS (Row 2) -->
|
||||
<!-- Karten -->
|
||||
<Image Grid.Column="3" Grid.Row="2" x:Name="Bild_1" Margin="5" Stretch="Uniform"/>
|
||||
<Image Grid.Column="5" Grid.Row="2" x:Name="Bild_2" Margin="5" Stretch="Uniform"/>
|
||||
<Image Grid.Column="7" Grid.Row="2" x:Name="Bild_3" Margin="5" Stretch="Uniform"/>
|
||||
<Image Grid.Column="9" Grid.Row="2" x:Name="Bild_4" Margin="5" Stretch="Uniform"/>
|
||||
|
||||
<!-- BUTTONS BELOW CARDS (Row 3) -->
|
||||
<!-- Round 1: Red / Black -->
|
||||
<StackPanel x:Name="PanelRedBlack" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="7" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,20,0,0">
|
||||
<Button x:Name="BtnRed" Content="Red" Width="120" Height="50" Margin="10" Background="#E74C3C" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnRed_Click"/>
|
||||
<Button x:Name="BtnBlack" Content="Black" Width="120" Height="50" Margin="10" Background="#2C3E50" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnBlack_Click"/>
|
||||
<!-- Frage 1: Rot / Schwarz -->
|
||||
<StackPanel x:Name="PanelRedBlack"
|
||||
Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="7"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,20,0,0">
|
||||
|
||||
<Button Content="Red"
|
||||
Width="120"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#E74C3C"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="ColorButton_Click"
|
||||
Tag="Red"/>
|
||||
|
||||
<Button Content="Black"
|
||||
Width="120"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#2C3E50"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="ColorButton_Click"
|
||||
Tag="Black"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Round 2: Higher / Lower -->
|
||||
<StackPanel x:Name="PanelHigherLower" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="7" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,20,0,0" Visibility="Collapsed">
|
||||
<Button x:Name="BtnHigher" Content="Higher" Width="120" Height="50" Margin="10" Background="#2ECC71" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnHigher_Click"/>
|
||||
<Button x:Name="BtnLower" Content="Lower" Width="120" Height="50" Margin="10" Background="#E67E22" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnLower_Click"/>
|
||||
<!-- Frage 2: Höher / Niedriger -->
|
||||
<StackPanel x:Name="PanelHigherLower"
|
||||
Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="7"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,20,0,0"
|
||||
Visibility="Collapsed">
|
||||
|
||||
<Button Content="Higher"
|
||||
Width="120"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#2ECC71"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="HigherLowerButton_Click"
|
||||
Tag="Higher"/>
|
||||
|
||||
<Button Content="Lower"
|
||||
Width="120"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#E67E22"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="HigherLowerButton_Click"
|
||||
Tag="Lower"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Round 3: Inside / Outside -->
|
||||
<StackPanel x:Name="PanelInsideOutside" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="7" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,20,0,0" Visibility="Collapsed">
|
||||
<Button x:Name="BtnInside" Content="Inside" Width="130" Height="50" Margin="10" Background="#9B59B6" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnInside_Click"/>
|
||||
<Button x:Name="BtnOutside" Content="Outside" Width="130" Height="50" Margin="10" Background="#3498DB" Foreground="White" FontSize="18" FontWeight="Bold" Click="BtnOutside_Click"/>
|
||||
<!-- Frage 3: Innen / Außen -->
|
||||
<StackPanel x:Name="PanelInsideOutside"
|
||||
Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="7"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,20,0,0"
|
||||
Visibility="Collapsed">
|
||||
|
||||
<Button Content="Inside"
|
||||
Width="130"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#9B59B6"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="InsideOutsideButton_Click"
|
||||
Tag="Inside"/>
|
||||
|
||||
<Button Content="Outside"
|
||||
Width="130"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#3498DB"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Click="InsideOutsideButton_Click"
|
||||
Tag="Outside"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Round 4: Suit selection -->
|
||||
<StackPanel x:Name="PanelSuit" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="7" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,20,0,0" Visibility="Collapsed">
|
||||
<Button x:Name="BtnHearts" Content="♥ Hearts" Width="110" Height="50" Margin="5" Background="#E74C3C" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnSuit_Click" Tag="Hearts"/>
|
||||
<Button x:Name="BtnDiamonds" Content="♦ Diamonds" Width="110" Height="50" Margin="5" Background="#E74C3C" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnSuit_Click" Tag="Diamonds"/>
|
||||
<Button x:Name="BtnSpades" Content="♠ Spades" Width="110" Height="50" Margin="5" Background="#2C3E50" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnSuit_Click" Tag="Spades"/>
|
||||
<Button x:Name="BtnClubs" Content="♣ Clubs" Width="110" Height="50" Margin="5" Background="#2C3E50" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnSuit_Click" Tag="Clubs"/>
|
||||
<!-- Frage 4: Symbol -->
|
||||
<StackPanel x:Name="PanelSuit"
|
||||
Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="7"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,20,0,0"
|
||||
Visibility="Collapsed">
|
||||
|
||||
<Button Content="♥ Hearts"
|
||||
Width="110"
|
||||
Height="50"
|
||||
Margin="5"
|
||||
Background="#E74C3C"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnSuit_Click"
|
||||
Tag="Hearts"/>
|
||||
|
||||
<Button Content="♦ Diamonds"
|
||||
Width="110"
|
||||
Height="50"
|
||||
Margin="5"
|
||||
Background="#E74C3C"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnSuit_Click"
|
||||
Tag="Diamonds"/>
|
||||
|
||||
<Button Content="♠ Spades"
|
||||
Width="110"
|
||||
Height="50"
|
||||
Margin="5"
|
||||
Background="#2C3E50"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnSuit_Click"
|
||||
Tag="Spades"/>
|
||||
|
||||
<Button Content="♣ Clubs"
|
||||
Width="110"
|
||||
Height="50"
|
||||
Margin="5"
|
||||
Background="#2C3E50"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnSuit_Click"
|
||||
Tag="Clubs"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Cash Out / Start / Next Buttons -->
|
||||
<StackPanel Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="7" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,20">
|
||||
<Button x:Name="BtnCashOut" Content="Cash Out (0.00)" Width="180" Height="50" Margin="10" Background="#27AE60" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnCashOut_Click" Visibility="Collapsed"/>
|
||||
<Button x:Name="BtnStart" Content="Start New Game" Width="180" Height="50" Margin="10" Background="#1ABC9C" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnStart_Click"/>
|
||||
<!-- Cash Out / Start -->
|
||||
<StackPanel Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Grid.ColumnSpan="7"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="0,0,0,20">
|
||||
|
||||
<Button x:Name="BtnCashOut"
|
||||
Content="Cash Out ($0.00)"
|
||||
Width="180"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#27AE60"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnCashOut_Click"
|
||||
Visibility="Collapsed"/>
|
||||
|
||||
<Button x:Name="BtnStart"
|
||||
Content="Start New Game"
|
||||
Width="180"
|
||||
Height="50"
|
||||
Margin="10"
|
||||
Background="#1ABC9C"
|
||||
Foreground="White"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Click="BtnStart_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Bet Input and Current Win Text Display -->
|
||||
<StackPanel Grid.Column="5" Grid.ColumnSpan="3" Grid.Row="4" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock x:Name="Txteinsatztext" Text="Einsatz" Foreground="White" FontSize="14" HorizontalAlignment="Center" Margin="0,0,0,5"/>
|
||||
<TextBox x:Name="TxtBet" Height="40" Width="192" Background="DimGray" Foreground="White" FontSize="18" TextAlignment="Center" VerticalContentAlignment="Center" PreviewTextInput="TxtBet_PreviewTextInput" PreviewKeyDown="TxtBet_PreviewKeyDown" DataObject.Pasting="TxtBet_Pasting"/>
|
||||
<!-- Einsatz -->
|
||||
<StackPanel Grid.Column="5"
|
||||
Grid.ColumnSpan="3"
|
||||
Grid.Row="4"
|
||||
Orientation="Vertical"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
|
||||
<TextBlock x:Name="Txteinsatztext"
|
||||
Text="Einsatz"
|
||||
Foreground="White"
|
||||
FontSize="14"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,5"/>
|
||||
|
||||
<TextBox x:Name="TxtBet"
|
||||
Height="40"
|
||||
Width="192"
|
||||
Background="DimGray"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
TextAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
PreviewTextInput="TxtBet_PreviewTextInput"
|
||||
PreviewKeyDown="TxtBet_PreviewKeyDown"
|
||||
DataObject.Pasting="TxtBet_Pasting"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Column="11" Grid.Row="4" Text="Konto" Margin="0,108,0,-8" Foreground="White" FontSize="14" HorizontalAlignment="Center"/>
|
||||
<TextBlock x:Name="Konto" Grid.Column="11" Grid.Row="4" Height="30" Width="100" Margin="90,133,90,37" Background="DarkRed" Foreground="Silver" TextAlignment="Right" FontSize="25"/>
|
||||
|
||||
<!-- Konto -->
|
||||
<TextBlock Grid.Column="11"
|
||||
Grid.Row="4"
|
||||
Text="Konto"
|
||||
Margin="0,108,0,-8"
|
||||
Foreground="White"
|
||||
FontSize="14"
|
||||
HorizontalAlignment="Center"/>
|
||||
|
||||
<TextBlock x:Name="Konto"
|
||||
Grid.Column="11"
|
||||
Grid.Row="4"
|
||||
Height="30"
|
||||
Width="100"
|
||||
Margin="90,133,90,37"
|
||||
Background="DarkRed"
|
||||
Foreground="Silver"
|
||||
TextAlignment="Right"
|
||||
FontSize="25"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
+407
-158
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
@@ -22,11 +23,12 @@ namespace Casino
|
||||
public ImageSource Image { get; set; } = null!;
|
||||
public int NumericValue { get; set; }
|
||||
|
||||
public bool IsRed => FarbeRaw.Equals("Hearts", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Diamonds", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Diamond", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Herz", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Karo", StringComparison.OrdinalIgnoreCase);
|
||||
public bool IsRed =>
|
||||
FarbeRaw.Equals("Hearts", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Diamonds", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Diamond", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Herz", StringComparison.OrdinalIgnoreCase) ||
|
||||
FarbeRaw.Equals("Karo", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public Card(int id, string wert, string farbe, byte[] imgBytes)
|
||||
{
|
||||
@@ -34,31 +36,29 @@ namespace Casino
|
||||
WertRaw = wert;
|
||||
FarbeRaw = farbe;
|
||||
NumericValue = ParseValue(wert);
|
||||
|
||||
if (imgBytes != null && imgBytes.Length > 0)
|
||||
{
|
||||
Image = ByteArrayToImage(imgBytes);
|
||||
}
|
||||
}
|
||||
|
||||
private int ParseValue(string wert)
|
||||
private static int ParseValue(string wert)
|
||||
{
|
||||
return wert.Trim() switch
|
||||
{
|
||||
"Jack" => 11,
|
||||
"Bube" => 11,
|
||||
"Queen" => 12,
|
||||
"Dame" => 12,
|
||||
"King" => 13,
|
||||
"König" => 13,
|
||||
"Ace" => 14,
|
||||
"Ass" => 14,
|
||||
_ => int.TryParse(wert, out int v) ? v : 0
|
||||
"Jack" or "Bube" => 11,
|
||||
"Queen" or "Dame" => 12,
|
||||
"King" or "König" => 13,
|
||||
"Ace" or "Ass" => 14,
|
||||
_ => int.TryParse(wert, out int value) ? value : 0
|
||||
};
|
||||
}
|
||||
|
||||
private static BitmapImage ByteArrayToImage(byte[] bytes)
|
||||
{
|
||||
BitmapImage image = new BitmapImage();
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(bytes))
|
||||
{
|
||||
image.BeginInit();
|
||||
@@ -66,229 +66,431 @@ namespace Casino
|
||||
image.StreamSource = ms;
|
||||
image.EndInit();
|
||||
}
|
||||
|
||||
image.Freeze();
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
public enum CardColor { Red, Black }
|
||||
private readonly Database db = new Database();
|
||||
private ObservableCollection<User> users;
|
||||
|
||||
private List<Card> deck = new();
|
||||
private List<Card> handCards = new();
|
||||
private List<Card> deck = new List<Card>();
|
||||
private List<Card> handCards = new List<Card>();
|
||||
private ImageSource cardBackImage = null!;
|
||||
|
||||
private int currentPhase = 0;
|
||||
private decimal currentBet = 0;
|
||||
private decimal currentProfit = 0;
|
||||
private bool roundRunning = false;
|
||||
|
||||
private Database db = new Database();
|
||||
private ObservableCollection<User> users;
|
||||
private static readonly Regex NumberRegex = new Regex("^[0-9]+$");
|
||||
|
||||
public Busfahrer()
|
||||
{
|
||||
InitializeComponent();
|
||||
users = db.GetUser();
|
||||
|
||||
users = db.GetUser();
|
||||
UpdateAccountDisplay();
|
||||
|
||||
StartNewGame();
|
||||
ShowWaitingState();
|
||||
}
|
||||
|
||||
private User CurrentUser => users[MainWindow.currentUser];
|
||||
|
||||
// =========================
|
||||
// KONTO
|
||||
// =========================
|
||||
|
||||
private void UpdateAccountDisplay()
|
||||
{
|
||||
users = db.GetUser();
|
||||
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||
Konto.Text = CurrentUser.Geld.ToString();
|
||||
}
|
||||
|
||||
private void SaveAccount()
|
||||
{
|
||||
db.UpdateGeld(CurrentUser.ID, CurrentUser.Geld);
|
||||
UpdateAccountDisplay();
|
||||
}
|
||||
|
||||
// =========================
|
||||
// SPIEL STARTEN
|
||||
// =========================
|
||||
|
||||
private void BtnStart_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
StartNewGame();
|
||||
StartGameFromInput();
|
||||
}
|
||||
|
||||
private void StartNewGame()
|
||||
private void StartGameFromInput()
|
||||
{
|
||||
if (roundRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
decimal currentgeld = users[MainWindow.currentUser].Geld;
|
||||
if (!int.TryParse(TxtBet.Text, out int bet) || bet <= 0)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Bitte gib einen gültigen Einsatz ein.",
|
||||
"Ungültiger Einsatz",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. Einsatz sofort auf dem Konto abziehen & in der Datenbank speichern
|
||||
db.UpdateGeld(users[MainWindow.currentUser].ID, currentgeld);
|
||||
UpdateAccountDisplay();
|
||||
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();
|
||||
}
|
||||
|
||||
private void StartRound()
|
||||
{
|
||||
if (currentBet <= 0 || currentBet > CurrentUser.Geld)
|
||||
{
|
||||
ShowWaitingState();
|
||||
return;
|
||||
}
|
||||
|
||||
// Einsatz vom Konto abziehen
|
||||
CurrentUser.Geld -= Convert.ToInt32(currentBet);
|
||||
SaveAccount();
|
||||
|
||||
currentProfit = 0;
|
||||
UpdateWinDisplay();
|
||||
currentPhase = 0;
|
||||
roundRunning = true;
|
||||
TxtBet.IsEnabled = false;
|
||||
|
||||
LoadCards();
|
||||
UpdateHandUI();
|
||||
UpdateWinDisplay();
|
||||
SetPhaseUI();
|
||||
}
|
||||
|
||||
private void LoadCards()
|
||||
{
|
||||
deck = db.GetAllCards()
|
||||
.OrderBy(_ => Random.Shared.Next())
|
||||
.ToList();
|
||||
|
||||
deck = db.GetAllCards();
|
||||
byte[] backBytes = db.GetCardBackImage();
|
||||
|
||||
if (backBytes != null)
|
||||
if (backBytes != null && backBytes.Length > 0)
|
||||
{
|
||||
cardBackImage = ByteArrayToImage(backBytes);
|
||||
}
|
||||
|
||||
Random ran = new Random();
|
||||
deck = deck.OrderBy(_ => ran.Next()).ToList();
|
||||
|
||||
handCards.Clear();
|
||||
currentPhase = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4 && deck.Count > 0; i++)
|
||||
{
|
||||
if (deck.Count > 0)
|
||||
{
|
||||
handCards.Add(DrawCard());
|
||||
}
|
||||
handCards.Add(DrawCard());
|
||||
}
|
||||
|
||||
UpdateHandUI();
|
||||
SetPhaseUI();
|
||||
}
|
||||
|
||||
private Card DrawCard()
|
||||
{
|
||||
var card = deck[0];
|
||||
Card card = deck[0];
|
||||
deck.RemoveAt(0);
|
||||
return card;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// KARTEN ANZEIGEN
|
||||
// =========================
|
||||
|
||||
private void UpdateHandUI()
|
||||
{
|
||||
Bild_1.Source = (currentPhase > 0) ? handCards[0].Image : cardBackImage;
|
||||
Bild_2.Source = (currentPhase > 1) ? handCards[1].Image : cardBackImage;
|
||||
Bild_3.Source = (currentPhase > 2) ? handCards[2].Image : cardBackImage;
|
||||
Bild_4.Source = (currentPhase > 3) ? handCards[3].Image : cardBackImage;
|
||||
Bild_1.Source = cardBackImage;
|
||||
Bild_2.Source = cardBackImage;
|
||||
Bild_3.Source = cardBackImage;
|
||||
Bild_4.Source = cardBackImage;
|
||||
|
||||
if (handCards.Count < 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentPhase >= 1)
|
||||
{
|
||||
Bild_1.Source = handCards[0].Image;
|
||||
}
|
||||
|
||||
if (currentPhase >= 2)
|
||||
{
|
||||
Bild_2.Source = handCards[1].Image;
|
||||
}
|
||||
|
||||
if (currentPhase >= 3)
|
||||
{
|
||||
Bild_3.Source = handCards[2].Image;
|
||||
}
|
||||
|
||||
if (currentPhase >= 4)
|
||||
{
|
||||
Bild_4.Source = handCards[3].Image;
|
||||
}
|
||||
}
|
||||
|
||||
private void RevealCurrentCard()
|
||||
{
|
||||
if (handCards.Count < 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (currentPhase)
|
||||
{
|
||||
case 0: Bild_1.Source = handCards[0].Image; break;
|
||||
case 1: Bild_2.Source = handCards[1].Image; break;
|
||||
case 2: Bild_3.Source = handCards[2].Image; break;
|
||||
case 3: Bild_4.Source = handCards[3].Image; break;
|
||||
case 0:
|
||||
Bild_1.Source = handCards[0].Image;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
Bild_2.Source = handCards[1].Image;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
Bild_3.Source = handCards[2].Image;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
Bild_4.Source = handCards[3].Image;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessGuess(bool success)
|
||||
// =========================
|
||||
// SPIELLOGIK
|
||||
// =========================
|
||||
|
||||
private async Task ProcessGuessAsync(bool success)
|
||||
{
|
||||
if (!roundRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RevealCurrentCard();
|
||||
|
||||
if (!success)
|
||||
{
|
||||
RevealCurrentCard();
|
||||
roundRunning = false;
|
||||
currentProfit = 0;
|
||||
UpdateWinDisplay();
|
||||
SetPhaseUI();
|
||||
StartNewGame();
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
// Nächste Runde mit demselben Einsatz
|
||||
if (currentBet <= CurrentUser.Geld)
|
||||
{
|
||||
StartRound();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowWaitingState();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
currentPhase++;
|
||||
switch (currentPhase)
|
||||
{
|
||||
case 1: currentProfit = currentBet * 1.75m; break;
|
||||
case 2: currentProfit = currentBet * 2.5m; break;
|
||||
case 3: currentProfit = currentBet * 5.0m; break;
|
||||
case 4: currentProfit = currentBet * 20.0m; break;
|
||||
}
|
||||
currentProfit = CalculateCurrentProfit();
|
||||
|
||||
UpdateWinDisplay();
|
||||
UpdateHandUI();
|
||||
UpdateWinDisplay();
|
||||
SetPhaseUI();
|
||||
|
||||
// Automatische Auszahlung bei Gewinn von Runde 4
|
||||
// Vierte Frage richtig -> automatisch auszahlen
|
||||
if (currentPhase == 4)
|
||||
{
|
||||
var currentUser = users[MainWindow.currentUser];
|
||||
currentUser.Geld += Convert.ToInt32(currentProfit);
|
||||
db.UpdateGeld(currentUser.ID, currentUser.Geld);
|
||||
UpdateAccountDisplay();
|
||||
roundRunning = false;
|
||||
|
||||
PayoutCurrentProfit();
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
// Neue Runde automatisch starten
|
||||
if (currentBet <= CurrentUser.Geld)
|
||||
{
|
||||
StartRound();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowWaitingState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateWinDisplay()
|
||||
private decimal CalculateCurrentProfit()
|
||||
{
|
||||
BtnCashOut.Content = $"Cash Out (${currentProfit:F2})";
|
||||
return currentPhase switch
|
||||
{
|
||||
1 => currentBet * 1.75m,
|
||||
2 => currentBet * 2.5m,
|
||||
3 => currentBet * 5.0m,
|
||||
4 => currentBet * 20.0m,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
// CASH OUT BUTTON
|
||||
// =========================
|
||||
// FRAGEN
|
||||
// =========================
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private static bool IsSameSuit(string cardSuit, string chosenSuit)
|
||||
{
|
||||
if (cardSuit.Equals(chosenSuit, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return chosenSuit switch
|
||||
{
|
||||
"Hearts" => cardSuit.Equals("Herz", StringComparison.OrdinalIgnoreCase),
|
||||
"Diamonds" => cardSuit.Equals("Karo", StringComparison.OrdinalIgnoreCase) ||
|
||||
cardSuit.Equals("Diamond", StringComparison.OrdinalIgnoreCase),
|
||||
"Spades" => cardSuit.Equals("Pik", StringComparison.OrdinalIgnoreCase),
|
||||
"Clubs" => cardSuit.Equals("Kreuz", StringComparison.OrdinalIgnoreCase),
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
|
||||
private enum CardColor
|
||||
{
|
||||
Red,
|
||||
Black
|
||||
}
|
||||
|
||||
// =========================
|
||||
// CASH OUT
|
||||
// =========================
|
||||
|
||||
private void BtnCashOut_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (currentProfit > 0)
|
||||
if (!roundRunning || currentProfit <= 0)
|
||||
{
|
||||
var currentUser = users[MainWindow.currentUser];
|
||||
currentUser.Geld += Convert.ToInt32(currentProfit);
|
||||
db.UpdateGeld(currentUser.ID, currentUser.Geld);
|
||||
UpdateAccountDisplay();
|
||||
|
||||
MessageBox.Show($"Du hast dir ${currentProfit:F2} auszahlen lassen!", "Cash Out", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
currentProfit = 0;
|
||||
UpdateWinDisplay();
|
||||
SetPhaseUI();
|
||||
return;
|
||||
}
|
||||
|
||||
roundRunning = false;
|
||||
|
||||
decimal payout = currentProfit;
|
||||
PayoutCurrentProfit();
|
||||
|
||||
MessageBox.Show(
|
||||
$"Du hast ${payout:F2} ausgezahlt bekommen!",
|
||||
"Cash Out",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
|
||||
ShowWaitingState();
|
||||
}
|
||||
|
||||
// RUNDEN BUTTONS
|
||||
private void BtnRed_Click(object sender, RoutedEventArgs e) => GuessColor(CardColor.Red);
|
||||
private void BtnBlack_Click(object sender, RoutedEventArgs e) => GuessColor(CardColor.Black);
|
||||
|
||||
private void GuessColor(CardColor chosenColor)
|
||||
private void PayoutCurrentProfit()
|
||||
{
|
||||
Card targetCard = handCards[0];
|
||||
bool ok = (chosenColor == CardColor.Red && targetCard.IsRed) ||
|
||||
(chosenColor == CardColor.Black && !targetCard.IsRed);
|
||||
ProcessGuess(ok);
|
||||
var currentUser = users[MainWindow.currentUser];
|
||||
currentBet -= Convert.ToInt32(TxtBet.Text);
|
||||
db.UpdateGeld(currentUser.ID, currentUser.Geld);
|
||||
UpdateAccountDisplay();
|
||||
|
||||
}
|
||||
|
||||
private void BtnHigher_Click(object sender, RoutedEventArgs e) => GuessHigherLower(true);
|
||||
private void BtnLower_Click(object sender, RoutedEventArgs e) => GuessHigherLower(false);
|
||||
|
||||
private void GuessHigherLower(bool higher)
|
||||
{
|
||||
Card card1 = handCards[0];
|
||||
Card card2 = handCards[1];
|
||||
|
||||
bool ok = higher ? card2.NumericValue > card1.NumericValue : card2.NumericValue < card1.NumericValue;
|
||||
ProcessGuess(ok);
|
||||
}
|
||||
|
||||
private void BtnInside_Click(object sender, RoutedEventArgs e) => GuessInside(true);
|
||||
private void BtnOutside_Click(object sender, RoutedEventArgs e) => GuessInside(false);
|
||||
|
||||
private void GuessInside(bool inside)
|
||||
{
|
||||
Card card3 = handCards[2];
|
||||
int min = Math.Min(handCards[0].NumericValue, handCards[1].NumericValue);
|
||||
int max = Math.Max(handCards[0].NumericValue, handCards[1].NumericValue);
|
||||
|
||||
bool isBetween = card3.NumericValue > min && card3.NumericValue < max;
|
||||
bool ok = inside ? isBetween : !isBetween;
|
||||
ProcessGuess(ok);
|
||||
}
|
||||
|
||||
private void BtnSuit_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button btn && btn.Tag != null)
|
||||
if (currentProfit <= 0)
|
||||
{
|
||||
string chosenSuit = btn.Tag.ToString()!;
|
||||
Card card4 = handCards[3];
|
||||
|
||||
bool ok = card4.FarbeRaw.Equals(chosenSuit, StringComparison.OrdinalIgnoreCase) ||
|
||||
(chosenSuit.Equals("Hearts", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Herz", StringComparison.OrdinalIgnoreCase)) ||
|
||||
(chosenSuit.Equals("Diamonds", StringComparison.OrdinalIgnoreCase) && (card4.FarbeRaw.Equals("Karo", StringComparison.OrdinalIgnoreCase) || card4.FarbeRaw.Equals("Diamond", StringComparison.OrdinalIgnoreCase))) ||
|
||||
(chosenSuit.Equals("Spades", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Pik", StringComparison.OrdinalIgnoreCase)) ||
|
||||
(chosenSuit.Equals("Clubs", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Kreuz", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
ProcessGuess(ok);
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentUser.Geld += Convert.ToInt32(currentProfit);
|
||||
SaveAccount();
|
||||
}
|
||||
|
||||
// =========================
|
||||
// UI
|
||||
// =========================
|
||||
|
||||
private void SetPhaseUI()
|
||||
{
|
||||
PanelRedBlack.Visibility = Visibility.Collapsed;
|
||||
@@ -296,27 +498,72 @@ namespace Casino
|
||||
PanelInsideOutside.Visibility = Visibility.Collapsed;
|
||||
PanelSuit.Visibility = Visibility.Collapsed;
|
||||
|
||||
BtnCashOut.Visibility = Visibility.Collapsed;
|
||||
BtnStart.Visibility = Visibility.Collapsed;
|
||||
|
||||
if (!roundRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (currentPhase)
|
||||
{
|
||||
case 0: PanelRedBlack.Visibility = Visibility.Visible; break;
|
||||
case 1: PanelHigherLower.Visibility = Visibility.Visible; BtnCashOut.Visibility = Visibility.Visible;break;
|
||||
case 2: PanelInsideOutside.Visibility = Visibility.Visible; break;
|
||||
case 3: PanelSuit.Visibility = Visibility.Visible; break;
|
||||
case 0:
|
||||
PanelRedBlack.Visibility = Visibility.Visible;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
PanelHigherLower.Visibility = Visibility.Visible;
|
||||
BtnCashOut.Visibility = Visibility.Visible;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
PanelInsideOutside.Visibility = Visibility.Visible;
|
||||
BtnCashOut.Visibility = Visibility.Visible;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
PanelSuit.Visibility = Visibility.Visible;
|
||||
BtnCashOut.Visibility = Visibility.Visible;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowWaitingState()
|
||||
{
|
||||
roundRunning = false;
|
||||
currentPhase = 0;
|
||||
currentProfit = 0;
|
||||
|
||||
UpdateWinDisplay();
|
||||
SetPhaseUI();
|
||||
|
||||
BtnStart.Visibility = Visibility.Visible;
|
||||
TxtBet.IsEnabled = true;
|
||||
}
|
||||
|
||||
private void UpdateWinDisplay()
|
||||
{
|
||||
BtnCashOut.Content = $"Cash Out (${currentProfit:F2})";
|
||||
}
|
||||
|
||||
// =========================
|
||||
// HAUPTMENÜ
|
||||
// =========================
|
||||
|
||||
private void Hauptmenue(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
// =========================
|
||||
// BILD AUS BYTE[]
|
||||
// =========================
|
||||
|
||||
private static BitmapImage ByteArrayToImage(byte[] bytes)
|
||||
{
|
||||
if (bytes == null || bytes.Length == 0) return null!;
|
||||
|
||||
BitmapImage image = new BitmapImage();
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(bytes))
|
||||
{
|
||||
image.BeginInit();
|
||||
@@ -324,18 +571,18 @@ namespace Casino
|
||||
image.StreamSource = ms;
|
||||
image.EndInit();
|
||||
}
|
||||
|
||||
image.Freeze();
|
||||
return image;
|
||||
}
|
||||
// =======================
|
||||
// NUMBER FIELD VALIDATION
|
||||
// =======================
|
||||
|
||||
private static readonly Regex _regex = new Regex("^[0-9]");
|
||||
// =========================
|
||||
// EINSATZ VALIDIERUNG
|
||||
// =========================
|
||||
|
||||
private void TxtBet_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
e.Handled = !_regex.IsMatch(e.Text);
|
||||
e.Handled = !NumberRegex.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
private void TxtBet_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||
@@ -344,20 +591,22 @@ namespace Casino
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void TxtBet_Pasting(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
if (e.DataObject.GetDataPresent(typeof(String)))
|
||||
if (!e.DataObject.GetDataPresent(typeof(string)))
|
||||
{
|
||||
var text = (String)e.DataObject.GetData(typeof(String));
|
||||
if (!_regex.IsMatch((string)text))
|
||||
{
|
||||
e.CancelCommand();
|
||||
}
|
||||
e.CancelCommand();
|
||||
return;
|
||||
}
|
||||
|
||||
string text = (string)e.DataObject.GetData(typeof(string));
|
||||
|
||||
if (!NumberRegex.IsMatch(text))
|
||||
{
|
||||
e.CancelCommand();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user