Exemplo 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);
                }
            }
Exemplo n.º 2
0
        public void StoreSeriesEvent(GameSeriesEvent gameEvent)
        {
            var persistableEvent = GameSeriesEventSerializer.Convert(gameEvent);

            using var ctx = _contextFactory.CreateDbContext();
            ctx.SeriesEvents.Add(persistableEvent);
            ctx.SaveChanges();
        }
Exemplo n.º 3
0
 public static PersistedSeriesEvent Convert(GameSeriesEvent ev)
 {
     return(new PersistedSeriesEvent
     {
         GameUuid = ev.GameUuid,
         Payload = ConvertPayload(ev),
         Type = ConvertType(ev)
     });
 }
Exemplo n.º 4
0
 public void OnNext(GameSeriesEvent value)
 {
     _logger.LogInformation("persisting {gameSeriesEvent}", value);
     // HACK: want to stay in 10k rows. Therefore delete previous rounds events for now.
     // TODO: old events can be used for stats, delete only when series is finished.
     if (value is RoundStarted roundStarted)
     {
         _repo.DeleteOutdatedEvents(roundStarted.GameUuid);
     }
     _repo.StoreSeriesEvent(value);
 }
Exemplo n.º 5
0
        public void OnNext(GameSeriesEvent value)
        {
            switch (value)
            {
            case GameSeriesStarted gameSeriesStarted:
                OnNext(gameSeriesStarted);
                break;

            case RoundStarted roundStarted:
                OnNext(roundStarted);
                break;

            case RoundEnded ended:
                OnNext(ended);
                break;
            }
        }
Exemplo n.º 6
0
 public void StoreSeriesEvent(GameSeriesEvent gameEvent)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 7
0
 public void OnNext(GameSeriesEvent value)
 {
     System.Console.WriteLine(value);
 }