Exemple #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!");
     }
 }
        public void CreateBattleShip()
        {
            Battleship battleship = new Battleship();

            battleship.shipName = "BattleShip";
            battleship.shipSize = 4;
            battleship.isHit    = false;
            battleship.isSunk   = false;
        }
 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>();
 }
Exemple #4
0
        static void Main(string[] args)
        {
            var battleship         = new Battleship();
            var gameMessageService = new GameMessageService();
            var gameLogic          = new GameLogic();

            gameMessageService.DisplayWelcomeMessage();

            for (int i = 1; i < 9; i++)
            {
                gameMessageService.DisplayRoundNumber(i);
                gameLogic.roundNumber = i;
                var row    = gameMessageService.ReadPlayerRowInput();
                var column = gameMessageService.ReadPlayerColumnInput();

                if (gameLogic.IsGameOverDueToDepletedMissiles())
                {
                    gameMessageService.DisplayGameOverMessage();
                }

                var battleShipIsHit = battleship.ShootMissile(row, column);

                if (battleShipIsHit == true)
                {
                    gameMessageService.DisplayMissileHitMessage(5 - battleship.Hits);
                    battleship.ResetPosition();
                }
                else
                {
                    gameMessageService.DisplayMissedMissileMessage();
                }
                if (battleship.IsSunk() == true)
                {
                    gameMessageService.DisplayWinnerMessage();
                }
            }
        }
Exemple #5
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();
        }
        public void Setup()
        {
            var gameGrid = new BattleShip.Battleship();

            _gameLogic = new GameLogic();
        }
Exemple #7
0
 public void Setup()
 {
     _battleship = new BattleShip.Battleship();
 }