Esempio n. 1
0
        public void EnemyShipTesting()
        {
            EnemyShip        theEnemy         = null;
            EnemyShipFactory enemyShipFactory = new EnemyShipFactory();
            int    flag      = 0;
            string userInput = "";

            do
            {
                if ((userInput == "R") || (userInput == "U") || (userInput == "B"))
                {
                    break;
                }
                Console.WriteLine("What type of ship? (R/U)");
                try
                {
                    userInput = Console.ReadLine();
                    flag      = 0;
                }
                catch (FormatException e)
                {
                    Console.WriteLine(e.Message);
                    flag = 1;
                }
                catch (OverflowException e)
                {
                    flag = 1;
                    Console.WriteLine(e.Message);
                }
            } while ((flag == 1) || (userInput != "R") || (userInput != "U") || (userInput != "B"));

            theEnemy = enemyShipFactory.makeEnemyShip(userInput);
            if (theEnemy != null)
            {
                doStuffEnemy(theEnemy);
            }
        }
        public ActionResult Index()
        {
            #region Singleton
            Singleton.getInstance().userID   = "180001";
            Singleton.getInstance().userPwd  = "Pwd18001";
            Singleton.getInstance().userName = "******";
            string userID   = Singleton.getInstance().userID;
            string userPwd  = Singleton.getInstance().userPwd;
            string userName = Singleton.getInstance().userName;
            #endregion

            #region Facade
            BankAccountFacade accessingBank = new BankAccountFacade(12345678, 1234);
            string            ResultFacade  = string.Empty;

            ResultFacade += accessingBank.withdrawCash(50.00);

            ResultFacade += accessingBank.withdrawCash(900.00);

            ResultFacade += accessingBank.depositCash(200.00);
            #endregion

            #region Factory Method

            EnemyShipFactory shipFactory = new EnemyShipFactory();
            EnemyShip        theEnemy    = null;
            theEnemy = shipFactory.makeEnemyShip("B");
            string resultFac = doStuffEnemy(theEnemy);


            #endregion

            #region Abstract Factory

            string resultAbstractFac = AbstractFactory.MainFn();

            #endregion

            #region Builder

            RobotBuilder  oldStyleRobot = new OldRobotBuilder();
            RobotEngineer robotEngineer = new RobotEngineer(oldStyleRobot);
            robotEngineer.makeRobot();
            Robot  firstRobot    = robotEngineer.getRobot();
            string resultBuilder = string.Empty;
            resultBuilder += firstRobot.getRobotHead() + "\n";
            resultBuilder += firstRobot.getRobotTorso() + "\n";
            resultBuilder += firstRobot.getRobotArms() + "\n";
            resultBuilder += firstRobot.getRobotLegs() + "\n";

            RobotBuilder  newStyleRobot    = new NewRobotBuilder();
            RobotEngineer robotEngineerNew = new RobotEngineer(newStyleRobot);
            robotEngineerNew.makeRobot();
            Robot  secondRobot      = robotEngineerNew.getRobot();
            string resultBuilderNew = string.Empty;
            resultBuilderNew += secondRobot.getRobotHead() + "\n";
            resultBuilderNew += secondRobot.getRobotTorso() + "\n";
            resultBuilderNew += secondRobot.getRobotArms() + "\n";
            resultBuilderNew += secondRobot.getRobotLegs() + "\n";
            #endregion

            #region State

            #endregion



            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application. <br />User ID : "
                              + userID + " <br />User Pwd : " + userPwd + " <br />User Name : " + userName;

            return(View());
        }