This commit is contained in:
2026-09-19 10:29:15 +02:00
2 changed files with 131 additions and 87 deletions
+54 -12
View File
@@ -14,7 +14,7 @@ namespace Casino
{ {
private readonly MediaPlayer player = new MediaPlayer(); private readonly MediaPlayer player = new MediaPlayer();
private readonly MediaPlayer shortplayer = new MediaPlayer(); private readonly MediaPlayer shortplayer = new MediaPlayer();
private readonly Dictionary<int, string> soundCache = new Dictionary<int, string>(); private readonly List<MediaPlayer> activePlayers = new();
public Audioplayer() { shortplayer.MediaEnded += Player_MediaEnded; } public Audioplayer() { shortplayer.MediaEnded += Player_MediaEnded; }
@@ -23,18 +23,60 @@ namespace Casino
if (audioBlob == null || audioBlob.Length == 0) if (audioBlob == null || audioBlob.Length == 0)
return; return;
if (!soundCache.TryGetValue(soundId, out string tempFile)) string tempFile = System.IO.Path.Combine(
{ System.IO.Path.GetTempPath(),
tempFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "casino_" + Guid.NewGuid().ToString("N") + ".mp3");
$"sound_{Guid.NewGuid():N}.mp3");
File.WriteAllBytes(tempFile, audioBlob);
soundCache[soundId] = tempFile;
}
shortplayer.Stop(); try
shortplayer.Close(); // gibt die alte Datei frei {
shortplayer.Open(new Uri(tempFile, UriKind.Absolute)); File.WriteAllBytes(tempFile, audioBlob);
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) private void Player_MediaEnded(object? sender, EventArgs e)
+82 -80
View File
@@ -173,13 +173,9 @@ namespace Casino
{ {
decimal multiplikator = 0m; decimal multiplikator = 0m;
// Wichtig: // ==========================================
// Bei jeder neuen Drehung wieder bei 0 anfangen.
highestWin = 0;
// -----------------------------------------------------
// WAAGERECHT // WAAGERECHT
// ----------------------------------------------------- // ==========================================
for (int row = 0; row < 3; row++) for (int row = 0; row < 3; row++)
{ {
@@ -193,9 +189,10 @@ namespace Casino
); );
} }
// -----------------------------------------------------
// ==========================================
// SENKRECHT // SENKRECHT
// ----------------------------------------------------- // ==========================================
for (int col = 0; col < 6; col++) for (int col = 0; col < 6; col++)
{ {
@@ -206,9 +203,10 @@ namespace Casino
); );
} }
// -----------------------------------------------------
// ==========================================
// X-MUSTER // X-MUSTER
// ----------------------------------------------------- // ==========================================
bool x1 = bool x1 =
board[0, 0] == board[1, 1] && board[0, 0] == board[1, 1] &&
@@ -218,9 +216,12 @@ namespace Casino
board[0, 5] == board[1, 4] && board[0, 5] == board[1, 4] &&
board[1, 4] == board[2, 3]; board[1, 4] == board[2, 3];
if (x1 && bool xMuster =
x1 &&
x2 && x2 &&
board[0, 0] == board[0, 5]) board[0, 0] == board[0, 5];
if (xMuster)
{ {
multiplikator += X_MUSTER; multiplikator += X_MUSTER;
@@ -228,9 +229,10 @@ namespace Casino
highestWin = Math.Max(highestWin, 7); highestWin = Math.Max(highestWin, 7);
} }
// -----------------------------------------------------
// ==========================================
// RAND // RAND
// ----------------------------------------------------- // ==========================================
int randId = board[0, 0]; int randId = board[0, 0];
@@ -260,14 +262,12 @@ namespace Casino
highestWin = Math.Max(highestWin, 8); highestWin = Math.Max(highestWin, 8);
} }
// -----------------------------------------------------
// X + RAND
// -----------------------------------------------------
if (randGleich && // ==========================================
x1 && // X + RAND
x2 && // ==========================================
board[0, 0] == board[0, 5])
if (randGleich && xMuster)
{ {
multiplikator += X_UND_RAND; multiplikator += X_UND_RAND;
@@ -275,18 +275,20 @@ namespace Casino
highestWin = Math.Max(highestWin, 9); highestWin = Math.Max(highestWin, 9);
} }
// -----------------------------------------------------
// ==========================================
// FULLBOARD // FULLBOARD
// ----------------------------------------------------- // ==========================================
int first = board[0, 0]; int first = board[0, 0];
bool fullBoard = true; 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; fullBoard = false;
break; break;
@@ -305,15 +307,21 @@ namespace Casino
highestWin = 12; highestWin = 12;
} }
// -----------------------------------------------------
// SOUND ABSPIELEN
// -----------------------------------------------------
if (multiplikator != 0) // ==========================================
// SOUND
// ==========================================
if (multiplikator > 0)
{ {
PlayWinSound(); PlayWinSound();
} }
// ==========================================
// AUSZAHLUNG
// ==========================================
return einsatz * multiplikator; return einsatz * multiplikator;
} }
@@ -324,66 +332,60 @@ namespace Casino
private decimal CheckLine(params int[] werte) private decimal CheckLine(params int[] werte)
{ {
if (werte.Length < 3)
return 0m;
decimal gewinn = 0m; decimal gewinn = 0m;
// Größte zusammenhängende Reihe int start = 0;
int maxGleiche = 1;
// Aktuelle Reihe while (start < werte.Length)
int aktuelleGleiche = 1; {
int gleiche = 1;
// Wir laufen von links nach rechts while (start + gleiche < werte.Length &&
for (int i = 1; i < werte.Length; i++) werte[start + gleiche] == werte[start])
{ {
if (werte[i] == werte[i - 1]) gleiche++;
{
aktuelleGleiche++;
}
else
{
aktuelleGleiche = 1;
} }
if (aktuelleGleiche > maxGleiche) // Nur den höchsten passenden Gewinn dieser Reihe geben
{ if (gleiche >= 6)
maxGleiche = aktuelleGleiche;
}
}
// -----------------------------------------------------
// GEWINN BESTIMMEN
// -----------------------------------------------------
if (maxGleiche >= 3)
{
gewinn += DREI;
// Sound für mindestens 3
highestWin = Math.Max(highestWin, 3);
}
if (maxGleiche >= 4)
{
gewinn += VIER;
// Sound für mindestens 4
highestWin = Math.Max(highestWin, 4);
}
if (maxGleiche >= 5)
{
gewinn += FUENF;
// Sound für mindestens 5
highestWin = Math.Max(highestWin, 5);
}
if (maxGleiche >= 6)
{ {
gewinn += SECHS; gewinn += SECHS;
// Sound für 6 if (8 > bestSoundId)
highestWin = Math.Max(highestWin, 6); bestSoundId = 8;
highestWin++;
}
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; return gewinn;