Exemplo n.º 1
0
 public void Receive(string message)
 {
     switch (message)
     {
         case "new-game":
             GUIPlayer player = new GUIPlayer("GUI");
             GUIDealer dealer = new GUIDealer("Dealer");
             NewGame(player, dealer);
             break;
         case "bet-25":
             _player.Place25Bet();
             break;
         case "bet-50":
             _player.Place50Bet();
             break;
         case "bet-100":
             _player.Place100Bet();
             break;
         case "hit":
             _player.TakeCard();
             break;
         case "stand":
             _player.Stand();
             break;
         case "double-down":
             _player.DoubleDown();
             break;
         case "play-again":
             _dealer.NewGame();
             break;
         default:
             throw new ArgumentOutOfRangeException("message");
     }
 }
Exemplo n.º 2
0
 public void TestGameConvertsToJson()
 {
     GUIPlayer player = new GUIPlayer("PLAYER1");
     GUIDealer dealer = new GUIDealer("DEALER");
     GameViewModel model = new GameViewModel
     {
         Player = new PlayerViewModel(player),
         Dealer = new PlayerViewModel(dealer)
     };
     Assert.AreEqual("{\"player\":{\"name\":\"PLAYER1: £1000.00\",\"currentState\":\"GUIBetting\",\"hand\":{\"cards\":[]}},\"dealer\":{\"name\":\"DEALER\",\"currentState\":\"DealerCollectingBets\",\"hand\":{\"cards\":[]}}}", model.ToJson());
 }
Exemplo n.º 3
0
        public void TestNewGameSubscribesToThePlayersHandChangedEvent()
        {
            string actualConnectionId = null;
            string actualMessage = null;

            _mockConnection.Setup(m => m.Send(It.IsAny<ConnectionMessage>())).Callback<ConnectionMessage>(c =>
                {
                    actualConnectionId = c.Signal;
                    actualMessage = c.Value.ToString();
                });

            Mock<IBlackjackDealer> mockDealer = new Mock<IBlackjackDealer>();
            mockDealer.SetupGet(m => m.Hand).Returns(new Hand());
            GUIPlayer player = new GUIPlayer("TEST");
            _engine.NewGame(player, mockDealer.Object);
            player.AddCard(new Card(Rank.Four, Suit.Diamonds));
            Assert.AreEqual("c-BCC23BA3-3F01-4F7F-B95E-01031DBC7A9F", actualConnectionId);
            Assert.AreEqual("{\"player\":{\"name\":\"TEST: £1000.00\",\"currentState\":\"GUIBetting\",\"hand\":{\"cards\":[{\"rank\":\"4\",\"suit\":\"D\",\"isFaceUp\":true}]}}}", actualMessage);
        }
Exemplo n.º 4
0
 public void TestBettingPlayerConvertsToJson()
 {
     GUIPlayer consolePlayer = new GUIPlayer("PLAYER1");
     PlayerViewModel player = new PlayerViewModel(consolePlayer);
     Assert.AreEqual("{\"name\":\"PLAYER1: £1000.00\",\"currentState\":\"GUIBetting\",\"hand\":{\"cards\":[]}}", player.ToJson());
 }