Exemple #1
0
 private void Apply(GameEndedGameEvent @event)
 {
     Status = GameStatus.Ended;
     WinnerTeam = @event.Winner;
 }
Exemple #2
0
        public Game End()
        {
            if (Status != GameStatus.Playing)
            {
                throw new InvalidOperationException("Can't end non-playing games.");
            }

            var winner = Board.GetSequences()
                              .GroupBy(s => s.Team)
                              .SingleOrDefault(s => s.Count() == 2);

            if (winner == null)
            {
                throw new InvalidOperationException("No team has enough sequences to win.");
            }

            var team = winner.Key;
            var e = new GameEndedGameEvent(Guid.NewGuid(), Id, Guid.Empty, Version + 1, team);
            RaiseEvent(e);
            return this;
        }