Ejemplo n.º 1
0
        private ShotConfig ConfigureShot()
        {
            ShotConfig shotConfig = new ShotConfig();

            shotConfig.RowNumber    = _userInterface.GetShotRow();
            shotConfig.ColumnNumber = _userInterface.GetShotColumn();

            return(shotConfig);
        }
Ejemplo n.º 2
0
        public void Play()
        {
            do
            {
                ShotConfig  shotConfig = ConfigureShot();
                Shot.Result shotResult = Shoot(shotConfig);

                _userInterface.PrintShotResult(shotResult);
                _userInterface.PrintNumberOfShipsOnBoard(_board.ShipsOnBoard);
                _userInterface.PrintBoardStatus(_board);
            } while (!_board.IsClear);
        }
Ejemplo n.º 3
0
        private Shot.Result Shoot(ShotConfig shotConfig)
        {
            BoardField targetField = _board.GetField(shotConfig.RowNumber, shotConfig.ColumnNumber);

            Shot.Result shotResult = targetField.Shoot();

            if (shotResult == Shot.Result.Destroyed)
            {
                _board.DecreaseShipsNumber();
            }

            _statistics.IncreaseShots();
            if (shotResult != Shot.Result.Missed)
            {
                _statistics.IncreaseShotsOnTarget();
            }

            return(shotResult);
        }