Ejemplo n.º 1
0
            public void OnNext(GameSeriesEvent e)
            {
                var message = e
                              switch
                {
                    GameSeriesStarted start => $"a new game series of {start.Plan.Rounds.Count} rounds was started",
                    RoundStarted roundStarted => $"a new round started",
                    RoundEnded roundEnded => $"round finished. {PointInfo(roundEnded.Result.PlayerResults)}",
                    _ => e.ToString(),
                };

                Render(message, ConsoleColor.DarkMagenta);
                if (e is GameSeriesStarted s)
                {
                    _playerNames = s.Players.Select(p => p.Name).ToList();
                    _totalScores = s.Players.Select(_ => 0).ToList();
                }
                else if (e is RoundEnded end)
                {
                    foreach (var(r, i) in end.Result.PlayerResults.Select((r, i) => (r, i)))
                    {
                        _totalScores[i] += r.Score;
                    }
                    Render("Total scores: " + string.Join(", ", Enumerable.Zip(_playerNames, _totalScores)), ConsoleColor.DarkMagenta);
                }
            }
Ejemplo n.º 2
0
 internal void NotifySeriesStart(GameSeriesStarted seriesStartEvent)
 {
     foreach (var bot in _bots)
     {
         bot?.NoteSeriesStart(seriesStartEvent);
     }
 }
Ejemplo n.º 3
0
 public void NoteSeriesStart(GameSeriesStarted seriesStarted)
 {
     Deck         = seriesStarted.Plan.Deck;
     _cardIndices = new Dictionary <Card, int>();
     foreach (var(card, index) in Deck.AllCards.Select((c, i) => (c, i)))
     {
         _cardIndices.Add(card, index);
     }
 }
Ejemplo n.º 4
0
        public Task GameSeriesStarted(GameSeriesDto data)
        {
            _deck = new GameCardDeck((Rank)data.MinCardRank);
            var plannedRounds = data.PlannedRounds
                                .Select(setting => new EumelRoundSettings(setting.StartingPlayer, setting.TricksToPlay));
            var plan    = new EumelGamePlan(plannedRounds, _deck);
            var players = data.PlayerInfos.Select(p => new PlayerInfo(p.Name, p.Type)).ToList();
            var e       = new GameSeriesStarted(data.GameId, players, plan);

            _gameSeriesEventCallback(e);
            return(Task.CompletedTask);
        }
Ejemplo n.º 5
0
        public void OnNext(GameSeriesStarted started)
        {
            var deck = started.Plan.Deck;

            _cardIndices = deck.AllCards
                           .Select((Card, Index) => (Card, Index))
                           .ToDictionary(pair => pair.Card, pair => pair.Index);
            var minCardRank   = (int)deck[0].Rank;
            var plannedRounds = started.Plan.Rounds.Select(ConvertRoundSettingsToDto);
            var playerInfos   = started.Players.Select(p => new PlayerDto(p.Name, p.Type));
            var data          = new GameSeriesDto(started.GameUuid, minCardRank, playerInfos, plannedRounds);

            _client.GameSeriesStarted(data);
        }
Ejemplo n.º 6
0
        public void GameSeriesStartIsMappedAndBack()
        {
            var playerInfos = new List <PlayerInfo> {
                new PlayerInfo("a", "t1"),
                new PlayerInfo("b", "t2"),
                new PlayerInfo("c", "t1")
            };
            var plan          = EumelGamePlan.For(3);
            var seriesStarted = new GameSeriesStarted("uuid", playerInfos, plan);

            var persistable = GameSeriesEventSerializer.Convert(seriesStarted);
            var recreated   = GameSeriesEventSerializer.Convert(persistable) as GameSeriesStarted;

            Assert.Equal(seriesStarted.Plan, recreated.Plan);
            Assert.Equal(seriesStarted.Players, recreated.Players);
            Assert.Equal(seriesStarted, recreated);
        }
Ejemplo n.º 7
0
 public void NoteSeriesStart(GameSeriesStarted seriesStarted)
 {
 }
Ejemplo n.º 8
0
 public SeriesStartedPayload(GameSeriesStarted seriesStarted)
 {
     Players = seriesStarted.Players.ToList();
 }
Ejemplo n.º 9
0
 private void AddSeriesStart(GameSeriesStarted seriesStarted)
 {
     _events.Insert(seriesStarted);
     _botController.NotifySeriesStart(seriesStarted);
 }