Esempio n. 1
0
        public Game Roll(PlayerId player)
        {
            if (_turn.CurrentPlayer.Equals(player))
            {
                var rolledNumber = _random.Next(1, 7);
                var diceRolled   = new DiceRolled(GameId, rolledNumber, player);

                var nextPlayer = GetNextPlayer();
                if (nextPlayer != null)
                {
                    ApplyEvents(diceRolled, new TurnChanged(GameId, new Turn(nextPlayer, GlobalSettings.TurnTimeoutSeconds)));
                }
                else
                {
                    var game = ApplyEvent(diceRolled);
                    if (game is RunningGame)
                    {
                        ApplyEvent(new GameFinished(GameId, BestPlayers()));
                    }
                }
                return(this);
            }
            else
            {
                throw new NotCurrentPlayerViolation();
            }
        }
Esempio n. 2
0
        public Game Roll(PlayerId player)
        {
            if (_turn.CurrentPlayer.Equals(player))
            {
                var rolledNumber = _random.Next(1, 7);
                var diceRolled   = new DiceRolled(GameId, rolledNumber, player);

                var nextPlayer = GetNextPlayer();
                if (nextPlayer != null)
                {
                    RegisterUncommitedEvents(diceRolled, new TurnChanged(GameId, new Turn(nextPlayer, GlobalSettings.TurnTimeoutSeconds)));
                }
                else
                {
                    //collect all previous rolls to finish the game
                    var rolls = _rolledNumbers.ToList();
                    //add the last roll
                    rolls.Add(new KeyValuePair <PlayerId, int>(diceRolled.Player, diceRolled.RolledNumber));

                    RegisterUncommitedEvents(diceRolled, new GameFinished(GameId, BestPlayers(rolls)));
                }
                return(this);
            }
            else
            {
                throw new NotCurrentPlayerViolation();
            }
        }