diff --git a/Casino/Busfahrer.xaml b/Casino/Busfahrer.xaml index fb5fdbf..9633e83 100644 --- a/Casino/Busfahrer.xaml +++ b/Casino/Busfahrer.xaml @@ -79,12 +79,13 @@ - - + + - - + + + \ No newline at end of file diff --git a/Casino/Busfahrer.xaml.cs b/Casino/Busfahrer.xaml.cs index 7b18714..91ae58b 100644 --- a/Casino/Busfahrer.xaml.cs +++ b/Casino/Busfahrer.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -22,7 +23,10 @@ namespace Casino public int NumericValue { get; set; } public bool IsRed => FarbeRaw.Equals("Hearts", StringComparison.OrdinalIgnoreCase) || - FarbeRaw.Equals("Diamond", 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) { @@ -73,16 +77,28 @@ namespace Casino private List 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; + private int currentPhase = 0; + private decimal currentBet = 0; + private decimal currentProfit = 0; + + private Database db = new Database(); + private ObservableCollection users; public Busfahrer() { InitializeComponent(); + users = db.GetUser(); + + UpdateAccountDisplay(); StartNewGame(); } + private void UpdateAccountDisplay() + { + users = db.GetUser(); + Konto.Text = users[MainWindow.currentUser].Geld.ToString(); + } + private void BtnStart_Click(object sender, RoutedEventArgs e) { StartNewGame(); @@ -91,9 +107,17 @@ namespace Casino private void StartNewGame() { + decimal currentgeld = users[MainWindow.currentUser].Geld; + + + // 1. Einsatz sofort auf dem Konto abziehen & in der Datenbank speichern + currentgeld -= Convert.ToInt32(currentBet); + db.UpdateGeld(users[MainWindow.currentUser].ID, currentgeld); + UpdateAccountDisplay(); + + currentProfit = 0; UpdateWinDisplay(); - Database db = new Database(); deck = db.GetAllCards(); byte[] backBytes = db.GetCardBackImage(); @@ -151,24 +175,34 @@ namespace Casino if (!success) { RevealCurrentCard(); - MessageBox.Show("Wrong guess! You lost your bet. Game will restart.", "Bus Driver", MessageBoxButton.OK, MessageBoxImage.Information); - StartNewGame(); + currentProfit = 0; + UpdateWinDisplay(); + SetPhaseUI(); 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 + 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; } UpdateWinDisplay(); UpdateHandUI(); SetPhaseUI(); + + // Automatische Auszahlung bei Gewinn von Runde 4 + if (currentPhase == 4) + { + var currentUser = users[MainWindow.currentUser]; + currentUser.Geld += Convert.ToInt32(currentProfit); + db.UpdateGeld(currentUser.ID, currentUser.Geld); + UpdateAccountDisplay(); + + } } private void UpdateWinDisplay() @@ -176,18 +210,25 @@ namespace Casino BtnCashOut.Content = $"Cash Out (${currentProfit:F2})"; } - // --- CASH OUT BUTTON EVENT --- + // CASH OUT BUTTON private void BtnCashOut_Click(object sender, RoutedEventArgs e) { if (currentProfit > 0) { - StartNewGame(); + 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(); } } - // --- BUTTON EVENTS --- - - // ROUND 1: Red / Black + // RUNDEN BUTTONS private void BtnRed_Click(object sender, RoutedEventArgs e) => GuessColor(CardColor.Red); private void BtnBlack_Click(object sender, RoutedEventArgs e) => GuessColor(CardColor.Black); @@ -199,7 +240,6 @@ namespace Casino 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); @@ -212,7 +252,6 @@ namespace Casino 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); @@ -227,7 +266,6 @@ namespace Casino ProcessGuess(ok); } - // ROUND 4: Suit private void BtnSuit_Click(object sender, RoutedEventArgs e) { if (sender is Button btn && btn.Tag != null) @@ -236,45 +274,31 @@ namespace Casino 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)); + (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); } } - // --- 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 > 1 && 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; + 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; } } @@ -298,19 +322,18 @@ namespace Casino image.Freeze(); return image; } - - // ============= - // NUMBER FIELD - // ============= + // ======================= + // NUMBER FIELD VALIDATION + // ======================= private static readonly Regex _regex = new Regex("^[0-9]"); - private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e) + private void TxtBet_PreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = !_regex.IsMatch(e.Text); } - private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e) + private void TxtBet_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Space) { @@ -318,7 +341,7 @@ namespace Casino } } - private void TextBox_Pasting(object sender, DataObjectPastingEventArgs e) + private void TxtBet_Pasting(object sender, DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(typeof(String))) { diff --git a/Casino/Login.xaml.cs b/Casino/Login.xaml.cs index 48e595a..120a71a 100644 --- a/Casino/Login.xaml.cs +++ b/Casino/Login.xaml.cs @@ -28,6 +28,7 @@ namespace Casino public Login() { InitializeComponent(); + Console.WriteLine(HashPassword("Mast")); }