コード例 #1
0
        public static void Main(string[] args)
        {
            // Create the factory object
            var shipFactory = new EnemyShipFactory();
            // Enemy ship object

            EnemyShip theEnemy = null;

            Console.WriteLine("What type of ship? (U / R / B)");
            var userInput = Console.ReadLine().ToLower();

            if (!(userInput == "u" | userInput == "r" | userInput == "b"))
            {
                return;
            }
            var typeOfShip = userInput;

            theEnemy = shipFactory.MakeEnemyShip(typeOfShip);
            if (theEnemy != null)
            {
                DoStuffEnemy(theEnemy);
            }
            else
            {
                Console.Write("Please enter U, R, or B next time");
            }
            Console.ReadKey();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Which ship do you want to instantiate?");
            EnemyShipFactory shipFactory = new EnemyShipFactory();
            var response  = Console.ReadLine();
            var enemyShip = shipFactory.MakeEnemyShip(response.ToString());

            DoStuffEnemy(enemyShip);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: rytisder/DesignPatternsGOF
        static void Main(string[] args)
        {
            EnemyShipFactory factory = new EnemyShipFactory();

            Enemy terran = factory.MakeEnemyShip("TERRAN");
            Enemy ufo    = factory.MakeEnemyShip("UFO");

            Console.WriteLine(terran.Name);
            Console.WriteLine(terran.Dmg);

            Console.WriteLine("-/-/-/-/-/-");

            Console.WriteLine(ufo.Name);
            Console.WriteLine(ufo.Dmg);
        }