Пример #1
0
 public static SaverSingleton GetInstance(int c)
 {
     if (instance == null)
     {
         instance = new SaverSingleton(c);
     }
     return(instance);
 }
Пример #2
0
        static void Use(AbstractHero h1, AbstractHero h2)
        {
            SaverSingleton saverSingleton;

            saverSingleton = SaverSingleton.GetInstance(1);

            int choice1, choice2;

            Console.WriteLine("Select action for first hero: ");
            Console.WriteLine("Hit: 1");
            Console.WriteLine("Magic: 2");
            Console.WriteLine("Special skill: 3");
            choice1 = int.Parse(Console.ReadLine());

            Console.WriteLine("Select action for second hero: ");
            Console.WriteLine("Hit: 1");
            Console.WriteLine("Magic: 2");
            Console.WriteLine("Special skill: 3");
            choice2 = int.Parse(Console.ReadLine());

            try
            {
                switch (choice1)
                {
                case 1:
                    h1.Hit.UseHit(h2);
                    break;

                case 2:
                    h1.Magic.UseMagic(h2);
                    if (h1.Magic is MagicType1)
                    {
                        return;
                    }
                    break;

                case 3:
                    h1.SpecialSkill.UsePsecialSkill();
                    if (h1.SpecialSkill is SpecialSkillType1)
                    {
                        return;
                    }
                    h1.Hit.UseHit(h2);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.Clear();
                Console.WriteLine(ex.Message);
                Console.WriteLine("Second hero win");
                Console.ReadKey();
                saverSingleton.SaveLog("Second win");
                Environment.Exit(0);
            }


            try
            {
                switch (choice2)
                {
                case 1:
                    h2.Hit.UseHit(h1);
                    break;

                case 2:
                    h2.Magic.UseMagic(h1);
                    if (h2.Magic is MagicType1)
                    {
                        return;
                    }
                    break;

                case 3:
                    h2.SpecialSkill.UsePsecialSkill();
                    if (h2.SpecialSkill is SpecialSkillType1)
                    {
                        return;
                    }
                    h2.Hit.UseHit(h1);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.Clear();
                Console.WriteLine(ex.Message);
                Console.WriteLine("First hero win");
                Console.ReadKey();
                saverSingleton.SaveLog("First win");
                Environment.Exit(0);
            }
        }