public void PlaceShipsOnBoard(IPlayer player) { try { _log.Info("BTG - trying to place ships on board!"); var ships = new[] { ShipType.Battleship, ShipType.Destroyer, ShipType.Destroyer }; var i = 0; foreach (var ship in ships) { _ship = _shipFactory.CreateShip(ship); _shipDirection = _randomManager.GetDirection(); do { _coordinate = _coordinateManager.GetRandomCoordinate(); }while (!_board.IsValidCoordinate(_coordinate, _shipDirection, _ship.Coordinates.Length) || _board.IsOverlap(player.Board.Ships, _coordinate)); _ship = PlaceShip(); player.Board.Ships[i++] = _ship; } _outputManager.WriteLine($"Ships for {player.Name} placed - completed!", ConsoleColor.Yellow); } catch (Exception e) { _log.Error($"BTG - Error when trying to place the ships on board: {e}"); } }
private IFireShotResponse Shot(IPlayer victim, IPlayer shooter, out ICoordinate shotPoint) { IFireShotResponse fireShotResponse; try { _log.Info("BTG - Trying to shot!"); do { if (!shooter.IsComputer) { _whereToShot = _inputManager.GetShotLocationManually(); fireShotResponse = _shotManager.FireShot(victim, _whereToShot); if (fireShotResponse.ShotStatus == ShotStatus.Invalid || fireShotResponse.ShotStatus == ShotStatus.Duplicate) { _outputManager.ShowShotResult(fireShotResponse, _whereToShot, shooter); } } else { _whereToShot = _coordinateManager.GetRandomCoordinate(); ; fireShotResponse = _shotManager.FireShot(victim, _whereToShot); } if (fireShotResponse.ShotStatus == ShotStatus.Victory) { shooter.Wins += 1; } } while (fireShotResponse.ShotStatus == ShotStatus.Duplicate || fireShotResponse.ShotStatus == ShotStatus.Invalid); shotPoint = _whereToShot; _log.Info("BTG - Shot completed!"); return(fireShotResponse); } catch (Exception e) { _log.Error($"BTG - Error when tryinh to shot: {e}"); } shotPoint = null; return(null); }