Merge branch 'main' of https://git.bib.de/PBG2H25AGE/GAMBLING-WIR-MACHEN-ALLE-ARM
This commit is contained in:
+20
-16
@@ -13,6 +13,8 @@ namespace Casino
|
|||||||
{
|
{
|
||||||
private readonly MediaPlayer player = new MediaPlayer();
|
private readonly MediaPlayer player = new MediaPlayer();
|
||||||
|
|
||||||
|
public Audioplayer() { player.MediaEnded += Player_MediaEnded; }
|
||||||
|
|
||||||
public void PlaySound(byte[] audioBlob)
|
public void PlaySound(byte[] audioBlob)
|
||||||
{
|
{
|
||||||
string tempFile = System.IO.Path.Combine(
|
string tempFile = System.IO.Path.Combine(
|
||||||
@@ -27,29 +29,31 @@ namespace Casino
|
|||||||
player.Play();
|
player.Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isPlaying = false;
|
private void Player_MediaEnded(object? sender, EventArgs e)
|
||||||
private readonly MediaPlayer musicPlayer = new();
|
|
||||||
|
|
||||||
public void PlayMusic(byte[] audioBlob)
|
|
||||||
{
|
{
|
||||||
if (isPlaying)
|
player.Position = TimeSpan.Zero;
|
||||||
return;
|
player.Play();
|
||||||
|
}
|
||||||
isPlaying = true;
|
|
||||||
|
|
||||||
|
public void PlayLoopingSound(byte[] audioBlob)
|
||||||
|
{
|
||||||
string tempFile = System.IO.Path.Combine(
|
string tempFile = System.IO.Path.Combine(
|
||||||
System.IO.Path.GetTempPath(),
|
System.IO.Path.GetTempPath(),
|
||||||
Guid.NewGuid() + ".mp3");
|
"background.mp3");
|
||||||
|
|
||||||
System.IO.File.WriteAllBytes(tempFile, audioBlob);
|
File.WriteAllBytes(tempFile, audioBlob);
|
||||||
|
|
||||||
musicPlayer.MediaEnded += (s, e) =>
|
player.Open(new Uri(tempFile));
|
||||||
{
|
|
||||||
isPlaying = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
musicPlayer.Open(new Uri(tempFile));
|
player.MediaEnded -= Player_MediaEnded;
|
||||||
musicPlayer.Play();
|
player.MediaEnded += Player_MediaEnded;
|
||||||
|
|
||||||
|
player.Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
player.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -157,6 +157,22 @@ 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Button Content="Slots" HorizontalAlignment="Left" Height="39" Margin="65,114,0,0" VerticalAlignment="Top" Width="93" Click="Slots_Click"/>
|
<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="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"/>
|
<Button Content="Busfahrer" HorizontalAlignment="Left" Margin="221,193,0,0" VerticalAlignment="Top" Height="40" Width="79" Click="Busfahrer_Click"/>
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,6 @@ 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)
|
private void Blackjack_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+3
-1
@@ -62,7 +62,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>
|
||||||
|
|||||||
+228
-6
@@ -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;
|
||||||
@@ -27,6 +28,20 @@ namespace Casino
|
|||||||
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 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;
|
||||||
|
|
||||||
|
|
||||||
public Slots()
|
public Slots()
|
||||||
{
|
{
|
||||||
@@ -48,7 +63,7 @@ namespace Casino
|
|||||||
|
|
||||||
};
|
};
|
||||||
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||||
|
audio.PlayLoopingSound(db.GetSound(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,29 +87,236 @@ namespace Casino
|
|||||||
}
|
}
|
||||||
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(70);
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
await Task.Delay(150);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Spin(object sender, RoutedEventArgs e)
|
private async void Spin(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
int einsatz = Convert.ToInt32(einsatzFeld.Text);
|
||||||
|
users[MainWindow.currentUser].Geld-=einsatz;
|
||||||
|
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||||
await Spin();
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Hauptmenue(object sender, RoutedEventArgs e)
|
private void Hauptmenue(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
audio.Stop();
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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];
|
||||||
|
|
||||||
|
if (x1 && x2 &&
|
||||||
|
board[0, 0] == board[0, 5])
|
||||||
|
{
|
||||||
|
multiplikator += X_MUSTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// X + Rand Bonus
|
||||||
|
if (
|
||||||
|
randGleich &&
|
||||||
|
x1 && x2 &&
|
||||||
|
board[0, 0] == board[0, 5]
|
||||||
|
)
|
||||||
|
{
|
||||||
|
multiplikator += X_UND_RAND;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fullboard
|
||||||
|
int first = board[0, 0];
|
||||||
|
bool fullBoard = true;
|
||||||
|
|
||||||
|
for (int r = 0; r < 3; r++)
|
||||||
|
{
|
||||||
|
for (int c = 0; c < 6; c++)
|
||||||
|
{
|
||||||
|
if (board[r, c] != first)
|
||||||
|
{
|
||||||
|
fullBoard = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fullBoard)
|
||||||
|
{
|
||||||
|
multiplikator += FULLBOARD;
|
||||||
|
}
|
||||||
|
|
||||||
|
return einsatz * multiplikator;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private decimal CheckLine(params int[] werte)
|
||||||
|
{
|
||||||
|
decimal gewinn = 0;
|
||||||
|
|
||||||
|
int laenge = werte.Length;
|
||||||
|
|
||||||
|
for (int start = 0; start < laenge; start++)
|
||||||
|
{
|
||||||
|
int gleiche = 1;
|
||||||
|
|
||||||
|
for (int next = start + 1; next < laenge; next++)
|
||||||
|
{
|
||||||
|
if (werte[next] == werte[start])
|
||||||
|
gleiche++;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gleiche >= 3)
|
||||||
|
gewinn += DREI;
|
||||||
|
|
||||||
|
if (gleiche >= 4)
|
||||||
|
gewinn += VIER;
|
||||||
|
|
||||||
|
if (gleiche >= 5)
|
||||||
|
gewinn += FUENF;
|
||||||
|
|
||||||
|
if (gleiche >= 6)
|
||||||
|
gewinn += SECHS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return gewinn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//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)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayWinSound()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ namespace Casino
|
|||||||
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 User(string n, int a, string p)
|
||||||
{
|
{
|
||||||
ID = ID_Generation();
|
ID = ID_Generation();
|
||||||
|
|||||||
Reference in New Issue
Block a user