Exemplo n.º 1
0
 public void PlayerDrawCard(string playerName, Card card)
 {
     if (PlayerDrawCardEvent != null)
     {
         PlayerDrawCardEvent.Invoke(playerName, card);
     }
 }
Exemplo n.º 2
0
        public void CardInfoIsSerializable()
        {
            AEvent source = new PlayerDrawCardEvent(Player.Player2);

            var deckP1 = new Deck().WithCardCount(1);
            var deckP2 = new Deck().WithCardCount(1);

            var gameState = new GameState(deckP1, deckP2);

            source.Run(gameState);

            GameMessage gameMessage = new GameMessage(source);

            string serialized = Util.Json.Serialize(gameMessage);

            GameMessage deserialized = Util.Json.Deserialize <GameMessage>(serialized);

            AEvent receivedEvent = deserialized.ToEvent();

            PlayerDrawCardEvent deserializedEvent = receivedEvent as PlayerDrawCardEvent;

            Assert.Equal(TestCards.SleepyPanda.Value.Title, deserializedEvent.CardDrawn.Value.Title);
            Assert.Equal(TestCards.SleepyPanda.Value.Text, deserializedEvent.CardDrawn.Value.Text);
            Assert.Equal(TestCards.SleepyPanda.Value.Cost, deserializedEvent.CardDrawn.Value.Cost);
            // ...
        }
Exemplo n.º 3
0
        public override void Run(GameState gameState)
        {
            for (int i = 0; i < this.DrawCount; i++)
            {
                var drawEventPlayer1 = new PlayerDrawCardEvent(Player.Player1);
                var drawEventPlayer2 = new PlayerDrawCardEvent(Player.Player2);

                EventRunner.RunEvent(drawEventPlayer1, gameState);
                EventRunner.RunEvent(drawEventPlayer2, gameState);
            }
        }
Exemplo n.º 4
0
        public void DrawCard()
        {
            const int    StartingDeckSize = 10;
            const Player playerToDraw     = Player.Player2;

            var deck1 = new Deck().WithCardCount(StartingDeckSize);
            var deck2 = new Deck().WithCardCount(StartingDeckSize);

            var gameState = new GameState(deck1, deck2);

            int startingHandSize = gameState.GetHand(playerToDraw).Size;

            var drawEvent = new PlayerDrawCardEvent(playerToDraw);

            EventRunner.RunEvent(drawEvent, gameState);

            Assert.Equal(StartingDeckSize - 1, deck2.Size);
            Assert.Equal(startingHandSize + 1, gameState.GetHand(playerToDraw).Size);
        }
Exemplo n.º 5
0
        public void GameMessageIsSerializable()
        {
            AEvent source = new PlayerDrawCardEvent(Player.Player2);

            GameMessage gameMessage = new GameMessage(source);

            // even though our reference is the abstract type, we should still know the derived
            Assert.Equal(typeof(PlayerDrawCardEvent), gameMessage.ContentType);

            string serializedMessage = Util.Json.Serialize(gameMessage);

            GameMessage deserializedMessage = Util.Json.Deserialize <GameMessage>(serializedMessage);

            // upon deserialization, the content type should still be known
            Assert.Equal(typeof(PlayerDrawCardEvent), deserializedMessage.ContentType);

            PlayerDrawCardEvent sourceCast   = source as PlayerDrawCardEvent;
            PlayerDrawCardEvent deserialized = deserializedMessage.DeserializeContent <PlayerDrawCardEvent>();

            Assert.Equal(sourceCast.Player, deserialized.Player);
        }