コード例 #1
0
        public void CreateShips()
        {
            Submarine  sub = new Submarine();
            Battleship bb  = new Battleship();
            Carrier    cv  = new Carrier();
            Cruiser    cl  = new Cruiser();
            Destroyer  dd  = new Destroyer();

            shipList = new List <Ship>()
            {
                sub, bb, cv, cl, dd
            };
        }
コード例 #2
0
ファイル: GameGrid.cs プロジェクト: nvanmiddendorp/Battleship
        /// <summary>
        /// Creates new instances of the ships and adds them to a list that tracks if they are alive or dead
        /// </summary>
        public void CreateShips()
        {
            _gridShips = new List <Ship>();

            //Loop through each type of ship
            foreach (SHIPS ship in Enum.GetValues(typeof(SHIPS)))
            {
                switch (ship)
                {
                case SHIPS.Carrier:
                    carrier = new Carrier(ship.ToString(), (int)SHIP_SIZES.CarrierSize, new SolidColorBrush(Colors.DarkGreen));
                    _gridShips.Add(carrier);
                    break;

                case SHIPS.Battleship:
                    battleship = new Battleship(ship.ToString(), (int)SHIP_SIZES.BattleshipSize, new SolidColorBrush(Colors.SeaGreen));
                    _gridShips.Add(battleship);
                    break;

                case SHIPS.Cruiser:
                    cruiser = new Cruiser(ship.ToString(), (int)SHIP_SIZES.CruiserSize, new SolidColorBrush(Colors.Cyan));
                    _gridShips.Add(cruiser);
                    break;

                case SHIPS.Submarine:
                    submarine = new Submarine(ship.ToString(), (int)SHIP_SIZES.SubmarineSize, new SolidColorBrush(Colors.Yellow));
                    _gridShips.Add(submarine);
                    break;

                case SHIPS.Destroyer:
                    destroyer = new Destroyer(ship.ToString(), (int)SHIP_SIZES.DestroyerSize, new SolidColorBrush(Colors.Violet));
                    _gridShips.Add(destroyer);
                    break;
                }
            }
        }