예제 #1
0
 public BlackJackController()
 {
     _house  = new CardPlayer();
     Players = new List <ICardPlayer>();
     Bets    = new Dictionary <ICardPlayer, int>();
     Winner += Win;
 }
예제 #2
0
파일: Game.cs 프로젝트: bennnym/Myob.Fma
 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());
     }
 }
예제 #4
0
        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);
                }
            }
        }
예제 #5
0
 public void HitPlayer(ICardPlayer cardPlayer)
 {
     if (CountHand(cardPlayer.Hand) < 21)
     {
         cardPlayer.Hand.Add(deck.DrawCard());
         if (CountHand(cardPlayer.Hand) > 21)
         {
             Bust?.Invoke(cardPlayer);
         }
     }
 }
예제 #6
0
        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;
 }
예제 #10
0
 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());
 }
예제 #11
0
 public GambleCardPlayer(ICardPlayer <T> player, int chips = 0)
     : this(player.Name, player.Hand, chips)
 {
 }
예제 #12
0
 public GambleCardPlayer(ICardPlayer player, int chips = 0)
     : base(player, chips)
 {
 }
예제 #13
0
 public CardPlayer(ICardPlayer <T> player)
     : this(player.Name, player.Hand)
 {
 }
예제 #14
0
 public void Busted(ICardPlayer player)
 {
     _bustedPlayers.Add(player);
     Play(this);
 }
예제 #15
0
 public void Standing(ICardPlayer player)
 {
     _standingPlayers.Add(player);
     Play(this);
 }
예제 #16
0
        public void Win(ICardPlayer player, WinCondition condition)
        {
            int initialBet = Bets[player];

            player.AmountOfMonies += initialBet * (int)condition;
        }
예제 #17
0
 public HandChangedArgs(ICardPlayer player)
 {
     Player = player;
 }
예제 #18
0
 public void AddPlayer(ICardPlayer player)
 {
     _players.Add(player);
 }
예제 #19
0
 public override void TakeBets(ICardPlayer player, int bettingAmount)
 {
     player.AmountOfMonies -= bettingAmount;
 }
예제 #20
0
 public void Blackjack(ICardPlayer player)
 {
     _blackjackPlayers.Add(player);
     Play(this);
 }
 public void AllIn(ICardPlayer player)
 {
     moneyPot += player.AmountOfMonies;
     player.AmountOfMonies = 0;
 }
예제 #22
0
 public void Hit(ICardPlayer player)
 {
     player.AddCard(_cards.DealUp());
 }
 public PokerController()
 {
     Players = new List <ICardPlayer>();
     _house  = new CardPlayer();
     BetPool = new Dictionary <ICardPlayer, int>();
 }
예제 #24
0
 public override void DrawCardForPlayer(ICardPlayer player)
 {
     throw new NotImplementedException();
 }
예제 #25
0
 public CardPlayer(ICardPlayer <ICard> player)
     : base(player)
 {
 }
예제 #26
0
 public void DiscardAndDraw(ICardPlayer player, List <Card> discardedCards)
 {
     _controller.Discard(player, discardedCards);
 }
예제 #27
0
 public PlayerViewModel(ICardPlayer player)
 {
     _player = player;
 }