Example #1
0
        public GameTurnEntity FinishTurn()
        {
            var winnerId = Guid.Empty;

            for (int i = 0; i < 2; i++)
            {
                var player   = Players[i];
                var opponent = Players[1 - i];
                if (!player.Decision.HasValue || !opponent.Decision.HasValue)
                {
                    throw new InvalidOperationException();
                }
                if (player.Decision.Value.Beats(opponent.Decision.Value))
                {
                    player.Score++;
                    winnerId = player.UserId;
                }
            }
            //TODO Заполнить все внутри GameTurnEntity, в том числе winnerId
            var result = new GameTurnEntity();

            // Это должно быть после создания GameTurnEntity
            foreach (var player in Players)
            {
                player.Decision = null;
            }
            CurrentTurnIndex++;
            if (CurrentTurnIndex == TurnsCount)
            {
                Status = GameStatus.Finished;
            }
            return(result);
        }
Example #2
0
        public GameTurnEntity FinishTurn()
        {
            var winnerId = Guid.Empty;

            for (int i = 0; i < 2; i++)
            {
                var player   = Players[i];
                var opponent = Players[1 - i];
                if (!player.Decision.HasValue || !opponent.Decision.HasValue)
                {
                    throw new InvalidOperationException();
                }
                if (player.Decision.Value.Beats(opponent.Decision.Value))
                {
                    player.Score++;
                    winnerId = player.UserId;
                }
            }

            var result = new GameTurnEntity();

            result.GameId   = Id;
            result.WinnerId = winnerId;
            foreach (var player in Players)
            {
                result.AddPlayerDecision(player);
                player.Decision = null;
            }
            result.Index = ++CurrentTurnIndex;
            if (CurrentTurnIndex == TurnsCount)
            {
                Status = GameStatus.Finished;
            }
            return(result);
        }
Example #3
0
 public void Update(GameTurnEntity gameTurn)
 {
     turnCollection.ReplaceOne(x => x.Id == gameTurn.Id, gameTurn);
 }
Example #4
0
 public GameTurnEntity Insert(GameTurnEntity gameTurn)
 {
     turnCollection.InsertOne(gameTurn);
     return(gameTurn);
 }