Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Brackeys Classes Challenge result

using System;


namespace New_Project
{
    class Wizard
    {
        public string name;
        public string favoriteSpell;
        public float health;
        public int fightHealth;
        public float golemHeath = 50f;


        public Wizard(string _name, string _favoriteSpell)
        {
            name = _name;
            favoriteSpell = _favoriteSpell;
            health = 100f;
        }


        public void fightGolem(string favSpell)
        {
            Random numGen = new Random();


            Console.WriteLine("You strike a serious blow to the golem with " + favSpell + "!\n");


            golemHeath -= numGen.Next(0, 100);


            if(golemHeath <= 20)
            {
                Console.WriteLine("The golem is crumbling!\n");
                fightHealth = Convert.ToInt32(health) - numGen.Next(0, 80);
            } else {
                Console.WriteLine("Your attack was too weak so the golem has eaten you!\n");
                fightHealth = 0;
            }
        }
    }


    class Program
    {
        static void Main(string[] args)
        { 
            string[] spells = 
            {
                " ",
                "Fire Whirl",
                "Ice Freeze",
                "Poison Wall"
            };


            Console.Write("Enter a Wizard name: ");


            string name = Console.ReadLine();


            Console.Write("\nChoices of spell:\n1. Fire Whirl\n2. Ice Freeze\n3. Poison Rush\nPlace number corresponding to spell here:");


            int spellNumber = Convert.ToInt32(Console.ReadLine());


            Wizard yourWizard = new Wizard(name, spells[spellNumber]);


            Console.WriteLine("\n-----------------\n\n"+ "Oh no! There is a Golem in front of you! Press Enter to attack him quickly!!\n");
            Console.ReadKey();


            yourWizard.fightGolem(spells[spellNumber]);


            if(yourWizard.fightHealth < 20)
            {
                Console.WriteLine("\n" + yourWizard.name + " has suffered a terrible defeat. :(");
            } else {
                Console.WriteLine("\n" + yourWizard.name + " has won the battle with " + yourWizard.fightHealth + " helth left!");
            }


            // Wait before closing. 
            Console.ReadKey();
        }
    }
}


Sign In or Register to comment.