static void Main(string[] args)
        {
            UserInputObserver = new Observer.Observer();
            helloObservable   = new HelloObservable();
            SmileyObservable smileyObservable = new SmileyObservable();

            helloObservable.SetInputStrategy(new FirstHelloStrategy());

            string line = "";

            Console.WriteLine("");
            Console.WriteLine("     __   __     __  ________  _____");
            Console.WriteLine("    /  / /  |  /  / /  _____/ /  _  |");
            Console.WriteLine("   /  / /   | /  / /  /____  /  /_| |");
            Console.WriteLine("  /  / /    |/  / /____   / /  ___  |");
            Console.WriteLine(" /  / /  /|    / _____/  / /  /   | |");
            Console.WriteLine("/__/ /__/ |___/ /_______/ /__/    |_|");
            Console.WriteLine("Desing Patterns - Anthony Maudry [email protected]");
            Console.WriteLine("Hello,");

            UserInputObserver.Register("hello", smileyObservable);
            UserInputObserver.Register("hello", helloObservable);
            do
            {
                if (line != "" && !UserInputObserver.Trigger(line))
                {
                    Console.WriteLine($"You wrote {line}");
                }

                Console.WriteLine($"{UserName}, write something or type 'exit' to exit the program.");
            } while ((line = Console.ReadLine()) != "exit");

            Console.WriteLine("Goodbye.");
        }
示例#2
0
        static void Main(string[] args)
        {
            UserInputObserver = new Observer.Observer();
            SmileyObservable smileyObservable = new SmileyObservable();

            string line = "";

            Console.WriteLine("");
            Console.WriteLine("     __   __     __  ________  _____");
            Console.WriteLine("    /  / /  |  /  / /  _____/ /  _  |");
            Console.WriteLine("   /  / /   | /  / /  /____  /  /_| |");
            Console.WriteLine("  /  / /    |/  / /____   / /  ___  |");
            Console.WriteLine(" /  / /  /|    / _____/  / /  /   | |");
            Console.WriteLine("/__/ /__/ |___/ /_______/ /__/    |_|");
            Console.WriteLine("Desing Patterns - Anthony Maudry [email protected]");
            Console.WriteLine("Hello,");

            UserInputObserver.Register("hi", smileyObservable);

            List <Composite.IMenuItems> MenuItemList = new List <Composite.IMenuItems>();

            MenuItemList.Add(new Composite.Menu());
            MenuItemList.Add(new Composite.TimeAttack());
            MenuItemList.Add(new Composite.Score());
            MenuItemList.Add(new Composite.QuickGame());
            MenuItemList.Add(new Composite.Infinite());
            MenuItemList.Add(new Composite.Goal());
            MenuItemList.Add(new Composite.GameMode());

            foreach (Composite.IMenuItems item in MenuItemList)
            {
                UserInputObserver.Register(item.GetKeyWord(), item);
            }

            do
            {
                if (line != "" && !UserInputObserver.Trigger(line))
                {
                    Console.WriteLine($"You wrote {line}");
                }

                Console.WriteLine($"\n{UserName}, write something or type 'exit' to exit the program.");
            } while ((line = Console.ReadLine()) != "exit");

            Console.WriteLine("Goodbye.");
        }
示例#3
0
        static void Main(string[] args)
        {
            //Définition de l'Observer, des Observables et du contexte
            userObserver = new MonObserver();
            menuObserver = new MonObserver();
            HelloContext     userHelloContext = new HelloContext();
            HelloObservable  hello            = new HelloObservable(userHelloContext);
            SmileyObservable smiley           = new SmileyObservable();
            Node             menu             = generateMenu();

            //Enregistre les observables auprès de l'observer
            userObserver.Register("hello", hello);
            userObserver.Register("Hello", hello);
            userObserver.Register("hello", smiley);
            //userObserver.Unregister("hello", smiley);

            userObserver.Register(menu.GetKeyWord(), menu.GetObservable());

            //Prompt d'accueil
            string line;

            Console.WriteLine("");
            Console.WriteLine("     __   __     __  ________  _____");
            Console.WriteLine("    /  / /  |  /  / /  _____/ /  _  |");
            Console.WriteLine("   /  / /   | /  / /  /____  /  /_| |");
            Console.WriteLine("  /  / /    |/  / /____   / /  ___  |");
            Console.WriteLine(" /  / /  /|    / _____/  / /  /   | |");
            Console.WriteLine("/__/ /__/ |___/ /_______/ /__/    |_|");
            Console.WriteLine("Desing Patterns - Anthony Maudry [email protected]");
            Console.WriteLine("Hello,");
            Console.WriteLine("Write something (type 'exit' to exit the program).");
            Console.WriteLine("Write 'menu' to go to the game menu.");

            //Questrion-réponse avec l'Observer qui réagit aux mots clés définits plus haut
            while ((line = Console.ReadLine()) != "exit")
            {
                if (0 == (userObserver.Trigger(line) + menuObserver.Trigger(line)))
                {
                    Console.WriteLine("You wrote : ");
                    Console.WriteLine(line);
                }
            }

            Console.WriteLine("Goodbye.");
        }