Slots gefixt

This commit is contained in:
NBTEMP\bib
2026-09-19 10:25:34 +02:00
parent c19fca22d2
commit 1d89b1440a
2 changed files with 156 additions and 50 deletions
+54 -3
View File
@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
@@ -13,19 +14,69 @@ namespace Casino
{
private readonly MediaPlayer player = new MediaPlayer();
private readonly MediaPlayer shortplayer = new MediaPlayer();
private readonly List<MediaPlayer> activePlayers = new();
public Audioplayer() { shortplayer.MediaEnded += Player_MediaEnded; }
public void PlaySound(byte[] audioBlob)
{
if (audioBlob == null || audioBlob.Length == 0)
return;
string tempFile = System.IO.Path.Combine(
System.IO.Path.GetTempPath(),
".mp3");
"casino_" + Guid.NewGuid().ToString("N") + ".mp3");
try
{
File.WriteAllBytes(tempFile, audioBlob);
shortplayer.Open(new Uri(tempFile));
shortplayer.Play();
MediaPlayer player = new MediaPlayer();
activePlayers.Add(player);
player.MediaEnded += (sender, e) =>
{
player.Close();
activePlayers.Remove(player);
try
{
if (File.Exists(tempFile))
File.Delete(tempFile);
}
catch
{
// Datei wird eventuell noch kurz von Windows verwendet.
}
};
player.MediaFailed += (sender, e) =>
{
player.Close();
activePlayers.Remove(player);
try
{
if (File.Exists(tempFile))
File.Delete(tempFile);
}
catch
{
}
};
player.Open(new Uri(tempFile));
player.Play();
}
catch (Exception ex)
{
MessageBox.Show(
"Fehler beim Abspielen des Sounds:\n" + ex.Message,
"Soundfehler",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
}
private void Player_MediaEnded(object? sender, EventArgs e)
+100 -45
View File
@@ -173,7 +173,10 @@ namespace Casino
{
decimal multiplikator = 0m;
// Waagerecht
// ==========================================
// WAAGERECHT
// ==========================================
for (int row = 0; row < 3; row++)
{
multiplikator += CheckLine(
@@ -185,7 +188,11 @@ namespace Casino
board[row, 5]);
}
// Senkrecht
// ==========================================
// SENKRECHT
// ==========================================
for (int col = 0; col < 6; col++)
{
multiplikator += CheckLine(
@@ -194,7 +201,11 @@ namespace Casino
board[2, col]);
}
// X Muster
// ==========================================
// X-MUSTER
// ==========================================
bool x1 =
board[0, 0] == board[1, 1] &&
board[1, 1] == board[2, 2];
@@ -203,14 +214,22 @@ namespace Casino
board[0, 5] == board[1, 4] &&
board[1, 4] == board[2, 3];
if (x1 && x2 &&
board[0, 0] == board[0, 5])
bool xMuster =
x1 &&
x2 &&
board[0, 0] == board[0, 5];
if (xMuster)
{
multiplikator += X_MUSTER;
highestWin++;
}
// Rand
// ==========================================
// RAND
// ==========================================
int randId = board[0, 0];
bool randGleich =
@@ -220,12 +239,14 @@ namespace Casino
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;
@@ -235,31 +256,39 @@ namespace Casino
highestWin++;
}
// X + Rand Bonus
if (
randGleich &&
x1 && x2 &&
board[0, 0] == board[0, 5]
)
// ==========================================
// X + RAND
// ==========================================
if (randGleich && xMuster)
{
multiplikator += X_UND_RAND;
highestWin++;
}
// Fullboard
// ==========================================
// FULLBOARD
// ==========================================
int first = board[0, 0];
bool fullBoard = true;
for (int r = 0; r < 3; r++)
for (int row = 0; row < 3; row++)
{
for (int c = 0; c < 6; c++)
for (int col = 0; col < 6; col++)
{
if (board[r, c] != first)
if (board[row, col] != first)
{
fullBoard = false;
break;
}
}
if (!fullBoard)
break;
}
if (fullBoard)
@@ -268,7 +297,20 @@ namespace Casino
highestWin = 12;
}
if (multiplikator != 0) PlayWinSound();
// ==========================================
// SOUND
// ==========================================
if (multiplikator > 0)
{
PlayWinSound();
}
// ==========================================
// AUSZAHLUNG
// ==========================================
return einsatz * multiplikator;
}
@@ -276,49 +318,62 @@ namespace Casino
// Lenard Gerdes
private decimal CheckLine(params int[] werte)
{
decimal gewinn = 0;
if (werte.Length < 3)
return 0m;
int laenge = werte.Length;
decimal gewinn = 0m;
for (int start = 0; start < laenge; start++)
int start = 0;
while (start < werte.Length)
{
int gleiche = 1;
for (int next = start + 1; next < laenge; next++)
while (start + gleiche < werte.Length &&
werte[start + gleiche] == werte[start])
{
if (werte[next] == werte[start])
gleiche++;
else
break;
}
if (gleiche >= 3)
{
gewinn += DREI;
if (5 > bestSoundId) bestSoundId = 5;
}
if (gleiche >= 4)
{
gewinn += VIER;
highestWin++;
if (6 > bestSoundId) bestSoundId = 6;
}
if (gleiche >= 5)
{
gewinn += FUENF;
highestWin++;
if (7 > bestSoundId) bestSoundId = 7;
}
// Nur den höchsten passenden Gewinn dieser Reihe geben
if (gleiche >= 6)
{
gewinn += SECHS;
if (8 > bestSoundId)
bestSoundId = 8;
highestWin++;
if (8 > bestSoundId) bestSoundId = 8;
}
else if (gleiche >= 5)
{
gewinn += FUENF;
if (7 > bestSoundId)
bestSoundId = 7;
highestWin++;
}
else if (gleiche >= 4)
{
gewinn += VIER;
if (6 > bestSoundId)
bestSoundId = 6;
highestWin++;
}
else if (gleiche >= 3)
{
gewinn += DREI;
if (5 > bestSoundId)
bestSoundId = 5;
}
start += gleiche;
}
return gewinn;
}