Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // this program will load by creating 3 players
            Player p1 = new Player1();
            Player p2 = new Player2();
            Player p3 = new Player3();

            // display the players then make them walk and run
            p1.diplay();
            p2.diplay();
            p3.diplay();

            p1.walk();
            p2.walk();
            p3.walk();

            p1.run();
            p2.run();
            p3.run();

            // in case of facing danger the players will select thier default defence behavior then default attack behavior
            Console.Write(" Player 1 say ");            p1.doDefence();
            Console.Write(" Player 2 say ");            p2.doDefence();
            Console.Write(" Player 3 say ");            p3.doDefence();


            Console.Write(" Player 1 say ");            p1.doAttack();
            Console.Write(" Player 2 say ");            p2.doAttack();
            Console.Write(" Player 3 say ");            p3.doAttack();



            Console.WriteLine("=================== Change player shield ===============");
            // the players will change thier defence behavior and attack behavior
            p1.defenceBehavior = new DefenceWithIronShield();
            p2.defenceBehavior = new DefenceWithWoodShield();
            p3.defenceBehavior = new DefenceWithIronShield();

            Console.Write(" Player 1 say ");            p1.doDefence();
            Console.Write(" Player 2 say ");            p2.doDefence();
            Console.Write(" Player 3 say ");            p3.doDefence();


            Console.WriteLine("=================== Change player weapon ===============");

            p1.attackBehavior = new AttackWithGun();
            p2.attackBehavior = new AttackWithGun();
            p3.attackBehavior = new AttackWithGun();

            Console.Write(" Player 1 say ");            p1.doAttack();
            Console.Write(" Player 2 say ");            p2.doAttack();
            Console.Write(" Player 3 say ");            p3.doAttack();



            Console.ReadLine();
        }