///isValidMove: Checks if the interrogated row / col is occupied by a ship or asteroid, returns true / false. public static Boolean isValidMove(int row, int col, spaceGrid gameGrid) { int obstacleCheckResult = gameGrid.isObstaclePresent(row, col); if (obstacleCheckResult == 0) { return(true); } else { return(false); } }
//spaceGrid copy constructor public spaceGrid(spaceGrid copyGrid) { this.shipGrid = (AssembledShip[, ])copyGrid.shipGrid.Clone(); this.spacegrid = (bool[, ])copyGrid.spacegrid.Clone(); }
//TODO: Finish implementing this method, make design decisions on how to move a vessel. public static void MoveShip(AssembledShip selectedShip, int destRow, int destCol, spaceGrid gameGrid) { //Null-Check before assigning variables based off the selectedShip and gameGrid if (selectedShip != null && gameGrid != null) { //Determine current position of object (ship). int currentRow = selectedShip.getLocationRow(); int currentCol = selectedShip.getLocationCol(); if (isValidMove(destRow, destCol, gameGrid) == true) { //place selectedShip in desired Col/Row gameGrid.shipGrid[destRow, destCol] = selectedShip; gameGrid.shipGrid[currentRow, currentCol] = null; //set the location on each ship object selectedShip.setLocationCol(destCol); selectedShip.setLocationRow(destRow); } } }