Bilder für Slots
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Casino
|
||||
{
|
||||
class Audioplayer
|
||||
{
|
||||
private readonly MediaPlayer player = new MediaPlayer();
|
||||
|
||||
public void Play(byte[] audioBlob)
|
||||
{
|
||||
string tempFile = System.IO.Path.Combine(
|
||||
System.IO.Path.GetTempPath(),
|
||||
Guid.NewGuid() + ".mp3");
|
||||
|
||||
|
||||
|
||||
File.WriteAllBytes(tempFile, audioBlob);
|
||||
|
||||
player.Open(new Uri(tempFile));
|
||||
player.Play();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -80,5 +80,29 @@ namespace Casino
|
||||
|
||||
return imageBytes;
|
||||
}
|
||||
|
||||
public byte[] GetSound(int id)
|
||||
{
|
||||
byte[] soundBytes = null;
|
||||
|
||||
using (MySqlConnection conn = new MySqlConnection(myConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = new MySqlCommand("SELECT sound FROM Sounds WHERE id = @id",conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
|
||||
using (MySqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
soundBytes = (byte[])reader["sound"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return soundBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
<Grid>
|
||||
<Button Content="Slots" HorizontalAlignment="Left" Height="39" Margin="65,114,0,0" VerticalAlignment="Top" Width="93" Click="Slots_Click"/>
|
||||
<Button Content="sound" HorizontalAlignment="Left" Height="39" Margin="65,193,0,0" VerticalAlignment="Top" Width="93" Click="Sound_Click"/>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -27,8 +27,17 @@ namespace Casino
|
||||
}
|
||||
private void Slots_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
Slots slotsWindow = new Slots();
|
||||
slotsWindow.Show();
|
||||
}
|
||||
|
||||
private void Sound_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Database data = new Database();
|
||||
byte[] blobData = data.GetSound(1);
|
||||
var audioService = new Audioplayer();
|
||||
audioService.Play(blobData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,9 @@ namespace Casino
|
||||
public class Slot_System
|
||||
{
|
||||
int[,] slots = new int[3, 6];
|
||||
bool fertig = false;
|
||||
|
||||
public bool getFertig () { return fertig; }
|
||||
|
||||
public async Task roll()
|
||||
{
|
||||
@@ -26,6 +28,7 @@ namespace Casino
|
||||
counter++;
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
fertig = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+23
-16
@@ -20,6 +20,29 @@ namespace Casino
|
||||
/// </summary>
|
||||
public partial class Slots : Window
|
||||
{
|
||||
|
||||
|
||||
|
||||
public Slots()
|
||||
{
|
||||
InitializeComponent();
|
||||
Slot_System sys = new Slot_System();
|
||||
sys.roll();
|
||||
while (sys.getFertig())
|
||||
{
|
||||
|
||||
LoadCard(8);
|
||||
}
|
||||
|
||||
}
|
||||
private void LoadCard(int Bild)
|
||||
{
|
||||
Database db = new Database();
|
||||
byte[] img = db.GetCardImage(Bild);//2-10
|
||||
|
||||
kartenBild.Source = ByteArrayToImage(img);
|
||||
}
|
||||
|
||||
private BitmapImage ByteArrayToImage(byte[] bytes)
|
||||
{
|
||||
BitmapImage image = new BitmapImage();
|
||||
@@ -32,21 +55,5 @@ namespace Casino
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
public Slots()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
LoadCard();
|
||||
|
||||
}
|
||||
private void LoadCard()
|
||||
{
|
||||
Database db = new Database();
|
||||
byte[] img = db.GetCardImage(3);//2-10
|
||||
|
||||
kartenBild.Source = ByteArrayToImage(img);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user