Busfahrer update
This commit is contained in:
@@ -79,12 +79,13 @@
|
|||||||
|
|
||||||
<!-- Bet Input and Current Win Text Display -->
|
<!-- Bet Input and Current Win Text Display -->
|
||||||
<StackPanel Grid.Column="5" Grid.ColumnSpan="3" Grid.Row="4" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
<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"/>
|
<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="TextBox_PreviewTextInput" PreviewKeyDown="TextBox_PreviewKeyDown" DataObject.Pasting="TextBox_Pasting"/>
|
<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>
|
</StackPanel>
|
||||||
|
|
||||||
<TextBlock Grid.Column="12" Grid.Row="4" Text="Einsatz" Margin="0,100,0,0" Foreground="White" FontSize="14" HorizontalAlignment="Left"/>
|
<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="251,133,29,37" Background="DarkRed" Foreground="Silver" TextAlignment="Right" FontSize="25" Grid.ColumnSpan="2"/>
|
<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>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
+72
-49
@@ -1,5 +1,6 @@
|
|||||||
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.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -22,7 +23,10 @@ namespace Casino
|
|||||||
public int NumericValue { get; set; }
|
public int NumericValue { get; set; }
|
||||||
|
|
||||||
public bool IsRed => FarbeRaw.Equals("Hearts", StringComparison.OrdinalIgnoreCase) ||
|
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)
|
public Card(int id, string wert, string farbe, byte[] imgBytes)
|
||||||
{
|
{
|
||||||
@@ -73,16 +77,28 @@ namespace Casino
|
|||||||
private List<Card> handCards = new();
|
private List<Card> handCards = new();
|
||||||
private ImageSource cardBackImage = null!;
|
private ImageSource cardBackImage = null!;
|
||||||
|
|
||||||
private int currentPhase = 0; // 0: Red/Black, 1: Higher/Lower, 2: In Between/Outside, 3: Suit, 4: Won
|
private int currentPhase = 0;
|
||||||
private double currentBet = 0;
|
private decimal currentBet = 0;
|
||||||
private double currentProfit = 0;
|
private decimal currentProfit = 0;
|
||||||
|
|
||||||
|
private Database db = new Database();
|
||||||
|
private ObservableCollection<User> users;
|
||||||
|
|
||||||
public Busfahrer()
|
public Busfahrer()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
users = db.GetUser();
|
||||||
|
|
||||||
|
UpdateAccountDisplay();
|
||||||
StartNewGame();
|
StartNewGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateAccountDisplay()
|
||||||
|
{
|
||||||
|
users = db.GetUser();
|
||||||
|
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
private void BtnStart_Click(object sender, RoutedEventArgs e)
|
private void BtnStart_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
StartNewGame();
|
StartNewGame();
|
||||||
@@ -91,9 +107,17 @@ namespace Casino
|
|||||||
private void StartNewGame()
|
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();
|
UpdateWinDisplay();
|
||||||
|
|
||||||
Database db = new Database();
|
|
||||||
deck = db.GetAllCards();
|
deck = db.GetAllCards();
|
||||||
byte[] backBytes = db.GetCardBackImage();
|
byte[] backBytes = db.GetCardBackImage();
|
||||||
|
|
||||||
@@ -151,24 +175,34 @@ namespace Casino
|
|||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
RevealCurrentCard();
|
RevealCurrentCard();
|
||||||
MessageBox.Show("Wrong guess! You lost your bet. Game will restart.", "Bus Driver", MessageBoxButton.OK, MessageBoxImage.Information);
|
currentProfit = 0;
|
||||||
StartNewGame();
|
UpdateWinDisplay();
|
||||||
|
SetPhaseUI();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gewinn-Multiplikatoren
|
|
||||||
currentPhase++;
|
currentPhase++;
|
||||||
switch (currentPhase)
|
switch (currentPhase)
|
||||||
{
|
{
|
||||||
case 1: currentProfit = currentBet * 1.75; break; // Runde 1 bestanden
|
case 1: currentProfit = currentBet * 1.75m; break;
|
||||||
case 2: currentProfit = currentBet * 2.5; break; // Runde 2 bestanden
|
case 2: currentProfit = currentBet * 2.5m; break;
|
||||||
case 3: currentProfit = currentBet * 5.0; break; // Runde 3 bestanden
|
case 3: currentProfit = currentBet * 5.0m; break;
|
||||||
case 4: currentProfit = currentBet * 20.0; break; // Runde 4 bestanden
|
case 4: currentProfit = currentBet * 20.0m; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateWinDisplay();
|
UpdateWinDisplay();
|
||||||
UpdateHandUI();
|
UpdateHandUI();
|
||||||
SetPhaseUI();
|
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()
|
private void UpdateWinDisplay()
|
||||||
@@ -176,18 +210,25 @@ namespace Casino
|
|||||||
BtnCashOut.Content = $"Cash Out (${currentProfit:F2})";
|
BtnCashOut.Content = $"Cash Out (${currentProfit:F2})";
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- CASH OUT BUTTON EVENT ---
|
// CASH OUT BUTTON
|
||||||
private void BtnCashOut_Click(object sender, RoutedEventArgs e)
|
private void BtnCashOut_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (currentProfit > 0)
|
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 ---
|
// RUNDEN BUTTONS
|
||||||
|
|
||||||
// ROUND 1: Red / Black
|
|
||||||
private void BtnRed_Click(object sender, RoutedEventArgs e) => GuessColor(CardColor.Red);
|
private void BtnRed_Click(object sender, RoutedEventArgs e) => GuessColor(CardColor.Red);
|
||||||
private void BtnBlack_Click(object sender, RoutedEventArgs e) => GuessColor(CardColor.Black);
|
private void BtnBlack_Click(object sender, RoutedEventArgs e) => GuessColor(CardColor.Black);
|
||||||
|
|
||||||
@@ -199,7 +240,6 @@ namespace Casino
|
|||||||
ProcessGuess(ok);
|
ProcessGuess(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ROUND 2: Higher / Lower
|
|
||||||
private void BtnHigher_Click(object sender, RoutedEventArgs e) => GuessHigherLower(true);
|
private void BtnHigher_Click(object sender, RoutedEventArgs e) => GuessHigherLower(true);
|
||||||
private void BtnLower_Click(object sender, RoutedEventArgs e) => GuessHigherLower(false);
|
private void BtnLower_Click(object sender, RoutedEventArgs e) => GuessHigherLower(false);
|
||||||
|
|
||||||
@@ -212,7 +252,6 @@ namespace Casino
|
|||||||
ProcessGuess(ok);
|
ProcessGuess(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ROUND 3: In Between / Outside
|
|
||||||
private void BtnInside_Click(object sender, RoutedEventArgs e) => GuessInside(true);
|
private void BtnInside_Click(object sender, RoutedEventArgs e) => GuessInside(true);
|
||||||
private void BtnOutside_Click(object sender, RoutedEventArgs e) => GuessInside(false);
|
private void BtnOutside_Click(object sender, RoutedEventArgs e) => GuessInside(false);
|
||||||
|
|
||||||
@@ -227,7 +266,6 @@ namespace Casino
|
|||||||
ProcessGuess(ok);
|
ProcessGuess(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ROUND 4: Suit
|
|
||||||
private void BtnSuit_Click(object sender, RoutedEventArgs e)
|
private void BtnSuit_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is Button btn && btn.Tag != null)
|
if (sender is Button btn && btn.Tag != null)
|
||||||
@@ -236,45 +274,31 @@ namespace Casino
|
|||||||
Card card4 = handCards[3];
|
Card card4 = handCards[3];
|
||||||
|
|
||||||
bool ok = card4.FarbeRaw.Equals(chosenSuit, StringComparison.OrdinalIgnoreCase) ||
|
bool ok = card4.FarbeRaw.Equals(chosenSuit, StringComparison.OrdinalIgnoreCase) ||
|
||||||
(chosenSuit.Equals("Hearts", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Hearts", StringComparison.OrdinalIgnoreCase)) ||
|
(chosenSuit.Equals("Hearts", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Herz", StringComparison.OrdinalIgnoreCase)) ||
|
||||||
(chosenSuit.Equals("Diamond", StringComparison.OrdinalIgnoreCase) && (card4.FarbeRaw.Equals("Diamond", 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("Spades", StringComparison.OrdinalIgnoreCase)) ||
|
(chosenSuit.Equals("Spades", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Pik", StringComparison.OrdinalIgnoreCase)) ||
|
||||||
(chosenSuit.Equals("Clubs", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Clubs", StringComparison.OrdinalIgnoreCase));
|
(chosenSuit.Equals("Clubs", StringComparison.OrdinalIgnoreCase) && card4.FarbeRaw.Equals("Kreuz", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
ProcessGuess(ok);
|
ProcessGuess(ok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- BUTTON VISIBILITY CONTROL ---
|
|
||||||
|
|
||||||
private void SetPhaseUI()
|
private void SetPhaseUI()
|
||||||
{
|
{
|
||||||
PanelRedBlack.Visibility = Visibility.Collapsed;
|
PanelRedBlack.Visibility = Visibility.Collapsed;
|
||||||
PanelHigherLower.Visibility = Visibility.Collapsed;
|
PanelHigherLower.Visibility = Visibility.Collapsed;
|
||||||
PanelInsideOutside.Visibility = Visibility.Collapsed;
|
PanelInsideOutside.Visibility = Visibility.Collapsed;
|
||||||
if (PanelSuit != null) PanelSuit.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
|
// Zeige den Auszahlungs-Button ab Runde 1 (nach dem ersten Gewinn) an
|
||||||
BtnCashOut.Visibility = (currentPhase > 1 && currentPhase < 4) ? Visibility.Visible : Visibility.Collapsed;
|
BtnCashOut.Visibility = (currentPhase > 1 && currentPhase < 4) ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
|
||||||
switch (currentPhase)
|
switch (currentPhase)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0: PanelRedBlack.Visibility = Visibility.Visible; break;
|
||||||
PanelRedBlack.Visibility = Visibility.Visible;
|
case 1: PanelHigherLower.Visibility = Visibility.Visible; break;
|
||||||
break;
|
case 2: PanelInsideOutside.Visibility = Visibility.Visible; break;
|
||||||
case 1:
|
case 3: if (PanelSuit != null) PanelSuit.Visibility = Visibility.Visible; break;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,19 +322,18 @@ namespace Casino
|
|||||||
image.Freeze();
|
image.Freeze();
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
// =======================
|
||||||
// =============
|
// NUMBER FIELD VALIDATION
|
||||||
// NUMBER FIELD
|
// =======================
|
||||||
// =============
|
|
||||||
|
|
||||||
private static readonly Regex _regex = new Regex("^[0-9]");
|
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);
|
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)
|
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)))
|
if (e.DataObject.GetDataPresent(typeof(String)))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ namespace Casino
|
|||||||
public Login()
|
public Login()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
Console.WriteLine(HashPassword("Mast"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user