Ejemplo n.º 1
0
        public Ships()
        {
            //create a new stack to hold ships
            shipsStack = new Stack <Ship>();

            //new instance of a ship
            ship                 = new Ship();
            blankShip            = new Ship();
            blankShip.shipLength = 1;
            blankShip.frontColor = ConsoleColor.White;
            blankShip.backColor  = ConsoleColor.Black;
            blankShip.symbol     = "   ";

            //new instance of each ship
            battleship = new Battleship();
            carrier    = new Carrier();
            cruiser    = new Cruiser();
            destroyer  = new Destroyer();
            submarine  = new Sub();

            //send the ships to the container.
            Add(battleship, carrier, cruiser, destroyer, submarine);
        }
Ejemplo n.º 2
0
        public void Add(Battleship battleship, Carrier carrier, Cruiser cruiser, Destroyer destroyer, Sub submarine)
        {
            //making sure the stack is empty for pushing new ships in
            Clear(shipsStack);

            //making sure the ships have default properties
            battleship.Reset();
            carrier.Reset();
            cruiser.Reset();
            destroyer.Reset();
            submarine.Reset();

            //push the ships into the stack
            shipsStack.Push(battleship);
            shipsStack.Push(carrier);
            shipsStack.Push(cruiser);
            shipsStack.Push(destroyer);
            shipsStack.Push(submarine);
        }