コード例 #1
0
        ///AddShip: adds a ship object at the selected row / col in the ShipGrid.
        //TODO: Check for existing ship or asteroid at row / col.
        public void AddShip(AssembledShip ship, int row, int col)
        {
            if (ship != null)
            {
                if (spacegrid[row, col] == true && (shipGrid[row, col] == null))
                {
                    shipGrid[row, col] = ship;

                    ship.setLocationRow(row);

                    ship.setLocationCol(col);
                }
            }
        }
コード例 #2
0
        //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);
                }
            }
        }
コード例 #3
0
        public void MoveShipDirection(AssembledShip selectedShip, int Direction)
        {
            int shipLocationCol = selectedShip.getLocationCol();
            int shipLocationRow = selectedShip.getLocationRow();


            if (Direction == UP)
            {
                selectedShip.setLocationCol(shipLocationCol);
                selectedShip.setLocationRow(shipLocationRow - 1);
                this.shipGrid[shipLocationRow - 1, shipLocationCol] = selectedShip;
                this.shipGrid[shipLocationRow, shipLocationCol]     = null;
            }

            if (Direction == DOWN)
            {
                selectedShip.setLocationCol(shipLocationCol);
                selectedShip.setLocationRow(shipLocationRow + 1);
                this.shipGrid[shipLocationRow + 1, shipLocationCol] = selectedShip;
                this.shipGrid[shipLocationRow, shipLocationCol]     = null;
            }

            if (Direction == LEFT)
            {
                selectedShip.setLocationCol(shipLocationCol - 1);
                selectedShip.setLocationRow(shipLocationRow);
                this.shipGrid[shipLocationRow, shipLocationCol - 1] = selectedShip;
                this.shipGrid[shipLocationRow, shipLocationCol]     = null;
            }

            if (Direction == RIGHT)
            {
                selectedShip.setLocationCol(shipLocationCol + 1);
                selectedShip.setLocationRow(shipLocationRow);
                this.shipGrid[shipLocationRow, shipLocationCol + 1] = selectedShip;
                this.shipGrid[shipLocationRow, shipLocationCol]     = null;
            }

            if (Direction == UP_AND_LEFT)
            {
                selectedShip.setLocationCol(shipLocationCol - 1);
                selectedShip.setLocationRow(shipLocationRow - 1);
                this.shipGrid[shipLocationRow - 1, shipLocationCol - 1] = selectedShip;
                this.shipGrid[shipLocationRow, shipLocationCol]         = null;
            }

            if (Direction == UP_AND_RIGHT)
            {
                selectedShip.setLocationCol(shipLocationCol + 1);
                selectedShip.setLocationRow(shipLocationRow - 1);
                this.shipGrid[shipLocationRow - 1, shipLocationCol + 1] = selectedShip;
                this.shipGrid[shipLocationRow, shipLocationCol]         = null;
            }

            if (Direction == DOWN_AND_LEFT)
            {
                selectedShip.setLocationCol(shipLocationCol - 1);
                selectedShip.setLocationRow(shipLocationRow + 1);
                this.shipGrid[shipLocationRow + 1, shipLocationCol - 1] = selectedShip;
                this.shipGrid[shipLocationRow, shipLocationCol]         = null;
            }

            if (Direction == DOWN_AND_RIGHT)
            {
                selectedShip.setLocationCol(shipLocationCol + 1);
                selectedShip.setLocationRow(shipLocationRow + 1);
                this.shipGrid[shipLocationRow + 1, shipLocationCol + 1] = selectedShip;
                this.shipGrid[shipLocationRow, shipLocationCol]         = null;
            }

            if (Direction == CENTER)
            {
                //Staying put. No action.
                return;
            }
        }