コード例 #1
0
 public void ErrorCheck(Submarine Sub, Destroyer Des, Battleship Bat, AircraftCarrier Air)
 {
     if (Sub.shipError || Des.shipError || Bat.shipError || Air.shipError)
     {
         Console.WriteLine("Ships can't be deployed in the shipyard!");
     }
 }
コード例 #2
0
 public Board(int height, int width)
 {
     this.height          = height;
     this.width           = width;
     this.shotsTaken      = new bool[height, width];
     this.destroyer       = new Destroyer();
     this.submarine       = new Submarine();
     this.battleship      = new Battleship();
     this.aircraftCarrier = new AircraftCarrier();
     this.unplacedShips   = new Ship[] { destroyer, submarine, battleship, aircraftCarrier };
     this.placedShips     = new List <Ship>();
 }
コード例 #3
0
        public void ShipSetup(Player Player, Grid Grid)
        {
            Submarine       Sub = new Submarine();
            Destroyer       Des = new Destroyer();
            Battleship      Bat = new Battleship();
            AircraftCarrier Air = new AircraftCarrier();

            for (int i = 0; i < 4; i++)
            {
                if (i == 0)
                {
                    int[] originCords = new int[2] {
                        1, 1
                    };

                    while (Sub.Authorize() == false)
                    {
                        Console.Clear();
                        Sub.ShipPlace(originCords, Grid);
                        Grid.DisplayGrid();
                        Grid.AssembleYard();
                        Console.WriteLine("-- " + Player.PlayerName + "'s setup phase --");
                        Console.WriteLine("Press Enter to place your ship.");
                        Console.WriteLine("Press the arrow keys to move your ship.");
                        ErrorCheck(Sub, Des, Bat, Air);
                        Sub.ShipMove(originCords, Grid, Console.ReadKey().Key);
                        Sub.Authorize();
                    }
                    Console.Clear();
                    Sub.ShipPlace(originCords, Grid);
                    Grid.DisplayGrid();
                }
                else if (i == 1)
                {
                    int[] originCords = new int[2] {
                        1, 1
                    };

                    while (Des.Authorize() == false)
                    {
                        Console.Clear();
                        Des.ShipPlace(originCords, Grid);
                        Grid.DisplayGrid();
                        Grid.AssembleYard();
                        Console.WriteLine("-- " + Player.PlayerName + "'s setup phase --");
                        Console.WriteLine("Press Enter to place your ship.");
                        Console.WriteLine("Press the arrow keys to move your ship.");
                        ErrorCheck(Sub, Des, Bat, Air);
                        Des.ShipMove(originCords, Grid, Console.ReadKey().Key);
                        Des.Authorize();
                    }
                    Console.Clear();
                    Des.ShipPlace(originCords, Grid);
                    Grid.DisplayGrid();
                }
                else if (i == 2)
                {
                    int[] originCords = new int[2] {
                        1, 1
                    };

                    while (Bat.Authorize() == false)
                    {
                        Console.Clear();
                        Bat.ShipPlace(originCords, Grid);
                        Grid.DisplayGrid();
                        Grid.AssembleYard();
                        Console.WriteLine("-- " + Player.PlayerName + "'s setup phase --");
                        Console.WriteLine("Press Enter to place your ship.");
                        Console.WriteLine("Press the arrow keys to move your ship.");
                        ErrorCheck(Sub, Des, Bat, Air);
                        Bat.ShipMove(originCords, Grid, Console.ReadKey().Key);
                        Bat.Authorize();
                    }
                    Console.Clear();
                    Bat.ShipPlace(originCords, Grid);
                    Grid.DisplayGrid();
                }
                else if (i == 3)
                {
                    int[] originCords = new int[2] {
                        1, 1
                    };

                    while (Air.Authorize() == false)
                    {
                        Console.Clear();
                        Air.ShipPlace(originCords, Grid);
                        Grid.DisplayGrid();
                        Grid.AssembleYard();
                        Console.WriteLine("-- " + Player.PlayerName + "'s setup phase --");
                        Console.WriteLine("Press Enter to place your ship.");
                        Console.WriteLine("Press the arrow keys to move your ship.");
                        ErrorCheck(Sub, Des, Bat, Air);
                        Air.ShipMove(originCords, Grid, Console.ReadKey().Key);
                        Air.Authorize();
                    }
                    Console.Clear();
                    Air.ShipPlace(originCords, Grid);
                    Grid.DisplayGrid();
                }
            }
            Console.Clear();
        }