public Tavolo() { PathImages = new List <BitmapImage>(); for (int i = 0; i < 22; i++) { Uri u = new Uri("Giocatori/user" + i + ".png", UriKind.Relative); BitmapImage im = new BitmapImage(u); PathImages.Add(im); } Giocatori1 = new Giocatore[11]; for (int i = 0; i < Giocatori1.Length; i++) { Giocatori1[i] = null; } }
private void AggiungiOrRimuovi(object sender, RoutedEventArgs e) { Button b = sender as Button; string[] el = b.Name.Split('_'); int pos = Convert.ToInt32(el[1]); if (b.Background == Brushes.Red) { MessageBoxResult result = MessageBox.Show("Sicuro di voler rimuovere il giocatore?", "Conferma", MessageBoxButton.YesNo); if (result.Equals(MessageBoxResult.Yes)) { t.Giocatori1[pos - 1] = null; b.Background = Brushes.Yellow; b.Foreground = Brushes.Black; b.Content = "✚"; ((TextBox)this.FindName("tbx_" + pos)).Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF858585")); ((TextBox)this.FindName("tbx_" + pos)).Text = "Nick..."; n--; } } else { try { if (((TextBox)this.FindName("tbx_" + pos)).Text == "" || ((TextBox)this.FindName("tbx_" + pos)).Text == "Nick...") { throw new Exception("Errore nell'inserimento del nickname"); } else { Giocatore g = new Giocatore(((TextBox)this.FindName("tbx_" + pos)).Text); g.Avatar = ((ListBox)FindName("lbxAvatars_" + Convert.ToString(pos + 1))).SelectedItem as BitmapImage; t.AggiungiGiocatore(g, pos); ((ListBox)FindName("lbxAvatars_" + pos)).Visibility = Visibility.Hidden; MessageBox.Show("Giocatore inserito con successo"); b.Background = Brushes.Red; b.Content = "X"; b.Foreground = Brushes.White; //buttons[pos - 1] = b; n++; } }catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnEstrai_Click(object sender, RoutedEventArgs e) { if (!tavolo.AssegnaCartaAGiocatore(tavolo.Giocatori1[playerAttuale])) { if (cartaAttuale == 0) { Uri u = new Uri(tavolo.Giocatori1[playerAttuale]._carte[0].PercorsoImmagineCarta, UriKind.Relative); BitmapImage b = new BitmapImage(u); ((Image)FindName("G" + Convert.ToString(playerAttuale + 1) + "_CS")).Source = b; if (playerAttuale == 10) { cartaAttuale++; } CercaProssimoGiocatore(); } if (cartaAttuale == 1 && !puntataCambiata) { int cont = 1; puntataCambiata = true; int j = playerAttuale; Giocatore last = tavolo.Giocatori1[playerAttuale]; for (int i = 0; i < nPlayers; i++) { Puntata nuova = new Puntata(tavolo, playerAttuale); nuova.ShowDialog(); ((TextBlock)FindName("G" + Convert.ToString(playerAttuale + 1) + "_Denaro")).Text = Convert.ToString(tavolo.Giocatori1[playerAttuale].Puntata); CercaProssimoGiocatore(); } while (cont != nPlayers) { CercaProssimoGiocatore(); if (tavolo.Giocatori1[playerAttuale].Puntata != last.Puntata) { Puntata nuova = new Puntata(tavolo, playerAttuale); nuova.ShowDialog(); ((TextBlock)FindName("G" + Convert.ToString(playerAttuale + 1) + "_Denaro")).Text = Convert.ToString(tavolo.Giocatori1[playerAttuale].Puntata); cont = 1; } else { cont++; } } playerAttuale = j; } else if (puntataCambiata) { if (tavolo.Giocatori1[playerAttuale].SforaLimite()) { cartaAttuale = 1; MessageBox.Show("Hai sforato il limite"); if (playerAttuale == 10) { Classifica nuova = new Classifica(tavolo); nuova.ShowDialog(); } CercaProssimoGiocatore(); } else { Uri u = new Uri(tavolo.Giocatori1[playerAttuale]._carte[cartaAttuale].PercorsoImmagineCarta, UriKind.Relative); BitmapImage b = new BitmapImage(u); ((Image)FindName("G" + Convert.ToString(playerAttuale + 1) + "_C" + cartaAttuale)).Source = b; cartaAttuale++; } } } else { MessageBox.Show("Inserire Valore per Re di Denara"); } }