Example #1
0
        public void PlaceShip(Guid gameId, string userId, Location shipStart, Location shipEnd)
        {
            try
            {
                _authorizer.AssertAuthorizedForPlaceShip(userId, gameId);

                var game = _repo.Get(gameId);

                game.PlaceShip(userId, shipStart, shipEnd);

                _logger.Info($"Player {game.GetPlayerNumber(userId)} placed a ship at {shipStart.ToString()}-{shipEnd.ToString()}");

                _repo.Update(gameId, game);
            }
            catch (InvalidOperationException ex)
            {
                _logger.Warn($"An error occurred placing a ship: {ex.Message}");
                throw;
            }
            catch (Exception ex)
            {
                _logger.Error("An error occurred placing a ship", ex);
                throw;
            }
        }