public EnemyShip MakeEnemyShip(EnemyShipEnum shipType)
    {
        EnemyShip shipChosen = null;

        switch (shipType)
        {
        case EnemyShipEnum.UFOEnemyShip:
            shipChosen = new UFOEnemyShip();
            break;

        case EnemyShipEnum.RocketEnemyShip:
            shipChosen = new RocketEnemyShip();
            break;

        case EnemyShipEnum.BigUFOEnemyShip:
            shipChosen = new BigUFOEnemyShip();
            break;

        default:
            shipChosen = null;
            break;
        }

        return(shipChosen);
    }
        public static void Main(String[] args)
        {
            EnemyShip theEnemy = null;
            // Old way of creating objects
            // When we use new we are not being dynamic
            EnemyShip ufoShip = new UFOEnemyShip();

            DoStuffEnemy(ufoShip);
            Console.WriteLine("\n");
            // -----------------------------------------
            // This allows me to make the program more dynamic
            // It doesn't close the code from being modified
            // and that is bad!
            // Defines an input stream to watch: keyboard

            Console.WriteLine("What type of ship? (U or R)");
            var enemyShipOption = Console.ReadLine();

            switch (enemyShipOption.ToLower())
            {
            case "u":
                theEnemy = new UFOEnemyShip();
                break;

            case "r":
                theEnemy = new RocketEnemyShip();
                break;

            default:
                theEnemy = new BigUFOEnemyShip();
                break;
            }
            DoStuffEnemy(theEnemy);
            Console.ReadKey();
        }
        public EnemyShip makeEnemyShip(string typeofShip)
        {
            EnemyShip newShip = null;

            if (typeofShip == "U")
            {
                newShip = new UFOEnmeyShip();
            }
            else if (typeofShip == "B")
            {
                newShip = new BigUFOEnemyShip();
            }
            else
            {
                newShip = new RocketEnemyShip();
            }
            return(newShip);
        }
Пример #4
0
        public EnemyShip MakeEnemyShip(string newShipType)
        {
            EnemyShip newShip = null;

            if (newShipType.Equals("U"))
            {
                newShip = new UFOEnemyShip();
            }
            else if (newShipType.Equals("R"))
            {
                newShip = new RocketEnemyShip();
            }
            else if (newShipType.Equals("B"))
            {
                newShip = new BigUFOEnemyShip();
            }

            return(newShip);
        }
        public EnemyShip makeEnemyShip(string newShipType)
        {
            EnemyShip newShip = null;

            switch (newShipType)
            {
            case "U":
                newShip = new UFOEnemyShip();
                break;

            case "R":
                newShip = new RocketEnemyShip();
                break;

            case "B":
                newShip = new BigUFOEnemyShip();
                break;

            default:
                break;
            }

            return(newShip);
        }