Esempio n. 1
0
        static void Main(string[] args)
        {
            IWeaponBehavior axeBehavior   = new AxeBehavior();
            IWeaponBehavior bowBehavior   = new BowAndArrowBehavior();
            IWeaponBehavior knifeBehavior = new KnifeBehavior();
            IWeaponBehavior swordBehavior = new SwordBehavior();

            Character kingCharacter = new King(swordBehavior);

            kingCharacter.Fight();
            kingCharacter.SetWeapon(knifeBehavior);
            kingCharacter.Fight();

            Character queenCharacter = new Queen(knifeBehavior);

            queenCharacter.Fight();

            Character knightCharacter = new Knight(swordBehavior);

            knightCharacter.Fight();

            Character trollCharacter = new Troll(axeBehavior);

            trollCharacter.Fight();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Game");

            Character character = new King();

            character.SetWeapon(new Knife());
            character.Fight();
            character.SetWeapon(new BowAndArrow());
            character.Fight();

            Console.WriteLine("\nDuck");

            Duck mallard = new MallardDuck();

            mallard.PerformFly();
            mallard.PerformQuack();

            Duck model = new ModelDuck();

            model.PerformFly();
            model.SetFlyBehavior(new FlyRocketPowered());
            model.PerformFly();

            Console.ReadKey();
        }
Esempio n. 3
0
        public void TestKingWeapon()

        {
            HeadFirstDesignPatterns.Strategy.Character.King KingWeapon = new King();

            Assert.AreEqual("I swing at thee with this sword!", KingWeapon.Fight());
        }
Esempio n. 4
0
        public void WhenCharacterIsAKingDefaultWeaponIsASword()
        {
            var king = new King();

            var weapon = king.Fight();

            Assert.AreEqual("I'm using a Sword", weapon);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Character james = new King();
            Character mary  = new Queen();

            james.Fight();
            james.PerformUseWeapon();
            mary.Fight();
            mary.PerformUseWeapon();
            //mary needs a better weapon
            mary.Weapon = new AxeBehavior();
            mary.PerformUseWeapon();

            Console.ReadLine();
        }