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)); }
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"); } }
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); }
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); }
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(); }
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); }