コード例 #1
0
ファイル: Battle.cs プロジェクト: Dila91/ConsoleApp3
        public void SimulateFight(character hero, character vilain)
        {
            // They fight
            while (userInput != "Q")
            {
                Console.WriteLine("Fighing has started");
                if (hero.Health > 0 && vilain.Health > 0)
                {
                    Console.WriteLine("Hero gets hit by 1 damage");

                    Round.Count++;

                    Console.WriteLine("If you want to stopp press Q" + " OR  Press any key to continu");
                    userInput = Console.ReadLine();
                }
                else
                {
                    userInput = "Q";
                }
            }
            if (userInput == "Q")
            {
                hero.Health = 0;
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Dila91/ConsoleApp3
        static void Main(string[] args)
        {
            Battle    battle = new Battle();
            character ch     = new character();

            ch.Name = "Hercules";
            ch.CreateHero();
            battle.DisplayStartingInfo();

            while (ch.Health > 0)
            {
                //Create an enemy
                character enemy = new character();
                enemy.CreateEnemy();

                //Let the hero fight him/her/it
                battle.SimulateFight(ch, enemy);

                if (ch.Health < 1)
                {
                    Console.WriteLine("{0} was defeated", ch.Name);
                }
                Console.WriteLine(" {0} fought {1} times", ch.Name, Round.Count);



                //string test = ch.Name;



                Console.ReadKey();
            }
        }