Ejemplo n.º 1
0
 private HandReceivedDto GetHandReceivedData(GameEventContext ctx, HandReceived hand)
 {
     if (hand.Player == _playerIndex)
     {
         var knownHand = hand.Hand as KnownHand;
         return(HandReceivedDto.ForKnownHand(ctx.GameId, ctx.RoundIndex, hand.Player, knownHand.Select(GetIndex).ToList()));
     }
     return(HandReceivedDto.ForSecretHand(ctx.GameId, ctx.RoundIndex, hand.Player, hand.Hand.NumberOfCards));
 }
Ejemplo n.º 2
0
 public HandReceivedPayload(HandReceived hr) : base(hr)
 {
     if (hr.Hand is KnownHand knownHand)
     {
         Cards = knownHand.Select(SerializableCard.From).ToList();
     }
     else
     {
         throw new NotSupportedException("cannot serialize hidden hands");
     }
 }
Ejemplo n.º 3
0
        public void HandReceivedIsMappedAndBack()
        {
            var ctx = new GameEventContext("g", 12);
            var handReceivedEvent = new HandReceived(ctx, new PlayerIndex(4), new KnownHand(new[] { new Card(Suit.Club, Rank.Four), new Card(Suit.Hearts, Rank.Ace) }));

            var persistable = GameEventSerializer.Convert(handReceivedEvent);
            var recreated   = GameEventSerializer.Convert(persistable) as HandReceived;

            Assert.Equal(4, recreated.Player.Value);
            Assert.Equal(handReceivedEvent.Hand, recreated.Hand);
        }
Ejemplo n.º 4
0
        public Task HandReceived(HandReceivedDto data)
        {
            System.Console.WriteLine(data);
            var hand = data.CardIndices == null ?
                       (IHand) new UnknownHand(data.NumberOfCards) :
                       new KnownHand(data.CardIndices.Select(i => _deck[i]));
            var ctx = new GameEventContext(data.GameId, data.RoundIndex);
            var e   = new HandReceived(ctx, new PlayerIndex(data.PlayerIndex), hand);

            System.Console.WriteLine(e);
            _gameEventCallback(e);
            return(Task.CompletedTask);
        }
Ejemplo n.º 5
0
        public void OnNext(GameEvent e)
        {
            var task = e
                       switch
            {
                HandReceived hand => _client.HandReceived(GetHandReceivedData(e.Context, hand)),
                CardPlayed move => _client.CardPlayed(new CardPlayedDto(e.Context.GameId, e.Context.RoundIndex, move.Player, GetIndex(move.Card))),
                GuessGiven guess => _client.GuessGiven(new GuessGivenDto(e.Context.GameId, e.Context.RoundIndex, guess.Player, guess.Count)),
                TrickWon trick => _client.TrickWon(new TrickWonDto(e.Context.GameId, e.Context.RoundIndex, trick.Player)),
                _ => Task.CompletedTask,
            };

            task.GetAwaiter().GetResult();
        }
Ejemplo n.º 6
0
            public void OnNext(GameEvent e)
            {
                var player  = _playerNames[e.Player];
                var message = e
                              switch
                {
                    GuessGiven guess => $"{player} made guess of <{guess.Count}>",
                    CardPlayed move => $"{player} played {move.Card} ({move.Card.Rank} of {move.Card.Suit})",
                    HandReceived received => $"{player} got {received.Hand.NumberOfCards} cards",
                    TrickWon trick => $"{player} won the trick",
                    _ => e.ToString(),
                };

                Render(message, ConsoleColor.DarkGreen);
            }