using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace Casino { /// /// Interaktionslogik für Slots.xaml /// public partial class Slots : Window { private List _bilder; private Random _random = new Random(); Database db = new Database(); private List AlleBilder; ObservableCollection users = new ObservableCollection(); private int[,] currentSlot = new int[3, 6]; public Slots() { InitializeComponent(); users = db.GetUser(); _bilder = new List { Bild_11, Bild_12, Bild_13, Bild_14, Bild_15, Bild_16, Bild_21, Bild_22, Bild_23, Bild_24, Bild_25, Bild_26, Bild_31, Bild_32, Bild_33, Bild_34, Bild_35, Bild_36 }; AlleBilder = new List { db.GetCardImage(2),db.GetCardImage(3),db.GetCardImage(4), db.GetCardImage(5),db.GetCardImage(6),db.GetCardImage(7), db.GetCardImage(8),db.GetCardImage(9),db.GetCardImage(10), }; Konto.Text = users[MainWindow.currentUser].Geld.ToString(); } private void LoadCard(Image imageControl, int bildId) { byte[] img = AlleBilder.ElementAt(bildId); imageControl.Source = ByteArrayToImage(img); } private BitmapImage ByteArrayToImage(byte[] bytes) { BitmapImage image = new BitmapImage(); using (MemoryStream ms = new MemoryStream(bytes)) { image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; image.StreamSource = ms; image.EndInit(); } return image; } private async Task Spin() { for (int i = 0; i < 15; i++) { for (int j = 5; j>=0;j--) { int randomBild = _random.Next(0, AlleBilder.Count); if (i == 0) { currentSlot[0,j] = randomBild; LoadCard(_bilder[j], randomBild); } else if (i == 1) { currentSlot[1, j] = currentSlot[0, j]; LoadCard(_bilder[j + 6], currentSlot[0,j]); currentSlot[0, j] = randomBild; LoadCard(_bilder[j], randomBild); } else { currentSlot[2, j] = currentSlot[1, j]; LoadCard(_bilder[j + 12], currentSlot[1, j]); currentSlot[1, j] = currentSlot[0, j]; LoadCard(_bilder[j + 6], currentSlot[0, j]); currentSlot[0, j] = randomBild; LoadCard(_bilder[j], randomBild); } await Task.Delay(70); } await Task.Delay(70); } } private async void Spin(object sender, RoutedEventArgs e) { users[MainWindow.currentUser].Geld++; Konto.Text = users[MainWindow.currentUser].Geld.ToString(); await Spin(); db.UpdateGeld( users[MainWindow.currentUser].ID, users[MainWindow.currentUser].Geld); } private void Hauptmenue(object sender, RoutedEventArgs e) { Close(); } } }