Busfahrer Spiel fertig
This commit is contained in:
@@ -35,6 +35,6 @@
|
|||||||
<Image Grid.Column="7" Grid.Row="1" x:Name="Dealer_Bild_2"/>
|
<Image Grid.Column="7" Grid.Row="1" x:Name="Dealer_Bild_2"/>
|
||||||
|
|
||||||
<Button Grid.Row="0" Content="Hauptmenü" HorizontalAlignment="Center" Click="Hauptmenue" Width="100"/>
|
<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"/>
|
<TextBox HorizontalAlignment="Right" Height="100" Grid.Row="4" TextWrapping="Wrap" Text="Einsatz" VerticalAlignment="Center" Width="192" PreviewTextInput="TextBox_OnPreviewTextInput" PreviewKeyDown="TextBox_OnPreviewKeyDown" DataObject.Pasting="TextBox_Pasting" Grid.Column="5" Grid.ColumnSpan="3" Margin="0,0,194,0"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ namespace Casino
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Numberfeld
|
||||||
private static readonly Regex _regex = new Regex("[^0-9]"); // Regex to match non-numeric input
|
private static readonly Regex _regex = new Regex("[^0-9]"); // Regex to match non-numeric input
|
||||||
|
|
||||||
//nur nummern
|
//nur nummern
|
||||||
|
|||||||
+73
-25
@@ -5,39 +5,87 @@
|
|||||||
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 Driver" Height="1080" Width="1960"
|
||||||
|
WindowState="Maximized"
|
||||||
|
WindowStyle="None"
|
||||||
|
Background="#2C3E50">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="100"></ColumnDefinition>
|
<ColumnDefinition Width="100"/>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="280"/>
|
||||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
<ColumnDefinition Width="20"/>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="280"/>
|
||||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
<ColumnDefinition Width="20"/>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="280"/>
|
||||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
<ColumnDefinition Width="20"/>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="280"/>
|
||||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
<ColumnDefinition Width="20"/>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="280"/>
|
||||||
<ColumnDefinition Width="20"></ColumnDefinition>
|
<ColumnDefinition Width="20"/>
|
||||||
<ColumnDefinition Width="280"></ColumnDefinition>
|
<ColumnDefinition Width="280"/>
|
||||||
<ColumnDefinition Width="100"></ColumnDefinition>
|
<ColumnDefinition Width="100"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="70"></RowDefinition>
|
<RowDefinition Height="70"/>
|
||||||
<RowDefinition Height="270"></RowDefinition>
|
<RowDefinition Height="270"/>
|
||||||
<RowDefinition Height="270"></RowDefinition>
|
<RowDefinition Height="270"/>
|
||||||
<RowDefinition Height="270"></RowDefinition>
|
<!-- Cards row -->
|
||||||
<RowDefinition Height="200"></RowDefinition>
|
<RowDefinition Height="270"/>
|
||||||
|
<!-- Buttons row -->
|
||||||
|
<RowDefinition Height="200"/>
|
||||||
</Grid.RowDefinitions>
|
</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"/>
|
||||||
|
|
||||||
<Image Grid.Column="3" Grid.Row="2" x:Name="Bild_1"/>
|
<!-- CARDS (Row 2) -->
|
||||||
<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"/>
|
|
||||||
|
|
||||||
|
<!-- 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"/>
|
||||||
|
</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"/>
|
||||||
|
</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"/>
|
||||||
|
</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"/>
|
||||||
|
</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="BtnNextPyramid" Content="Reveal Next Card" Width="200" Height="50" Margin="10" Background="#F39C12" Foreground="White" FontSize="16" FontWeight="Bold" Click="BtnNextPyramid_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 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="TextBox_PreviewTextInput" PreviewKeyDown="TextBox_PreviewKeyDown" DataObject.Pasting="TextBox_Pasting"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<TextBlock Grid.Column="12" Grid.Row="4" Text="Einsatz" Margin="0,100,0,0" Foreground="White" FontSize="14" HorizontalAlignment="Left"/>
|
||||||
|
<TextBlock x:Name="Konto" Grid.Column="11" Grid.Row="4" Height="30" Width="100" Margin="251,133,29,37" Background="DarkRed" Foreground="Silver" TextAlignment="Right" FontSize="25" Grid.ColumnSpan="2"/>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
+266
-37
@@ -2,46 +2,291 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
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.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
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
public Card(int id, string wert, string farbe, byte[] imgBytes)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
WertRaw = wert;
|
||||||
|
FarbeRaw = farbe;
|
||||||
|
NumericValue = ParseValue(wert);
|
||||||
|
if (imgBytes != null && imgBytes.Length > 0)
|
||||||
|
{
|
||||||
|
Image = ByteArrayToImage(imgBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int ParseValue(string wert)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CardColor { Red, Black }
|
||||||
|
|
||||||
|
private List<Card> deck = new();
|
||||||
|
private List<Card> handCards = new();
|
||||||
|
private ImageSource cardBackImage = null!;
|
||||||
|
|
||||||
|
private int currentPhase = 0; // 0: Red/Black, 1: Higher/Lower, 2: In Between/Outside, 3: Suit, 4: Won
|
||||||
|
private double currentBet = 0;
|
||||||
|
private double currentProfit = 0;
|
||||||
|
|
||||||
public Busfahrer()
|
public Busfahrer()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
StartNewGame();
|
||||||
LoadCard(8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadCard(int Bild)
|
private void BtnStart_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
StartNewGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartNewGame()
|
||||||
|
{
|
||||||
|
|
||||||
|
UpdateWinDisplay();
|
||||||
|
|
||||||
Database db = new Database();
|
Database db = new Database();
|
||||||
byte[] img = db.GetCardImage(Bild);
|
deck = db.GetAllCards();
|
||||||
|
byte[] backBytes = db.GetCardBackImage();
|
||||||
|
|
||||||
Bild_4.Source = ByteArrayToImage(img);
|
if (backBytes != null)
|
||||||
|
{
|
||||||
|
cardBackImage = ByteArrayToImage(backBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
Random ran = new Random();
|
||||||
|
deck = deck.OrderBy(_ => ran.Next()).ToList();
|
||||||
|
|
||||||
|
handCards.Clear();
|
||||||
|
currentPhase = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (deck.Count > 0)
|
||||||
|
{
|
||||||
|
handCards.Add(DrawCard());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateHandUI();
|
||||||
|
SetPhaseUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private BitmapImage ByteArrayToImage(byte[] bytes)
|
private Card DrawCard()
|
||||||
{
|
{
|
||||||
|
var card = deck[0];
|
||||||
|
deck.RemoveAt(0);
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RevealCurrentCard()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessGuess(bool success)
|
||||||
|
{
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
RevealCurrentCard();
|
||||||
|
MessageBox.Show("Wrong guess! You lost your bet. Game will restart.", "Bus Driver", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
StartNewGame();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gewinn-Multiplikatoren
|
||||||
|
currentPhase++;
|
||||||
|
switch (currentPhase)
|
||||||
|
{
|
||||||
|
case 1: currentProfit = currentBet * 1.75; break; // Runde 1 bestanden
|
||||||
|
case 2: currentProfit = currentBet * 2.5; break; // Runde 2 bestanden
|
||||||
|
case 3: currentProfit = currentBet * 5.0; break; // Runde 3 bestanden
|
||||||
|
case 4: currentProfit = currentBet * 20.0; break; // Runde 4 bestanden
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateWinDisplay();
|
||||||
|
UpdateHandUI();
|
||||||
|
SetPhaseUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateWinDisplay()
|
||||||
|
{
|
||||||
|
BtnCashOut.Content = $"Cash Out (${currentProfit:F2})";
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- CASH OUT BUTTON EVENT ---
|
||||||
|
private void BtnCashOut_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (currentProfit > 0)
|
||||||
|
{
|
||||||
|
StartNewGame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- BUTTON EVENTS ---
|
||||||
|
|
||||||
|
// ROUND 1: Red / Black
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
Card targetCard = handCards[0];
|
||||||
|
bool ok = (chosenColor == CardColor.Red && targetCard.IsRed) ||
|
||||||
|
(chosenColor == CardColor.Black && !targetCard.IsRed);
|
||||||
|
ProcessGuess(ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ROUND 2: Higher / Lower
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ROUND 3: In Between / Outside
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ROUND 4: Suit
|
||||||
|
private void BtnSuit_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is Button btn && btn.Tag != null)
|
||||||
|
{
|
||||||
|
string chosenSuit = btn.Tag.ToString()!;
|
||||||
|
Card card4 = handCards[3];
|
||||||
|
|
||||||
|
bool ok = card4.FarbeRaw.Equals(chosenSuit, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
(chosenSuit.Equals("Hearts", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Hearts", StringComparison.OrdinalIgnoreCase)) ||
|
||||||
|
(chosenSuit.Equals("Diamond", StringComparison.OrdinalIgnoreCase) && (card4.FarbeRaw.Equals("Diamond", StringComparison.OrdinalIgnoreCase))) ||
|
||||||
|
(chosenSuit.Equals("Spades", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Spades", StringComparison.OrdinalIgnoreCase)) ||
|
||||||
|
(chosenSuit.Equals("Clubs", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Clubs", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
ProcessGuess(ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- BUTTON VISIBILITY CONTROL ---
|
||||||
|
|
||||||
|
private void SetPhaseUI()
|
||||||
|
{
|
||||||
|
PanelRedBlack.Visibility = Visibility.Collapsed;
|
||||||
|
PanelHigherLower.Visibility = Visibility.Collapsed;
|
||||||
|
PanelInsideOutside.Visibility = Visibility.Collapsed;
|
||||||
|
if (PanelSuit != null) PanelSuit.Visibility = Visibility.Collapsed;
|
||||||
|
BtnNextPyramid.Visibility = Visibility.Collapsed;
|
||||||
|
|
||||||
|
// Zeige den Auszahlungs-Button ab Runde 1 (nach dem ersten Gewinn) an
|
||||||
|
BtnCashOut.Visibility = (currentPhase > 0 && currentPhase < 4) ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
|
||||||
|
switch (currentPhase)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
PanelRedBlack.Visibility = Visibility.Visible;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
PanelHigherLower.Visibility = Visibility.Visible;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
PanelInsideOutside.Visibility = Visibility.Visible;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (PanelSuit != null) PanelSuit.Visibility = Visibility.Visible;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
BtnNextPyramid.Visibility = Visibility.Visible;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Hauptmenue(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BitmapImage ByteArrayToImage(byte[] bytes)
|
||||||
|
{
|
||||||
|
if (bytes == null || bytes.Length == 0) return null!;
|
||||||
|
|
||||||
BitmapImage image = new BitmapImage();
|
BitmapImage image = new BitmapImage();
|
||||||
using (MemoryStream ms = new MemoryStream(bytes))
|
using (MemoryStream ms = new MemoryStream(bytes))
|
||||||
{
|
{
|
||||||
@@ -50,35 +295,21 @@ namespace Casino
|
|||||||
image.StreamSource = ms;
|
image.StreamSource = ms;
|
||||||
image.EndInit();
|
image.EndInit();
|
||||||
}
|
}
|
||||||
|
image.Freeze();
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int rand()
|
// =============
|
||||||
{
|
// NUMBER FIELD
|
||||||
Random ran = new Random();
|
// =============
|
||||||
int temp = ran.Next(13, 66);
|
|
||||||
Console.WriteLine(temp);
|
|
||||||
|
|
||||||
return 0;
|
private static readonly Regex _regex = new Regex("^[0-9]");
|
||||||
}
|
|
||||||
|
|
||||||
private void Hauptmenue(object sender, RoutedEventArgs 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)
|
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||||
{
|
{
|
||||||
e.Handled = !_regex.IsMatch(e.Text);
|
e.Handled = !_regex.IsMatch(e.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keine Spaces
|
|
||||||
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
|
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Key == Key.Space)
|
if (e.Key == Key.Space)
|
||||||
@@ -87,18 +318,16 @@ namespace Casino
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//das man nichts reinkopieren kann außer Zahlen
|
|
||||||
private void TextBox_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)));
|
var text = (String)e.DataObject.GetData(typeof(String));
|
||||||
if (!_regex.IsMatch((string)text))
|
if (!_regex.IsMatch((string)text))
|
||||||
{
|
{
|
||||||
e.CancelCommand();
|
e.CancelCommand();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,6 +81,59 @@ namespace Casino
|
|||||||
return imageBytes;
|
return imageBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NEU: Holt das Bild der Kartenrückseite
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
byte[] soundBytes = null;
|
byte[] soundBytes = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user