Exemple #1
0
        public static Position GetFromBattleshipBoard(char gridRow, string gridCol)
        {
            int row = (int)gridRow - GlobalConstants.MinRowValueOnGridAsciiCode;
            int col = int.Parse(gridCol) - 1;
            var position = new Position(row, col);

            return position;
        }
 /// <summary>
 /// Updates grid position
 /// </summary>
 public void UpdateGrid(Grid grid, Position position)
 {
     Console.SetCursorPosition(position.Col + GridColPosition + 1, position.Row + GridRowPosition + 1);
     Console.Write(grid.GetCell(position.Row, position.Col));
     this.SetCursorAtInputPosition();
 }
Exemple #3
0
 public void SetCell(Position position, char value)
 {
     this.grid[position.Row, position.Col] = value;
 }
Exemple #4
0
 public char GetCell(Position position)
 {
     return this.grid[position.Row, position.Col];
 }
Exemple #5
0
 private void ProcessCommand(UserCommand command)
 {
     switch (command)
     {
         case UserCommand.Show:
             this.ProcessShowCommand();
             break;
         case UserCommand.Exit:
             this.ProcessExitCommand();
             break;
         case UserCommand.New:
             this.ProcessNewGame();
             break;
         case UserCommand.Shoot:
             this.shotPosition = this.userInterface.GetShotPositionFromInput();
             this.ProcessShootCommand();
             break;
         case UserCommand.Invalid:
         default:
             throw new InvalidOperationException(GlobalConstants.InvalidCommandMsg);
     }
 }
Exemple #6
0
        private bool IsShipHit(IShip ship, Position position)
        {
            var row = ship.TopLeft.Row;
            var col = ship.TopLeft.Col;

            for (int j = 0; j < ship.Size; j++)
            {
                if (position.Row == row && position.Col == col)
                {
                    return true;
                }

                if (ship.Direction == ShipDirection.Horizontal)
                {
                    col++;
                }
                else
                {
                    row++;
                }
            }

            return false;
        }
Exemple #7
0
 public Destroyer(ShipDirection direction, Position topLeft)
     : base(GlobalConstants.DestroyerSize, direction, GlobalConstants.DestroyerSymbol, topLeft)
 {
 }
Exemple #8
0
 public Ship(int size, ShipDirection direction, char shipSymbol, Position topLeft)
     : this(size, direction, shipSymbol)
 {
     this.TopLeft = topLeft;
 }