//Enviar Carta A La Derecha private void SendCardRight(bool back) { //get Card card = dealer.Deal(); card.Back = back; //add dealer.AddCard(card); //draw Grid cardToDraw = DrawCard(Convert.ToInt32(grdMaster.ActualWidth / 4), -200, card.Symbol, card.Suit, card.Back); //add to gridlist gridRightCards.Add(cardToDraw); //animate Animate(cardToDraw, rightPos[dealer.getCardCount() - 1, 0], rightPos[dealer.getCardCount() - 1, 1], rightPos[dealer.getCardCount() - 1, 2], Convert.ToInt32(grdMaster.ActualWidth / 4), -200); //sound SoundCard(0); UpdateLabelScore(); //Change rect color (ROJO) if (Check(dealer.Hand) > 21) { Color color = new Color(); color.A = 100; color.R = 255; color.G = 0; color.B = 0; rctScoreDealer.Fill = new SolidColorBrush(color); } }
private void Button_Click(object sender, RoutedEventArgs e) { Card card = d.Deal(); d.AddCard(card); txtDealerHand.Text = ""; foreach (Card c in d.Hand) { txtDealerHand.Text += c.Symbol + c.Suit + " "; } int count = 1; txtPrueba.Text = ""; foreach (Card c in d.Deck) { if (count == 13) { txtPrueba.Text += c.Symbol + c.Suit + "\n"; count = 1; } else { txtPrueba.Text += c.Symbol + c.Suit + " "; count++; } } }
private void btnStart_Click(object sender, RoutedEventArgs e) { btnStart.Visibility = Visibility.Collapsed; lbMatchResults.Content = ""; lbDealerCards.Content = ""; lbPlayerCards.Content = ""; PlayerScore = 0; DealerScore = 0; d = new Dealer(); p = new Player(); p.PlayerReady(); p.Hand.Clear(); d.Generate(); d.Hand.Clear(); d.Randomize(); lbCardsCount.Content = "Cards In Deck = " + d.Deck.Count.ToString(); Card FirstPlayerCard = d.Deal(); Card SecondPlayerCard = d.Deal(); p.Init(FirstPlayerCard, SecondPlayerCard); lbPlayerCards.Content = lbPlayerCards.Content + FirstPlayerCard.Symbol + FirstPlayerCard.Suit + " " + SecondPlayerCard.Symbol + SecondPlayerCard.Suit; PlayerScore = PlayerScore + FirstPlayerCard.Score + SecondPlayerCard.Score; lbPlayerScore.Content = "Total = " + PlayerScore.ToString(); lbCardsCount.Content = "Cards In Deck = " + d.Deck.Count.ToString(); Card FirstDealerCard = d.Deal(); d.AddCard(FirstDealerCard); lbDealerCards.Content = lbDealerCards.Content + FirstDealerCard.Symbol + FirstDealerCard.Suit; DealerScore = DealerScore + FirstDealerCard.Score; lbDealerScore.Content = "Total = " + DealerScore.ToString(); lbCardsCount.Content = "Cards In Deck = " + d.Deck.Count.ToString(); btnHit.Visibility = Visibility.Visible; btnStand.Visibility = Visibility.Visible; if (PlayerScore == 21) { lbMatchResults.Foreground = Brushes.Yellow; lbMatchResults.Content = "You Win!"; MatchesCount++; VictoryCount++; lbTotalMatches.Content = "Total Matches = " + MatchesCount.ToString(); lbVictoryCount.Content = "V = " + VictoryCount.ToString(); btnHit.Visibility = Visibility.Collapsed; btnStand.Visibility = Visibility.Collapsed; btnNewRound.Visibility = Visibility.Visible; } }
//****************************************************************************************** public void PlaySingleHand() { StartHand(); if (dealer.HasOnlyAce) { CollectInsurance(); DecideOnEvenMoney(); } // Players foreach (Player player in players) { while (player.HasActiveBox) { if (player.ActiveBox.CardsAmount == 1) { player.ActiveBox.AddCard(PopCardFromShoe()); } uiManager.DisplayAll(dealer, players, player); int optionsAmount = uiManager.OptionsAmount; // Making decision bool makingDecision = true; int decision = 0; while (makingDecision) { try { decision = Convert.ToInt32(Console.ReadLine()); if (decision < 1 || decision > optionsAmount) { Console.WriteLine("Wrong number! Try again."); } else { makingDecision = false; } } catch { Console.WriteLine("It needs to be a number!"); } } Option?choosenOption = uiManager.GetOption(decision - 1); // Taking action based on decision switch (choosenOption) { case Option.Hit: player.AddCard(PopCardFromShoe()); break; case Option.Stand: player.Stand(); break; case Option.Surrender: player.Surrender(); break; case Option.Double: player.Double(PopCardFromShoe()); break; case Option.Split: player.Split(); break; } } } // Dealer while (!dealer.ShouldStopHitting(players)) { dealer.AddCard(PopCardFromShoe()); } // Playing is over, summarying the hand uiManager.DisplayAll(dealer, players); PayoutWinnings(); Console.WriteLine("Press Enter to play another hand..."); Console.ReadLine(); Reset(); }
private void btnStand_Click(object sender, RoutedEventArgs e) { if (PlayerScore > 16) { while (DealerScore < 17) { if (d.Deck.Count > 0) { Card card = d.Deal(); d.AddCard(card); lbDealerCards.Content = lbDealerCards.Content + " " + card.Symbol + card.Suit; DealerScore = DealerScore + card.Score; if (DealerScore > 21) { DealerScore = 0; foreach (Card c in d.Hand) { if (c.Score == 11) { c.Score = 1; } DealerScore = DealerScore + c.Score; } } } else { break; } } lbDealerScore.Content = "Total = " + DealerScore.ToString(); lbCardsCount.Content = "Cards In Deck = " + d.Deck.Count.ToString(); if (PlayerScore > DealerScore || DealerScore > 21) { lbMatchResults.Foreground = Brushes.Yellow; lbMatchResults.Content = "You Win!"; MatchesCount++; VictoryCount++; lbTotalMatches.Content = "Total Matches = " + MatchesCount.ToString(); lbVictoryCount.Content = "V = " + VictoryCount.ToString(); } else { lbMatchResults.Foreground = Brushes.Red; lbMatchResults.Content = "You Lose!"; MatchesCount++; DefeatCount++; lbTotalMatches.Content = "Total Matches = " + MatchesCount.ToString(); lbDefeatCount.Content = "D = " + DefeatCount.ToString(); } btnHit.Visibility = Visibility.Collapsed; btnStand.Visibility = Visibility.Collapsed; if (d.Deck.Count > 0) { btnNewRound.Visibility = Visibility.Visible; } else { MessageBox.Show("No Cards Left" + "\n" + "Press Restart"); btnStart.Visibility = Visibility.Visible; } } else { MessageBox.Show("Your Score has to be higher than 16"); } }