private void Hit_Click(object sender, RoutedEventArgs e) { bool busted = false; if (cardnum < 6) { BitmapImage image = new BitmapImage(); cardnum++; Card card = new Card(); card = deck.deal(); pcards.Add(card); string pngsource = "/CardPNG/" + pcards[cardnum - 1].getPNG() + ".png"; image.BeginInit(); image.UriSource = new Uri(pngsource, UriKind.Relative); image.EndInit(); pImage[cardnum - 1].Source = image; busted = pbustcheck(busted); } if (busted == true) { BitmapImage image = new BitmapImage(); Title.Text = "You Went Bust"; EndGameButtons endGameButtons = new EndGameButtons(); ButtonGrid.ColumnDefinitions.Clear(); ButtonGrid.Children.Add(endGameButtons); string pngsource = "/CardPNG/" + dcards[0].getPNG() + ".png"; image.BeginInit(); image.UriSource = new Uri(pngsource, UriKind.Relative); image.EndInit(); dImage[0].Source = image; } }
private void Stay_Click(object sender, RoutedEventArgs e) { string pngsource1 = ""; bool busted = false; while (dtotalval() < 17) { dcards.Add(deck.deal()); dcardnum++; pngsource1 = "/CardPNG/" + dcards[dcardnum - 1].getPNG() + ".png"; BitmapImage image1 = new BitmapImage(new Uri(pngsource1, UriKind.Relative)); dImage[dcardnum - 1].Source = image1; } busted = dbustcheck(busted); if (busted == true) { Title.Text = "Dealer Went Bust"; } else { if (ptotalval() > dtotalval()) { Title.Text = "You Won"; } else if (ptotalval() < dtotalval()) { Title.Text = "Dealer Won"; } else { Title.Text = "You Tied"; } } EndGameButtons endGameButtons = new EndGameButtons(); ButtonGrid.ColumnDefinitions.Clear(); ButtonGrid.Children.Add(endGameButtons); BitmapImage image = new BitmapImage(); string pngsource = "/CardPNG/" + dcards[0].getPNG() + ".png"; image.BeginInit(); image.UriSource = new Uri(pngsource, UriKind.Relative); image.EndInit(); dImage[0].Source = image; }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { #region creating image arrays pImage.Add(this.P1Image); pImage.Add(this.P2Image); pImage.Add(this.P3Image); pImage.Add(this.P4Image); pImage.Add(this.P5Image); pImage.Add(this.P6Image); dImage.Add(this.D1Image); dImage.Add(this.D2Image); dImage.Add(this.D3Image); dImage.Add(this.D4Image); dImage.Add(this.D6Image); dImage.Add(this.D5Image); #endregion cardnum = 2; dcardnum = 2; deck.reset(); deck.shuffle(); Card placeholder = new BlackJack.Card(); for (int x = 0; x < 2; x++) { placeholder = deck.deal(); pcards.Add(placeholder); placeholder = deck.deal(); dcards.Add(placeholder); } string pngsource2 = "/CardPNG/back.png"; for (int x = 0; x < 2; x++) { BitmapImage image1 = new BitmapImage(); BitmapImage image2 = new BitmapImage(); string pngsource1 = "/CardPNG/" + pcards[x].getPNG() + ".png"; image1.BeginInit(); image1.UriSource = new Uri(pngsource1, UriKind.Relative); image1.EndInit(); pImage[x].Source = image1; image2.BeginInit(); image2.UriSource = new Uri(pngsource2, UriKind.Relative); image2.EndInit(); dImage[x].Source = image2; pngsource2 = "/CardPNG/" + dcards[1].getPNG() + ".png"; } if (ptotalval() == 21 && dtotalval() == 21) { Title.Text = "You Tie"; EndGameButtons endGameButtons = new EndGameButtons(); ButtonGrid.ColumnDefinitions.Clear(); ButtonGrid.Children.Add(endGameButtons); BitmapImage image = new BitmapImage(); string pngsource = "/CardPNG/" + dcards[0].getPNG() + ".png"; image.BeginInit(); image.UriSource = new Uri(pngsource, UriKind.Relative); image.EndInit(); dImage[0].Source = image; } else if (ptotalval() == 21) { //player blackjack Title.Text = "You Got BlackJack"; EndGameButtons endGameButtons = new EndGameButtons(); ButtonGrid.ColumnDefinitions.Clear(); ButtonGrid.Children.Add(endGameButtons); BitmapImage image = new BitmapImage(); string pngsource = "/CardPNG/" + dcards[0].getPNG() + ".png"; image.BeginInit(); image.UriSource = new Uri(pngsource, UriKind.Relative); image.EndInit(); dImage[0].Source = image; } else if (dtotalval() == 21) { //dealer blackjack Title.Text = "Dealer Got BlackJack"; EndGameButtons endGameButtons = new EndGameButtons(); ButtonGrid.ColumnDefinitions.Clear(); ButtonGrid.Children.Add(endGameButtons); BitmapImage image = new BitmapImage(); string pngsource = "/CardPNG/" + dcards[0].getPNG() + ".png"; image.BeginInit(); image.UriSource = new Uri(pngsource, UriKind.Relative); image.EndInit(); dImage[0].Source = image; } }