public BlackJackController() { _house = new CardPlayer(); Players = new List <ICardPlayer>(); Bets = new Dictionary <ICardPlayer, int>(); Winner += Win; }
public Game(ICardPlayer player, ICardPlayer dealer) { _players = new List <ICardPlayer>() { player, dealer }; _deck = new Deck(); }
public void Discard(ICardPlayer player, List <Card> discardedCards) { foreach (Card card in discardedCards) { player.Hand.Remove(card); player.Hand.Add(deck.DrawCard()); } }
private void CalculateWhoWon(ICardPlayer player) { var houseTotal = CountHand(_house.Hand); var playerTotal = CountHand(player.Hand); if (houseTotal > 21) { if (playerTotal <= 21) { if (playerTotal == 21) { Winner?.Invoke(player, WinCondition.Blackjack); } else if (player.Hand.Count >= 5) { Winner?.Invoke(player, WinCondition.Five_Card_Charlie); } else { Winner?.Invoke(player, WinCondition.Win); } } else { Winner?.Invoke(player, WinCondition.Draw); } } else if (playerTotal > 21) { Winner?.Invoke(player, WinCondition.IsThisLoss); } else { if (player.Hand.Count >= 5) { Winner?.Invoke(player, WinCondition.Five_Card_Charlie); } else if (playerTotal == 21) { Winner?.Invoke(player, WinCondition.Blackjack); } else if (playerTotal > houseTotal) { Winner?.Invoke(player, WinCondition.Win); } else if (houseTotal > playerTotal) { Winner?.Invoke(player, WinCondition.IsThisLoss); } else { Winner?.Invoke(player, WinCondition.Draw); } } }
public void HitPlayer(ICardPlayer cardPlayer) { if (CountHand(cardPlayer.Hand) < 21) { cardPlayer.Hand.Add(deck.DrawCard()); if (CountHand(cardPlayer.Hand) > 21) { Bust?.Invoke(cardPlayer); } } }
public void TakeInitialBet(ICardPlayer playerTakingTurn, int amountBetting) { if (amountBetting <= 0) { throw new ArgumentOutOfRangeException(nameof(amountBetting), "Amount betting must be greater than zero."); } Bets[playerTakingTurn] = amountBetting; playerTakingTurn.AmountOfMonies -= amountBetting; playerTakingTurn.Hand = GetStartingHand(); }
public void Raise(ICardPlayer player, int amountRaising) { if (!BetPool.ContainsKey(player)) { throw new ArgumentException("The Player Must have placed a bet before raising.", nameof(player)); } if (amountRaising <= 0) { throw new ArgumentOutOfRangeException(nameof(amountRaising), "The amount raising must be greater than 0."); } BetPool[player] += amountRaising; }
public void Call(ICardPlayer player) { player.AmountOfMonies -= (currentBet - player.LastBet); moneyPot += (currentBet - player.LastBet); player.LastBet = currentBet; //Prevents going into the negative when going all in on a high raise if (player.AmountOfMonies < 0) { player.AmountOfMonies = 0; } }
public void StartingBet(ICardPlayer player, int AmountBetting) { if (player is null) { throw new ArgumentNullException(nameof(player), "Player betting may not be null."); } if (AmountBetting <= 0) { throw new ArgumentOutOfRangeException(nameof(AmountBetting), "Amount betting must be greater than zero."); } BetPool[player] = AmountBetting; player.AmountOfMonies -= AmountBetting; }
private void RegisterListeners(ICardPlayer player, ICardPlayer dealer) { player.PlayerChanged += p => _connection.Send(_connectionId, new GameViewModel { Player = new PlayerViewModel(p) }.ToJson()); player.PlayerBusted += p => _connection.Send(_connectionId, new GameViewModel { Player = new PlayerViewModel(p) }.ToJson()); player.PlayerBlackjack += p => _connection.Send(_connectionId, new GameViewModel { Player = new PlayerViewModel(p) }.ToJson()); player.PlayerStanding += p => _connection.Send(_connectionId, new GameViewModel { Player = new PlayerViewModel(p) }.ToJson()); player.PlayerWon += p => _connection.Send(_connectionId, new GameViewModel { Player = new PlayerViewModel(p) }.ToJson()); player.PlayerLost += p => _connection.Send(_connectionId, new GameViewModel { Player = new PlayerViewModel(p) }.ToJson()); player.PlayerStandoff += p => _connection.Send(_connectionId, new GameViewModel { Player = new PlayerViewModel(p) }.ToJson()); player.Hand.HandChanged += (sender, args) => _connection.Send(_connectionId, new GameViewModel { Player = new PlayerViewModel(args.Player) }.ToJson()); dealer.PlayerChanged += p => _connection.Send(_connectionId, new GameViewModel { Dealer = new PlayerViewModel(p) }.ToJson()); dealer.PlayerBusted += p => _connection.Send(_connectionId, new GameViewModel { Dealer = new PlayerViewModel(p) }.ToJson()); dealer.PlayerBlackjack += p => _connection.Send(_connectionId, new GameViewModel { Dealer = new PlayerViewModel(p) }.ToJson()); dealer.PlayerStanding += p => _connection.Send(_connectionId, new GameViewModel { Dealer = new PlayerViewModel(p) }.ToJson()); dealer.PlayerWon += p => _connection.Send(_connectionId, new GameViewModel { Dealer = new PlayerViewModel(p) }.ToJson()); dealer.PlayerLost += p => _connection.Send(_connectionId, new GameViewModel { Dealer = new PlayerViewModel(p) }.ToJson()); dealer.PlayerStandoff += p => _connection.Send(_connectionId, new GameViewModel { Dealer = new PlayerViewModel(p) }.ToJson()); dealer.Hand.HandChanged += (sender, args) => _connection.Send(_connectionId, new GameViewModel { Dealer = new PlayerViewModel(args.Player) }.ToJson()); }
public GambleCardPlayer(ICardPlayer <T> player, int chips = 0) : this(player.Name, player.Hand, chips) { }
public GambleCardPlayer(ICardPlayer player, int chips = 0) : base(player, chips) { }
public CardPlayer(ICardPlayer <T> player) : this(player.Name, player.Hand) { }
public void Busted(ICardPlayer player) { _bustedPlayers.Add(player); Play(this); }
public void Standing(ICardPlayer player) { _standingPlayers.Add(player); Play(this); }
public void Win(ICardPlayer player, WinCondition condition) { int initialBet = Bets[player]; player.AmountOfMonies += initialBet * (int)condition; }
public HandChangedArgs(ICardPlayer player) { Player = player; }
public void AddPlayer(ICardPlayer player) { _players.Add(player); }
public override void TakeBets(ICardPlayer player, int bettingAmount) { player.AmountOfMonies -= bettingAmount; }
public void Blackjack(ICardPlayer player) { _blackjackPlayers.Add(player); Play(this); }
public void AllIn(ICardPlayer player) { moneyPot += player.AmountOfMonies; player.AmountOfMonies = 0; }
public void Hit(ICardPlayer player) { player.AddCard(_cards.DealUp()); }
public PokerController() { Players = new List <ICardPlayer>(); _house = new CardPlayer(); BetPool = new Dictionary <ICardPlayer, int>(); }
public override void DrawCardForPlayer(ICardPlayer player) { throw new NotImplementedException(); }
public CardPlayer(ICardPlayer <ICard> player) : base(player) { }
public void DiscardAndDraw(ICardPlayer player, List <Card> discardedCards) { _controller.Discard(player, discardedCards); }
public PlayerViewModel(ICardPlayer player) { _player = player; }