merge 32
This commit is contained in:
+54
-12
@@ -14,7 +14,7 @@ namespace Casino
|
||||
{
|
||||
private readonly MediaPlayer player = 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; }
|
||||
|
||||
@@ -23,18 +23,60 @@ namespace Casino
|
||||
if (audioBlob == null || audioBlob.Length == 0)
|
||||
return;
|
||||
|
||||
if (!soundCache.TryGetValue(soundId, out string tempFile))
|
||||
{
|
||||
tempFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(),
|
||||
$"sound_{Guid.NewGuid():N}.mp3");
|
||||
File.WriteAllBytes(tempFile, audioBlob);
|
||||
soundCache[soundId] = tempFile;
|
||||
}
|
||||
string tempFile = System.IO.Path.Combine(
|
||||
System.IO.Path.GetTempPath(),
|
||||
"casino_" + Guid.NewGuid().ToString("N") + ".mp3");
|
||||
|
||||
shortplayer.Stop();
|
||||
shortplayer.Close(); // gibt die alte Datei frei
|
||||
shortplayer.Open(new Uri(tempFile, UriKind.Absolute));
|
||||
shortplayer.Play();
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes(tempFile, audioBlob);
|
||||
|
||||
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)
|
||||
|
||||
+82
-80
@@ -173,13 +173,9 @@ namespace Casino
|
||||
{
|
||||
decimal multiplikator = 0m;
|
||||
|
||||
// Wichtig:
|
||||
// Bei jeder neuen Drehung wieder bei 0 anfangen.
|
||||
highestWin = 0;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// ==========================================
|
||||
// WAAGERECHT
|
||||
// -----------------------------------------------------
|
||||
// ==========================================
|
||||
|
||||
for (int row = 0; row < 3; row++)
|
||||
{
|
||||
@@ -193,9 +189,10 @@ namespace Casino
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// ==========================================
|
||||
// SENKRECHT
|
||||
// -----------------------------------------------------
|
||||
// ==========================================
|
||||
|
||||
for (int col = 0; col < 6; col++)
|
||||
{
|
||||
@@ -206,9 +203,10 @@ namespace Casino
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// ==========================================
|
||||
// X-MUSTER
|
||||
// -----------------------------------------------------
|
||||
// ==========================================
|
||||
|
||||
bool x1 =
|
||||
board[0, 0] == board[1, 1] &&
|
||||
@@ -218,9 +216,12 @@ namespace Casino
|
||||
board[0, 5] == board[1, 4] &&
|
||||
board[1, 4] == board[2, 3];
|
||||
|
||||
if (x1 &&
|
||||
bool xMuster =
|
||||
x1 &&
|
||||
x2 &&
|
||||
board[0, 0] == board[0, 5])
|
||||
board[0, 0] == board[0, 5];
|
||||
|
||||
if (xMuster)
|
||||
{
|
||||
multiplikator += X_MUSTER;
|
||||
|
||||
@@ -228,9 +229,10 @@ namespace Casino
|
||||
highestWin = Math.Max(highestWin, 7);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// ==========================================
|
||||
// RAND
|
||||
// -----------------------------------------------------
|
||||
// ==========================================
|
||||
|
||||
int randId = board[0, 0];
|
||||
|
||||
@@ -260,14 +262,12 @@ namespace Casino
|
||||
highestWin = Math.Max(highestWin, 8);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// X + RAND
|
||||
// -----------------------------------------------------
|
||||
|
||||
if (randGleich &&
|
||||
x1 &&
|
||||
x2 &&
|
||||
board[0, 0] == board[0, 5])
|
||||
// ==========================================
|
||||
// X + RAND
|
||||
// ==========================================
|
||||
|
||||
if (randGleich && xMuster)
|
||||
{
|
||||
multiplikator += X_UND_RAND;
|
||||
|
||||
@@ -275,18 +275,20 @@ namespace Casino
|
||||
highestWin = Math.Max(highestWin, 9);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// ==========================================
|
||||
// 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;
|
||||
@@ -305,15 +307,21 @@ namespace Casino
|
||||
highestWin = 12;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// SOUND ABSPIELEN
|
||||
// -----------------------------------------------------
|
||||
|
||||
if (multiplikator != 0)
|
||||
// ==========================================
|
||||
// SOUND
|
||||
// ==========================================
|
||||
|
||||
if (multiplikator > 0)
|
||||
{
|
||||
PlayWinSound();
|
||||
}
|
||||
|
||||
|
||||
// ==========================================
|
||||
// AUSZAHLUNG
|
||||
// ==========================================
|
||||
|
||||
return einsatz * multiplikator;
|
||||
}
|
||||
|
||||
@@ -324,66 +332,60 @@ namespace Casino
|
||||
|
||||
private decimal CheckLine(params int[] werte)
|
||||
{
|
||||
if (werte.Length < 3)
|
||||
return 0m;
|
||||
|
||||
decimal gewinn = 0m;
|
||||
|
||||
// Größte zusammenhängende Reihe
|
||||
int maxGleiche = 1;
|
||||
int start = 0;
|
||||
|
||||
// Aktuelle Reihe
|
||||
int aktuelleGleiche = 1;
|
||||
while (start < werte.Length)
|
||||
{
|
||||
int gleiche = 1;
|
||||
|
||||
// Wir laufen von links nach rechts
|
||||
for (int i = 1; i < werte.Length; i++)
|
||||
while (start + gleiche < werte.Length &&
|
||||
werte[start + gleiche] == werte[start])
|
||||
{
|
||||
if (werte[i] == werte[i - 1])
|
||||
{
|
||||
aktuelleGleiche++;
|
||||
}
|
||||
else
|
||||
{
|
||||
aktuelleGleiche = 1;
|
||||
gleiche++;
|
||||
}
|
||||
|
||||
if (aktuelleGleiche > maxGleiche)
|
||||
{
|
||||
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)
|
||||
// Nur den höchsten passenden Gewinn dieser Reihe geben
|
||||
if (gleiche >= 6)
|
||||
{
|
||||
gewinn += SECHS;
|
||||
|
||||
// Sound für 6
|
||||
highestWin = Math.Max(highestWin, 6);
|
||||
if (8 > bestSoundId)
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user