Esempio n. 1
0
        public Dictionary <int, Stats> Stats => new Dictionary <int, Stats>(_stats); // Returning a copy of the list to prevent fiddling from outside the Entity with the actual dictionary

        protected override void Init()
        {
            var groups = CompletedGames.GroupBy(g => g.NrOfDigits);

            foreach (var group in groups)
            {
                CalculateStats(group.Key, group);
            }
        }
Esempio n. 2
0
        public void NewGame(StartGame command) 
        {
            if (CompletedGames.Any(g => g.Id == command.Game) || ActiveGame?.Id == command.Game)
                throw new DXGameException("game_already_started");
            if (ActiveGame != null && ActiveGame.State != GameState.Finished && ActiveGame.State != GameState.None)
                throw new DXGameException("another_game_is_already_in_progress");
            if (_players.Count < 3)
                throw new DXGameException("too_small_amount_of_players");
            if (!_players.Contains(command.Requester))
                throw new DXGameException("unathorized_request");

            ApplyEvent(new GameStartRequested(this.Id, command.Game, command.CommandId));
        }
Esempio n. 3
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder
            .Query <LeaderBoardRecord>()
            .ToQuery(() => Players.Select(p => new LeaderBoardRecord
            {
                Player = p,
                Wins   = CompletedGames.Count(g => g.WinnerId == p.Id),
                Losses = CompletedGames.Count(g => g.LoserId == p.Id)
            }));

            /*
             * SELECT p.*, WinCount, LossCount
             * FROM Players p INNER JOIN
             * (SELECT WinnerId, COUNT(1) WinCount FROM CompletedGames GROUP BY WinnerId) w ON p.Id = w.WinnerId INNER JOIN
             * (SELECT LoserId, COUNT(1) LossCount FROM CompletedGames GROUP BY LoserId) l ON p.Id = l.LoserId
             */
        }
Esempio n. 4
0
        protected override void HandleGameCompleted(Game game)
        {
            var gamesToRecalculate = CompletedGames.Where(item => item.NrOfDigits == game.NrOfDigits);

            CalculateStats(game.NrOfDigits, gamesToRecalculate);
        }