merge31
This commit is contained in:
+14
-5
@@ -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,18 +14,26 @@ namespace Casino
|
||||
{
|
||||
private readonly MediaPlayer player = new MediaPlayer();
|
||||
private readonly MediaPlayer shortplayer = new MediaPlayer();
|
||||
private readonly Dictionary<int, string> soundCache = new Dictionary<int, string>();
|
||||
|
||||
public Audioplayer() { shortplayer.MediaEnded += Player_MediaEnded; }
|
||||
|
||||
public void PlaySound(byte[] audioBlob)
|
||||
public void PlaySound(byte[] audioBlob, int soundId)
|
||||
{
|
||||
string tempFile = System.IO.Path.Combine(
|
||||
System.IO.Path.GetTempPath(),
|
||||
".mp3");
|
||||
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;
|
||||
}
|
||||
|
||||
shortplayer.Open(new Uri(tempFile));
|
||||
shortplayer.Stop();
|
||||
shortplayer.Close(); // gibt die alte Datei frei
|
||||
shortplayer.Open(new Uri(tempFile, UriKind.Absolute));
|
||||
shortplayer.Play();
|
||||
}
|
||||
|
||||
|
||||
+119
-43
@@ -63,9 +63,9 @@ namespace Casino
|
||||
AlleBilder = new List<Byte[]>
|
||||
{
|
||||
db.GetCardImage(2),db.GetCardImage(3),
|
||||
db.GetCardImage(4),db.GetCardImage(5),
|
||||
db.GetCardImage(4),/*db.GetCardImage(5),
|
||||
db.GetCardImage(6),db.GetCardImage(7),
|
||||
db.GetCardImage(8),db.GetCardImage(9), db.GetCardImage(10)
|
||||
db.GetCardImage(8),db.GetCardImage(9), db.GetCardImage(10)*/
|
||||
|
||||
};
|
||||
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||
@@ -173,7 +173,14 @@ namespace Casino
|
||||
{
|
||||
decimal multiplikator = 0m;
|
||||
|
||||
// Waagerecht
|
||||
// Wichtig:
|
||||
// Bei jeder neuen Drehung wieder bei 0 anfangen.
|
||||
highestWin = 0;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// WAAGERECHT
|
||||
// -----------------------------------------------------
|
||||
|
||||
for (int row = 0; row < 3; row++)
|
||||
{
|
||||
multiplikator += CheckLine(
|
||||
@@ -182,19 +189,27 @@ namespace Casino
|
||||
board[row, 2],
|
||||
board[row, 3],
|
||||
board[row, 4],
|
||||
board[row, 5]);
|
||||
board[row, 5]
|
||||
);
|
||||
}
|
||||
|
||||
// Senkrecht
|
||||
// -----------------------------------------------------
|
||||
// SENKRECHT
|
||||
// -----------------------------------------------------
|
||||
|
||||
for (int col = 0; col < 6; col++)
|
||||
{
|
||||
multiplikator += CheckLine(
|
||||
board[0, col],
|
||||
board[1, col],
|
||||
board[2, col]);
|
||||
board[2, col]
|
||||
);
|
||||
}
|
||||
|
||||
// X Muster
|
||||
// -----------------------------------------------------
|
||||
// X-MUSTER
|
||||
// -----------------------------------------------------
|
||||
|
||||
bool x1 =
|
||||
board[0, 0] == board[1, 1] &&
|
||||
board[1, 1] == board[2, 2];
|
||||
@@ -203,14 +218,20 @@ namespace Casino
|
||||
board[0, 5] == board[1, 4] &&
|
||||
board[1, 4] == board[2, 3];
|
||||
|
||||
if (x1 && x2 &&
|
||||
if (x1 &&
|
||||
x2 &&
|
||||
board[0, 0] == board[0, 5])
|
||||
{
|
||||
multiplikator += X_MUSTER;
|
||||
highestWin++;
|
||||
|
||||
// Sound-ID für X-Muster
|
||||
highestWin = Math.Max(highestWin, 7);
|
||||
}
|
||||
|
||||
// Rand
|
||||
// -----------------------------------------------------
|
||||
// RAND
|
||||
// -----------------------------------------------------
|
||||
|
||||
int randId = board[0, 0];
|
||||
|
||||
bool randGleich =
|
||||
@@ -220,33 +241,44 @@ 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;
|
||||
|
||||
if (randGleich)
|
||||
{
|
||||
multiplikator += RAND;
|
||||
highestWin++;
|
||||
|
||||
// Sound-ID für Rand
|
||||
highestWin = Math.Max(highestWin, 8);
|
||||
}
|
||||
|
||||
// X + Rand Bonus
|
||||
if (
|
||||
randGleich &&
|
||||
x1 && x2 &&
|
||||
board[0, 0] == board[0, 5]
|
||||
)
|
||||
// -----------------------------------------------------
|
||||
// X + RAND
|
||||
// -----------------------------------------------------
|
||||
|
||||
if (randGleich &&
|
||||
x1 &&
|
||||
x2 &&
|
||||
board[0, 0] == board[0, 5])
|
||||
{
|
||||
multiplikator += X_UND_RAND;
|
||||
highestWin++;
|
||||
|
||||
// Sound-ID für X + Rand
|
||||
highestWin = Math.Max(highestWin, 9);
|
||||
}
|
||||
|
||||
// Fullboard
|
||||
// -----------------------------------------------------
|
||||
// FULLBOARD
|
||||
// -----------------------------------------------------
|
||||
|
||||
int first = board[0, 0];
|
||||
bool fullBoard = true;
|
||||
|
||||
@@ -260,71 +292,115 @@ namespace Casino
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fullBoard)
|
||||
break;
|
||||
}
|
||||
|
||||
if (fullBoard)
|
||||
{
|
||||
multiplikator += FULLBOARD;
|
||||
|
||||
// Fullboard = Sound-ID 12
|
||||
highestWin = 12;
|
||||
}
|
||||
|
||||
if (multiplikator != 0) PlayWinSound();
|
||||
// -----------------------------------------------------
|
||||
// SOUND ABSPIELEN
|
||||
// -----------------------------------------------------
|
||||
|
||||
if (multiplikator != 0)
|
||||
{
|
||||
PlayWinSound();
|
||||
}
|
||||
|
||||
return einsatz * multiplikator;
|
||||
}
|
||||
|
||||
// Lenard Gerdes
|
||||
|
||||
// =========================================================
|
||||
// CHECK LINE
|
||||
// =========================================================
|
||||
|
||||
private decimal CheckLine(params int[] werte)
|
||||
{
|
||||
decimal gewinn = 0;
|
||||
decimal gewinn = 0m;
|
||||
|
||||
int laenge = werte.Length;
|
||||
// Größte zusammenhängende Reihe
|
||||
int maxGleiche = 1;
|
||||
|
||||
for (int start = 0; start < laenge; start++)
|
||||
// Aktuelle Reihe
|
||||
int aktuelleGleiche = 1;
|
||||
|
||||
// Wir laufen von links nach rechts
|
||||
for (int i = 1; i < werte.Length; i++)
|
||||
{
|
||||
int gleiche = 1;
|
||||
|
||||
for (int next = start + 1; next < laenge; next++)
|
||||
if (werte[i] == werte[i - 1])
|
||||
{
|
||||
if (werte[next] == werte[start])
|
||||
gleiche++;
|
||||
aktuelleGleiche++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
{
|
||||
aktuelleGleiche = 1;
|
||||
}
|
||||
|
||||
if (gleiche >= 3)
|
||||
if (aktuelleGleiche > maxGleiche)
|
||||
{
|
||||
maxGleiche = aktuelleGleiche;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// GEWINN BESTIMMEN
|
||||
// -----------------------------------------------------
|
||||
|
||||
if (maxGleiche >= 3)
|
||||
{
|
||||
gewinn += DREI;
|
||||
if (5 > bestSoundId) bestSoundId = 5;
|
||||
|
||||
// Sound für mindestens 3
|
||||
highestWin = Math.Max(highestWin, 3);
|
||||
}
|
||||
|
||||
if (gleiche >= 4)
|
||||
if (maxGleiche >= 4)
|
||||
{
|
||||
gewinn += VIER;
|
||||
highestWin++;
|
||||
if (6 > bestSoundId) bestSoundId = 6;
|
||||
|
||||
// Sound für mindestens 4
|
||||
highestWin = Math.Max(highestWin, 4);
|
||||
}
|
||||
|
||||
if (gleiche >= 5)
|
||||
if (maxGleiche >= 5)
|
||||
{
|
||||
gewinn += FUENF;
|
||||
highestWin++;
|
||||
if (7 > bestSoundId) bestSoundId = 7;
|
||||
|
||||
// Sound für mindestens 5
|
||||
highestWin = Math.Max(highestWin, 5);
|
||||
}
|
||||
|
||||
if (gleiche >= 6)
|
||||
if (maxGleiche >= 6)
|
||||
{
|
||||
gewinn += SECHS;
|
||||
highestWin++;
|
||||
if (8 > bestSoundId) bestSoundId = 8;
|
||||
}
|
||||
|
||||
// Sound für 6
|
||||
highestWin = Math.Max(highestWin, 6);
|
||||
}
|
||||
|
||||
return gewinn;
|
||||
}
|
||||
|
||||
|
||||
// =========================================================
|
||||
// WIN SOUND AUS DATENBANK
|
||||
// =========================================================
|
||||
|
||||
void PlayWinSound()
|
||||
{
|
||||
audio.PlaySound(db.GetSound(bestSoundId));
|
||||
bestSoundId = highestWin+1;
|
||||
if (bestSoundId > 0)
|
||||
audio.PlaySound(db.GetSound(bestSoundId), bestSoundId);
|
||||
|
||||
bestSoundId = 0; // fehlte komplett
|
||||
highestWin = 5;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user