コード例 #1
0
        public void TestGridDraw()
        {
            spaceGrid     testGrid = new spaceGrid();
            AssembledShip testShip = new AssembledShip(new Frigate(), 5, 5);

            SpaceshipGame.SpaceGame.Grid.GridDraw.DrawShipGrid(testGrid);
        }
コード例 #2
0
        public Player()
        {
            Console.WriteLine("Enter player name:");
            PlayerName = Console.ReadLine();

            Console.WriteLine("----SHIP ASSEMBLY----");
            PlayerShips.Add(AssembledShip.AssembleMenu());
        }
コード例 #3
0
        public CPU(String CPUname, List <AssembledShip> CPUships)
        {
            Console.WriteLine("Enter player name:");
            CPUName = Console.ReadLine();

            Console.WriteLine("----SHIP ASSEMBLY----");
            CPUships.Add(AssembledShip.AssembleMenu());
        }
コード例 #4
0
        public void TestShipPlacement()
        {
            spaceGrid     testGrid2 = new spaceGrid();
            AssembledShip testShip  = new AssembledShip(new Frigate(), 5, 5);

            testGrid2.AddShip(testShip, 5, 5);

            Assert.IsTrue(testGrid2.isObstaclePresent(5, 5) == 1);
        }
コード例 #5
0
        public void TestShipMovement()
        {
            spaceGrid     testGrid = new spaceGrid();
            AssembledShip testShip = new AssembledShip(new Frigate(), 5, 5);

            testGrid.AddShip(testShip, 5, 5);

            Assert.IsTrue(testGrid.isObstaclePresent(5, 5) == 1);

            spaceGrid.MoveShip(testShip, 4, 4, testGrid);
            Assert.IsTrue(testGrid.isObstaclePresent(5, 5) == 0);
            Assert.IsTrue(testGrid.isObstaclePresent(4, 4) == 1);
        }
コード例 #6
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);
                }
            }
        }
コード例 #7
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);
                }
            }
        }
コード例 #8
0
        private void PlayerMoveShip(AssembledShip currentShip)
        {
            Console.WriteLine($"You selected 'MOVE'. Moving {0}\n", currentShip);
            Console.WriteLine("Enter destination Column:");

            string responseColString = Console.ReadLine();
            int    responseCol       = Int32.Parse(responseColString);



            Console.WriteLine("Enter destination Row:");

            string responseRowString = Console.ReadLine();
            int    responseRow       = Int32.Parse(responseRowString);


            Console.WriteLine($"Moving to Column {responseCol}, Row: {responseRow}");

            spaceGrid.MoveShip(currentShip, responseRow, responseRow, grid);

            Console.WriteLine($"Moved to Column {responseCol}, Row: {responseRow}");

            return;
        }
コード例 #9
0
 public void PerformCombat(AssembledShip ship1, AssembledShip ship2)
 {
 }
コード例 #10
0
 public void PerformEncounter(AssembledShip ship1, AssembledShip ship2)
 {
 }
コード例 #11
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;
            }
        }