public Board CreateBoard(int rows, int columns) { try { //build up the board and set all cells to unoccupied BoardCellStatus[,] statusArray = new BoardCellStatus[rows, columns]; for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { statusArray[row, column] = BoardCellStatus.Unoccupied; } } //return the board return(new Board { BoardCellStatuses = statusArray, Rows = rows, Columns = columns }); } catch (Exception ex) { throw new Exception($"Error while creating board : {ex.Message}"); } }
public void ShouldReturnCorrectAttackStatus_WhenAttackLaunched( int boardRows, int boardColumns, int placementRow, int placementColumn, int attackRow, int attackColumn, ShipType shipType, BoardCellStatus boardCellStatus) { //arrange //first create a board var boardCreator = new BoardCreator(); var board = boardCreator.CreateBoard(boardRows, boardColumns); //then create a ship var shipCreator = new ShipCreator(); var ship = shipCreator.CreateShip(shipType); //place the ship on the board var shipPlacer = new ShipPlacer(); shipPlacer.AddShipToBoard(ship, board, placementRow, placementColumn); //act //now attack the ship at the given position var attacker = new Attacker(); attacker.Attack(board, attackRow, attackColumn); //assert /*check that the status on the board is hit*/ Assert.True( board.BoardCellStatuses[attackRow, attackColumn] == boardCellStatus ); }
private void OnChangeStatusHandler(object sender, BoardCellStatus status) { Material material = null; _meshRenderer.enabled = status != BoardCellStatus.Empty; switch (status) { case BoardCellStatus.HasFocusFigure: material = _materialFocus; break; case BoardCellStatus.AvailableForMove: material = _materialAvailable; break; } _meshRenderer.material = material; }