public void Combine(Entry entry, GameResult result)
        {
            Count        += entry.Count;
            TotalEloDiff += entry.EloDiff.Or(0);

            switch (result)
            {
            case GameResult.WhiteWin:
                WinCount += entry.Count;
                break;

            case GameResult.Draw:
                DrawCount += entry.Count;
                break;

            case GameResult.BlackWin:
                LossCount += entry.Count;
                break;
            }

            if (FirstGame.Count() == 0)
            {
                FirstGame = entry.FirstGame;
            }
            else if (entry.FirstGame.Count() != 0 && entry.FirstGame.First().GameId < FirstGame.First().GameId)
            {
                FirstGame = entry.FirstGame;
            }
        }
        public async Task <Guid> CreateGame(
            FirstGameType firstGameType,
            DateTimeOffset registrationEndDate,
            DateTimeOffset gameDate,
            string description)
        {
            switch (firstGameType)
            {
            case FirstGameType.Basketball:
                var basketballGame = new FirstGame
                {
                    RegistrationEndDate         = registrationEndDate,
                    MaxPlayersCount             = 10,
                    MinimalRequiredPlayersCount = 6,
                    Description = description,
                    GameDate    = gameDate,
                    Guid        = Guid.NewGuid()
                };
                await _gameRepository.SaveGameAsync(basketballGame);

                return(basketballGame.Guid);

            case FirstGameType.Chess:
                var chessGame = new FirstGame
                {
                    RegistrationEndDate         = registrationEndDate,
                    MaxPlayersCount             = 10,
                    MinimalRequiredPlayersCount = 6,
                    Description = description,
                    GameDate    = gameDate,
                    Guid        = Guid.NewGuid()
                };
                await _gameRepository.SaveGameAsync(chessGame);

                return(chessGame.Guid);

            case FirstGameType.Soccer:
                var soccerGame = new FirstGame
                {
                    RegistrationEndDate         = registrationEndDate,
                    MaxPlayersCount             = 10,
                    MinimalRequiredPlayersCount = 6,
                    Description = description,
                    GameDate    = gameDate,
                    Guid        = Guid.NewGuid()
                };
                await _gameRepository.SaveGameAsync(soccerGame);

                return(soccerGame.Guid);

            default:
                throw new ArgumentException();
            }
        }
        public Task SaveGameAsync(FirstGame newGame)
        {
            var storedGame = _store.SingleOrDefault(x => x.Guid == newGame.Guid);

            if (storedGame != null)
            {
                _store.Remove(storedGame);
            }

            _store.Add(newGame);
            return(Task.CompletedTask);
        }
        public void Combine(AggregatedEntry entry)
        {
            if (entry == null)
            {
                return;
            }

            Count        += entry.Count;
            WinCount     += entry.WinCount;
            DrawCount    += entry.DrawCount;
            LossCount    += entry.LossCount;
            TotalEloDiff += entry.TotalEloDiff;

            if (FirstGame.Count() == 0)
            {
                FirstGame = entry.FirstGame;
            }
            else if (entry.FirstGame.Count() != 0 && entry.FirstGame.First().IsBefore(FirstGame.First()))
            {
                FirstGame = entry.FirstGame;
            }
        }
Beispiel #5
0
 static void Main()
 {
     using (var game = new FirstGame())
         game.Run();
 }
 public void UpdateBothGameStatus()
 {
     FirstGame.UpdateGameStatus();
     SecondGame.UpdateGameStatus();
 }