Slots gefixt
This commit is contained in:
+55
-4
@@ -4,6 +4,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
@@ -13,19 +14,69 @@ 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 List<MediaPlayer> activePlayers = new();
|
||||||
|
|
||||||
public Audioplayer() { shortplayer.MediaEnded += Player_MediaEnded; }
|
public Audioplayer() { shortplayer.MediaEnded += Player_MediaEnded; }
|
||||||
|
|
||||||
public void PlaySound(byte[] audioBlob)
|
public void PlaySound(byte[] audioBlob)
|
||||||
{
|
{
|
||||||
|
if (audioBlob == null || audioBlob.Length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
string tempFile = System.IO.Path.Combine(
|
string tempFile = System.IO.Path.Combine(
|
||||||
System.IO.Path.GetTempPath(),
|
System.IO.Path.GetTempPath(),
|
||||||
".mp3");
|
"casino_" + Guid.NewGuid().ToString("N") + ".mp3");
|
||||||
|
|
||||||
File.WriteAllBytes(tempFile, audioBlob);
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllBytes(tempFile, audioBlob);
|
||||||
|
|
||||||
shortplayer.Open(new Uri(tempFile));
|
MediaPlayer player = new MediaPlayer();
|
||||||
shortplayer.Play();
|
|
||||||
|
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)
|
||||||
|
|||||||
+101
-46
@@ -173,7 +173,10 @@ namespace Casino
|
|||||||
{
|
{
|
||||||
decimal multiplikator = 0m;
|
decimal multiplikator = 0m;
|
||||||
|
|
||||||
// Waagerecht
|
// ==========================================
|
||||||
|
// WAAGERECHT
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
for (int row = 0; row < 3; row++)
|
for (int row = 0; row < 3; row++)
|
||||||
{
|
{
|
||||||
multiplikator += CheckLine(
|
multiplikator += CheckLine(
|
||||||
@@ -185,7 +188,11 @@ namespace Casino
|
|||||||
board[row, 5]);
|
board[row, 5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Senkrecht
|
|
||||||
|
// ==========================================
|
||||||
|
// SENKRECHT
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
for (int col = 0; col < 6; col++)
|
for (int col = 0; col < 6; col++)
|
||||||
{
|
{
|
||||||
multiplikator += CheckLine(
|
multiplikator += CheckLine(
|
||||||
@@ -194,7 +201,11 @@ namespace Casino
|
|||||||
board[2, col]);
|
board[2, col]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// X Muster
|
|
||||||
|
// ==========================================
|
||||||
|
// X-MUSTER
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
bool x1 =
|
bool x1 =
|
||||||
board[0, 0] == board[1, 1] &&
|
board[0, 0] == board[1, 1] &&
|
||||||
board[1, 1] == board[2, 2];
|
board[1, 1] == board[2, 2];
|
||||||
@@ -203,14 +214,22 @@ 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 && x2 &&
|
bool xMuster =
|
||||||
board[0, 0] == board[0, 5])
|
x1 &&
|
||||||
|
x2 &&
|
||||||
|
board[0, 0] == board[0, 5];
|
||||||
|
|
||||||
|
if (xMuster)
|
||||||
{
|
{
|
||||||
multiplikator += X_MUSTER;
|
multiplikator += X_MUSTER;
|
||||||
highestWin++;
|
highestWin++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rand
|
|
||||||
|
// ==========================================
|
||||||
|
// RAND
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
int randId = board[0, 0];
|
int randId = board[0, 0];
|
||||||
|
|
||||||
bool randGleich =
|
bool randGleich =
|
||||||
@@ -220,12 +239,14 @@ namespace Casino
|
|||||||
board[0, 3] == randId &&
|
board[0, 3] == randId &&
|
||||||
board[0, 4] == randId &&
|
board[0, 4] == randId &&
|
||||||
board[0, 5] == randId &&
|
board[0, 5] == randId &&
|
||||||
|
|
||||||
board[2, 0] == randId &&
|
board[2, 0] == randId &&
|
||||||
board[2, 1] == randId &&
|
board[2, 1] == randId &&
|
||||||
board[2, 2] == randId &&
|
board[2, 2] == randId &&
|
||||||
board[2, 3] == randId &&
|
board[2, 3] == randId &&
|
||||||
board[2, 4] == randId &&
|
board[2, 4] == randId &&
|
||||||
board[2, 5] == randId &&
|
board[2, 5] == randId &&
|
||||||
|
|
||||||
board[1, 0] == randId &&
|
board[1, 0] == randId &&
|
||||||
board[1, 5] == randId;
|
board[1, 5] == randId;
|
||||||
|
|
||||||
@@ -235,31 +256,39 @@ namespace Casino
|
|||||||
highestWin++;
|
highestWin++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// X + Rand Bonus
|
|
||||||
if (
|
// ==========================================
|
||||||
randGleich &&
|
// X + RAND
|
||||||
x1 && x2 &&
|
// ==========================================
|
||||||
board[0, 0] == board[0, 5]
|
|
||||||
)
|
if (randGleich && xMuster)
|
||||||
{
|
{
|
||||||
multiplikator += X_UND_RAND;
|
multiplikator += X_UND_RAND;
|
||||||
highestWin++;
|
highestWin++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fullBoard)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullBoard)
|
if (fullBoard)
|
||||||
@@ -268,7 +297,20 @@ namespace Casino
|
|||||||
highestWin = 12;
|
highestWin = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (multiplikator != 0) PlayWinSound();
|
|
||||||
|
// ==========================================
|
||||||
|
// SOUND
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
if (multiplikator > 0)
|
||||||
|
{
|
||||||
|
PlayWinSound();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// AUSZAHLUNG
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
return einsatz * multiplikator;
|
return einsatz * multiplikator;
|
||||||
}
|
}
|
||||||
@@ -276,49 +318,62 @@ namespace Casino
|
|||||||
// Lenard Gerdes
|
// Lenard Gerdes
|
||||||
private decimal CheckLine(params int[] werte)
|
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;
|
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++;
|
||||||
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)
|
if (gleiche >= 6)
|
||||||
{
|
{
|
||||||
gewinn += SECHS;
|
gewinn += SECHS;
|
||||||
|
|
||||||
|
if (8 > bestSoundId)
|
||||||
|
bestSoundId = 8;
|
||||||
|
|
||||||
highestWin++;
|
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;
|
return gewinn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user