merge 32
This commit is contained in:
+54
-12
@@ -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)
|
||||||
|
|||||||
+77
-75
@@ -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;
|
|
||||||
|
|
||||||
// Wir laufen von links nach rechts
|
|
||||||
for (int i = 1; i < werte.Length; i++)
|
|
||||||
{
|
{
|
||||||
if (werte[i] == werte[i - 1])
|
int gleiche = 1;
|
||||||
|
|
||||||
|
while (start + gleiche < werte.Length &&
|
||||||
|
werte[start + gleiche] == werte[start])
|
||||||
{
|
{
|
||||||
aktuelleGleiche++;
|
gleiche++;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
aktuelleGleiche = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aktuelleGleiche > maxGleiche)
|
// Nur den höchsten passenden Gewinn dieser Reihe geben
|
||||||
|
if (gleiche >= 6)
|
||||||
{
|
{
|
||||||
maxGleiche = aktuelleGleiche;
|
gewinn += SECHS;
|
||||||
|
|
||||||
|
if (8 > bestSoundId)
|
||||||
|
bestSoundId = 8;
|
||||||
|
|
||||||
|
highestWin++;
|
||||||
}
|
}
|
||||||
}
|
else if (gleiche >= 5)
|
||||||
|
{
|
||||||
|
gewinn += FUENF;
|
||||||
|
|
||||||
// -----------------------------------------------------
|
if (7 > bestSoundId)
|
||||||
// GEWINN BESTIMMEN
|
bestSoundId = 7;
|
||||||
// -----------------------------------------------------
|
|
||||||
|
|
||||||
if (maxGleiche >= 3)
|
highestWin++;
|
||||||
{
|
}
|
||||||
gewinn += DREI;
|
else if (gleiche >= 4)
|
||||||
|
{
|
||||||
|
gewinn += VIER;
|
||||||
|
|
||||||
// Sound für mindestens 3
|
if (6 > bestSoundId)
|
||||||
highestWin = Math.Max(highestWin, 3);
|
bestSoundId = 6;
|
||||||
}
|
|
||||||
|
|
||||||
if (maxGleiche >= 4)
|
highestWin++;
|
||||||
{
|
}
|
||||||
gewinn += VIER;
|
else if (gleiche >= 3)
|
||||||
|
{
|
||||||
|
gewinn += DREI;
|
||||||
|
|
||||||
// Sound für mindestens 4
|
if (5 > bestSoundId)
|
||||||
highestWin = Math.Max(highestWin, 4);
|
bestSoundId = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxGleiche >= 5)
|
start += gleiche;
|
||||||
{
|
|
||||||
gewinn += FUENF;
|
|
||||||
|
|
||||||
// Sound für mindestens 5
|
|
||||||
highestWin = Math.Max(highestWin, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maxGleiche >= 6)
|
|
||||||
{
|
|
||||||
gewinn += SECHS;
|
|
||||||
|
|
||||||
// Sound für 6
|
|
||||||
highestWin = Math.Max(highestWin, 6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return gewinn;
|
return gewinn;
|
||||||
|
|||||||
Reference in New Issue
Block a user