Exemplo n.º 1
0
        private static void SingletonExample()
        {
            Highlander john = Highlander.GetInstance();
            Highlander rick = Highlander.GetInstance();

            Console.WriteLine($"john is equal to rick? {ReferenceEquals(john, rick)}");
        }
Exemplo n.º 2
0
        public void ArmoredSwordsmanVsHighlander()
        {
            Highlander highlander = new Highlander();

            Swordsman swordsman = new Swordsman()
                                  .Equip("buckler")
                                  .Equip("armor");

            swordsman.Engage(highlander);

            Assert.AreEqual(0, swordsman.HitPoints());
            Assert.AreEqual(10, highlander.HitPoints());
        }
Exemplo n.º 3
0
        public void ViciousSwordsmanVsVeteranHighlander()
        {
            Swordsman swordsman = new Swordsman("Vicious")
                                  .Equip("axe")
                                  .Equip("buckler")
                                  .Equip("armor");

            Highlander highlander = new Highlander("Veteran");

            swordsman.Engage(highlander);

            Assert.AreEqual(1, swordsman.HitPoints());
            Assert.AreEqual(0, highlander.HitPoints());
        }
Exemplo n.º 4
0
 public static Highlander GetInstance()
 {
     return(_highlander ?? (_highlander = new Highlander()));
 }