// change to Main to run.
        public static void Main(string[] args)
        {
            Game3  game    = new Game3();
            Goblin goblin  = new Goblin(game);
            Goblin goblin2 = new Goblin(game);
            Goblin goblin3 = new Goblin(game);

            Game3.Creatures.Add(goblin);
            Game3.Creatures.Add(goblin2);
            Game3.Creatures.Add(goblin3);

            GoblinKing gk = new GoblinKing(game);

            //GoblinKing gk2 = new GoblinKing(game);
            //GoblinKing gk3 = new GoblinKing(game);

            Game3.Creatures.Add(gk);
            //Game3.Creatures.Add(gk2);
            //Game3.Creatures.Add(gk3);

            Game3.CreatureUpdate(); // goblin 2/4 3 goblin 1/1 + 0/2 buff + 1/0 for king
            game.PrintGame();
            Game3.Creatures.Remove(gk);
            Game3.CreatureUpdate();          // king leaves -1 attack to all
            Game3.Creatures.Remove(goblin3); // 1 goblin leaves -1 defense to remaining goblins.
            Game3.CreatureUpdate();

            game.PrintGame();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            /*
             * This implementation of chain of responsibility demonstrates the
             * method chaining approach. This approach is the most basic form in which
             * you apply various modifiers and responsibilities to the original object's
             * operations.
             */
            var ba = new BankAccount("John Doe", 1000M);
            var t  = new Transaction(ba);

            t.AddTransaction(new SafeWithdrawTransaction(ba, 750));
            t.AddTransaction(new SafeWithdrawTransaction(ba, 500));
            t.AddTransaction(new SafeDepositTransaction(ba, 300));
            t.AddTransaction(new SafeWithdrawTransaction(ba, 250));
            t.Handle();

            /*
             * Below exercise demonstrates the chain of responsibility pattern
             * with a Mediator pattern approach. This can be called broker chain
             * instead of method chain since there is a broker in between the calls
             * and we avoid mutating the original object's properties.
             */

            var carGame = new CarGame();
            var car     = new Car(carGame);

            WriteLine(car);
            using (new DoubleSpeedModifier(carGame, car))
            {
                WriteLine(car);
            }
            WriteLine(car);

            /*
             * Below is the course exercise in which we simulate a card game.
             * Goblins have default A/D points 1/1 and GoblinKing has 3/3.
             * A Goblin gets +1 defense point for every other Goblin on the board (king is a goblin)
             * All Goblins get +1 attack point when a GoblinKing is on the board.
             */

            var game = new Game();
            var c1   = new Goblin(game);
            var c2   = new Goblin(game);
            var c3   = new Goblin(game);
            var king = new GoblinKing(game);

            game.Creatures.Add(c1);
            game.Creatures.Add(c2);
            game.Creatures.Add(c3);
            game.Creatures.Add(king);

            WriteLine(c1);
            WriteLine(c2);
            WriteLine(c3);
            WriteLine(king);
        }
Exemplo n.º 3
0
        public void GoblinKing_HasDefense_3()
        {
            // Arrange
            var king = new GoblinKing(game);

            // Act
            var actual = king.Defense;

            // Assert
            Assert.AreEqual(3, actual);
        }
Exemplo n.º 4
0
        public void GoblinKing_HasAttack_3()
        {
            // Arrange
            var king = new GoblinKing(game);

            // Act
            var actual = king.Attack;

            // Assert
            Assert.AreEqual(3, actual);
        }
Exemplo n.º 5
0
        public void WhenThereAreOneGoblinAndKingInGame_SimpleGoblinDefense_EqualsNumberOfGoblins()
        {
            // Arrange
            var goblin = new Goblin(game);
            var king   = new GoblinKing(game);

            // Act
            var actual1    = goblin.Defense;
            var actualKing = king.Defense;

            // Assert
            Assert.AreEqual(2, actual1);
            Assert.AreEqual(3, actualKing);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var game   = new Game();
            var goblin = new Goblin(game);

            game.Creatures.Add(goblin);

            var goblinKing = new GoblinKing(game);

            game.Creatures.Add(goblinKing);

            var goblin2 = new Goblin(game);

            game.Creatures.Add(goblin2);

            Console.WriteLine(game);
            Console.ReadKey();
        }
Exemplo n.º 7
0
        public void WhenThereAreSeveralGoblinsInGame_SimpleGoblinDefense_EqualsNumberOfGoblins()
        {
            // Arrange
            var goblin1 = new Goblin(game);
            var goblin2 = new Goblin(game);
            var goblin3 = new Goblin(game);
            var king    = new GoblinKing(game);

            // Act
            var actual1    = goblin1.Defense;
            var actual2    = goblin2.Defense;
            var actual3    = goblin3.Defense;
            var actualKing = king.Defense;

            // Assert
            Assert.AreEqual(4, actual1);
            Assert.AreEqual(4, actual2);
            Assert.AreEqual(4, actual3);
            Assert.AreEqual(4, actualKing);
        }
Exemplo n.º 8
0
        public void When_GoblinKingIsInGame_SimpleGoblinHasAttack_2()
        {
            // Arrange
            var goblin1 = new Goblin(game);
            var goblin2 = new Goblin(game);
            var goblin3 = new Goblin(game);
            var king    = new GoblinKing(game);

            // Act
            var actual1    = goblin1.Attack;
            var actual2    = goblin2.Attack;
            var actual3    = goblin3.Attack;
            var actualKing = king.Attack;

            // Assert
            Assert.AreEqual(2, actual1);
            Assert.AreEqual(2, actual2);
            Assert.AreEqual(2, actual3);
            Assert.AreEqual(3, actualKing);
        }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            var game   = new Game();
            var goblin = new Goblin(game);

            game.Creatures.Add(goblin);

            System.Console.WriteLine(goblin.Attack);
            System.Console.WriteLine(goblin.Defense);

            var goblin2 = new Goblin(game);

            game.Creatures.Add(goblin2);

            System.Console.WriteLine(goblin2.Attack);
            System.Console.WriteLine(goblin2.Defense);

            var goblin3 = new GoblinKing(game);

            game.Creatures.Add(goblin3);

            System.Console.WriteLine(goblin.Attack);
            System.Console.WriteLine(goblin.Defense);
        }
Exemplo n.º 10
0
        public void ManyGoblinsTest()
        {
            var game   = new Game();
            var goblin = new Goblin(game);

            game.Creatures.Add(goblin);

            Assert.That(goblin.Attack, Is.EqualTo(1));
            Assert.That(goblin.Defense, Is.EqualTo(1));

            var goblin2 = new Goblin(game);

            game.Creatures.Add(goblin2);

            Assert.That(goblin.Attack, Is.EqualTo(1));
            Assert.That(goblin.Defense, Is.EqualTo(2));

            var goblin3 = new GoblinKing(game);

            game.Creatures.Add(goblin3);

            Assert.That(goblin.Attack, Is.EqualTo(2));
            Assert.That(goblin.Defense, Is.EqualTo(3));
        }