Example #1
0
 static void GetMoreHeroData(ISuperHero superHero)
 {
     if (superHero is SuperMan)
     {
         SuperMan trueHero = superHero as SuperMan;
         Console.WriteLine("\n" + trueHero.ToString());
     }
     else if (superHero is SpiderMan)
     {
         SpiderMan trueHero = superHero as SpiderMan;
         Console.WriteLine("\n" + trueHero.ToString());
     }
     else if (superHero is Flash)
     {
         Flash trueHero = superHero as Flash;
         Console.WriteLine("\n" + trueHero.ToString());
     }
 }
Example #2
0
        static void Main(string[] args)
        {
            //Create 3 super heroes
            ISuperHero[] superHeroes = new ISuperHero[3];

            superHeroes[0] = new SuperMan("Clark", 32, true);
            superHeroes[1] = new SpiderMan("Peter", 16, 20.19f);
            superHeroes[2] = new Flash("Berry", 23, 12767.62f);

            Console.WriteLine("\n//// Activate powers ////\n");

            foreach (var hero in superHeroes)
            {
                ActivateHero(hero);
            }

            Console.WriteLine("\n//// Identify Heroes ////\n");

            foreach (var hero in superHeroes)
            {
                IdentifyHero(hero);
            }

            Console.WriteLine("\n//// Get More Hero Data ////\n");

            foreach (var hero in superHeroes)
            {
                GetMoreHeroData(hero);
            }

            //create heroes
            var newHero1 = CreateHero("spiderman", "tomi", 31, true);

            var newHero2 = CreateHero("spiderman", "tomi", 31, 8383.99f);

            var newHero3 = CreateHero("superman", "sam", 22, 3939f);

            var newHero4 = CreateHero("superman", "sam", 22, true);

            var newHero5 = CreateHero("flash", "john", 53, true);

            var newHero6 = CreateHero("flash", "john", 53, 4848.20f);
        }