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.");
        }
Example #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.");
        }
Example #3
0
        static void Main(string[] args)
        {
            //définir Observer et observable
            Observer.Observer         obs      = new Observer.Observer();
            Observables.HelloResponse hellorep = new Observables.HelloResponse();
            Observables.Smiley        smiley   = new Observables.Smiley();



            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).");

            obs.Register("hello", smiley);
            obs.Register("hello", hellorep);

            //le déclenchement des évènements va dépendre de l'ordre dans lequel on les enregistre
            // .Register pour enregistrer évènement

            while ((line = Console.ReadLine()) != "exit")
            {
                //on déclenche l'évènement line, pas besoin de le faire si on trigge directement la ligne,
                // car si il y a un évènement, ça se lance, sinon non

                //if (line=="hello")
                //    obs.Trigger("hello");


                obs.Trigger(line);


                Console.WriteLine("You wrote : ");
                Console.WriteLine(line);
            }

            Console.WriteLine("Goodbye.");
        }
Example #4
0
        //On peut faire methode UserSaidHello
        //On peut mettre les obs en static ici

        static void Main(string[] args)
        {
            context = new Context();


            Observer.Observer observer = new Observer.Observer();

            /*
             * helloObservable helloObs = new helloObservable();
             * smileyObservable smileyObs = new smileyObservable();
             *
             * observer.Register("hello", smileyObs);
             * observer.Register("hello", helloObs);
             *
             *
             * int helloCount=0;
             */
            string line;

            NewObserver newObserver = new NewObserver();
            IComposite  tmp;

            //Creation des composites
            Composites.Composite menu     = new Composites.Composite("Menu", "menu", new compObservable());
            Composites.Composite partieR  = new Composites.Composite("Partie Rapide", "jouer", new compObservable());
            Composites.Composite typeP    = new Composites.Composite("Type Partie", "type", new compObservable());
            Composites.Composite chrono   = new Composites.Composite("Chronométrée", "timed", new compObservable());
            Composites.Composite infinie  = new Composites.Composite("Infinie", "endless", new compObservable());
            Composites.Composite objectif = new Composites.Composite("Objectif", "points", new compObservable());
            Composites.Composite score    = new Composites.Composite("Score", "score", new compObservable());

            /*
             * //Fin de l'arbre
             * Composites.Composite  = new Composites.Composite("Score", "score", new compObservable());
             * Composites.Composite score = new Composites.Composite("Score", "score", new compObservable());
             * Composites.Composite score = new Composites.Composite("Score", "score", new compObservable());
             * Composites.Composite score = new Composites.Composite("Score", "score", new compObservable());
             * Composites.Composite score = new Composites.Composite("Score", "score", new compObservable());
             */


            //Construction de l'arbre
            menu.AddSon(partieR);
            menu.AddSon(typeP);
            menu.AddSon(score);

            typeP.AddSon(chrono);
            typeP.AddSon(infinie);
            typeP.AddSon(objectif);

            //Ajout des parents
            partieR.Parent = menu;
            typeP.Parent   = menu;
            score.Parent   = menu;

            chrono.Parent   = typeP;
            infinie.Parent  = typeP;
            objectif.Parent = typeP;

            //Dictionnaires de composites pour MaJ le current composite
            Dictionary <string, IComposite> composites = new Dictionary <string, IComposite>();

            composites.Add(menu.GetKeyWord(), menu);
            composites.Add(partieR.GetKeyWord(), partieR);
            composites.Add(typeP.GetKeyWord(), typeP);
            composites.Add(chrono.GetKeyWord(), chrono);
            composites.Add(infinie.GetKeyWord(), infinie);
            composites.Add(objectif.GetKeyWord(), objectif);
            composites.Add(score.GetKeyWord(), score);


            //Register le menu
            newObserver.Register(menu.GetKeyWord(), menu.GetObservable());

            observer.Register("back", new backObservable());

            context.CurrentComposite = menu;


            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 access Menu");


            while ((line = Console.ReadLine()) != "exit")
            {
                if (line.Equals("back") && !context.CurrentComposite.Equals(menu))
                {
                    observer.Trigger(line);
                    newObserver.BackMenu();
                    tmp = context.CurrentComposite;
                    context.CurrentComposite = tmp.Parent;
                }
                else if (context.CurrentComposite.GetSons().Exists(p => p.GetKeyWord().Equals(line)) || context.CurrentComposite.GetKeyWord().Equals(line))
                {
                    context.CurrentComposite = composites[line];
                    newObserver.Trigger(line);
                }
                else
                {
                    Console.WriteLine("You wrote : ");
                    Console.WriteLine(line);
                }

                /*
                 * if (line.Equals("hello"))
                 * {
                 *  helloCount++;
                 *
                 *  switch (helloCount) {
                 *      case 1:
                 *          helloObs.InputStrat = new FirstStrategy();
                 *          break;
                 *      case 2:
                 *          helloObs.InputStrat = new SecondStrategy();
                 *          break;
                 *      case 6:
                 *          helloObs.InputStrat = new ThirdStrategy();
                 *          break;
                 *      default:
                 *          break;
                 *  }
                 * }
                 *
                 * if (!observer.Trigger(line))
                 * {
                 *  Console.WriteLine("You wrote : ");
                 *  Console.WriteLine(line);
                 * }
                 */
            }

            Console.WriteLine("Goodbye.");
        }