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(); }
public void SetCell(Position position, char value) { this.grid[position.Row, position.Col] = value; }
public char GetCell(Position position) { return this.grid[position.Row, position.Col]; }
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); } }
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; }
public Destroyer(ShipDirection direction, Position topLeft) : base(GlobalConstants.DestroyerSize, direction, GlobalConstants.DestroyerSymbol, topLeft) { }
public Ship(int size, ShipDirection direction, char shipSymbol, Position topLeft) : this(size, direction, shipSymbol) { this.TopLeft = topLeft; }