Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Plan your heist!");
            Console.WriteLine();
            Heister teamMember;

            // List<Heister> heistTeam = new List<Heister>();

            Console.WriteLine("What is the team member's name?");
            string name = Console.ReadLine();

            Console.WriteLine("What is the team member's skill level?");
            string skillLevelString = Console.ReadLine();
            int    skillLevel;

            try
            {
                skillLevel = int.Parse(skillLevelString);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{skillLevelString} is not a valid skill level. Skill level now set to 10.");
                skillLevel = 10;
            }

            Console.WriteLine("What is the team member's courage factor?");
            string  courageFactorString = Console.ReadLine();
            decimal courageFactor;

            try
            {
                courageFactor = decimal.Parse(courageFactorString);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{courageFactorString} is not a valid courage factor. Courage Factor now set to 10.");
                // Console.WriteLine(ex.Message);
                courageFactor = 1.1M;
            }

            teamMember = new Heister()
            {
                Name          = name,
                SkillLevel    = skillLevel,
                CourageFactor = courageFactor
            };

            Console.WriteLine($"Name: {teamMember.Name}");
            Console.WriteLine($"Skill Level: {teamMember.SkillLevel}");
            Console.WriteLine($"Courage Factor: {teamMember.CourageFactor}");
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Crime.Net welcomes you!");

            int trialNumber = -1;
            int wins        = 0;
            int losses      = 0;

            //Bank info
            Random luckValue          = new Random();
            int    bankDifficulty     = 101;
            int    difficultyWithLuck = 0;
            int    teamSkillNumber    = 0;

            List <Heister> heisterList = new List <Heister>();

            Console.WriteLine("Crime.Net welcomes you!");

            while (heisterList.Count < 4)
            {
                string name;
                string skillString;
                string courageString;

                int     skillLevel    = 0;
                decimal courageFactor = 0.0M;

                Console.WriteLine($"Number of heisters: {heisterList.Count}");
                Console.WriteLine("What is your name?");
                name = Console.ReadLine();
                if (name == "")
                {
                    break;
                }
                Console.WriteLine("What is your skill level?");
                skillString = Console.ReadLine();

                try
                {
                    skillLevel = int.Parse(skillString);
                }

                catch (Exception ex)
                {
                    Console.WriteLine($"{skillString} is not a valid skill. Using the default of 10.");
                    skillLevel = 10;
                }

                Console.WriteLine("What is your courage factor?");
                courageString = Console.ReadLine();

                try
                {
                    courageFactor = decimal.Parse(courageString);
                }

                catch (Exception ex)
                {
                    Console.WriteLine($"{courageString} is not a valid courage value. Using the default of 1.0.");
                    courageFactor = 1.0M;
                }

                Heister heister = new Heister(name, skillLevel, courageFactor);
                heisterList.Add(heister);
            }

            while (bankDifficulty > 100 || bankDifficulty < 0)
            {
                Console.WriteLine("How difficult is the bank?");

                try
                {
                    bankDifficulty = int.Parse(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Something went wrong. Try again.");
                }
            }

            while (trialNumber <= 0)
            {
                Console.WriteLine("How many trials will you perform.");

                try
                {
                    trialNumber = int.Parse(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Something went wrong. Try again.");
                }

                if (trialNumber == 0)
                {
                    Console.WriteLine("Please enter a number more than 0.");
                }
            }

            foreach (Heister heister in heisterList)
            {
                teamSkillNumber += heister.GetSkillLevel();
            }

            Console.WriteLine($"The heisters' power is {teamSkillNumber} and the bank's difficulty is {bankDifficulty}");

            for (int i = 0; i < trialNumber; i++)
            {
                difficultyWithLuck = bankDifficulty + luckValue.Next(-10, 10);
                if (teamSkillNumber > difficultyWithLuck)
                {
                    wins++;
                }
                else
                {
                    losses++;
                }
            }

            Console.WriteLine($"You robbed {wins} banks successfully, but you were apprehended {losses} times.");
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Plan your heist!");
            Console.WriteLine();
            Console.WriteLine("Base Difficulty of Bank>");
            int bankDifficulty = int.Parse(Console.ReadLine());

            Console.WriteLine();

            List <Heister> Robbers = new List <Heister>();

            Console.WriteLine("What is the team members name?");
            string name = Console.ReadLine();

            while (name != "")
            {
                Console.WriteLine("What is the team members skill level?");
                string skillLevelString = Console.ReadLine();
                int    skillLevel;

                try
                {
                    skillLevel = int.Parse(skillLevelString);
                }
                catch (Exception)
                {
                    Console.WriteLine($"{skillLevelString} is not a valid skill level. Using a default value of 10");
                    skillLevel = 10;
                }

                Console.WriteLine("Waht is your team members courage factor?");
                string  courageFactorString = Console.ReadLine();
                decimal courageFactor;

                try
                {
                    courageFactor = decimal.Parse(courageFactorString);
                }
                catch (Exception)
                {
                    Console.WriteLine($"{courageFactorString} is not a valid courage factor. Using a default value of 1.0");
                    courageFactor = 1.0M;
                }

                Heister member = new Heister();
                member.Name          = name;
                member.SkillLevel    = skillLevel;
                member.CourageFactor = courageFactor;

                Robbers.Add(member);

                Console.WriteLine();
                Console.WriteLine("New Crew Member");
                name = Console.ReadLine();
            }
            Console.WriteLine($"{Robbers.Count} Crew Member's total!");
            Console.WriteLine();

            Console.WriteLine("How many times would you like to run this?");
            int numberOfRuns = int.Parse(Console.ReadLine());

            Console.WriteLine();

            int teamSkill = 0;

            foreach (Heister member in Robbers)
            {
                teamSkill += member.SkillLevel;
            }

            Report heistReport = new Report();

            for (int i = 0; i < numberOfRuns; i++)
            {
                Random luckGen           = new Random();
                int    luckRating        = luckGen.Next(-10, 11);
                int    officalBankRating = bankDifficulty + luckRating;

                Console.WriteLine();
                Console.WriteLine($"Team Skill> {teamSkill}");
                Console.WriteLine($"Bank Skill> {officalBankRating}");
                Console.WriteLine();

                if (teamSkill >= officalBankRating)
                {
                    Console.WriteLine("Atta Boy!");
                    heistReport.SuccessCount++;
                }
                else
                {
                    Console.WriteLine("Going to jail now Boy!");
                    heistReport.FailureCount++;
                }
            }

            heistReport.ShowReport();

            // Console.WriteLine(" <Crew Members> ");
            // Console.WriteLine();
            // foreach (Heister member in Robbers)
            // {
            //     Console.WriteLine($"{member.Name}");
            //     Console.WriteLine($"Skill Level: {member.SkillLevel}");
            //     Console.WriteLine($"Courage Factor: {member.CourageFactor}");
            //     Console.WriteLine();
            // }

            //First way i did it, but cleaned it up

            // List<int> robbersSkillLevels = new List<int>();
            // foreach (var robber in Robbers)
            // {
            //     robbersSkillLevels.Add(robber.SkillLevel);
            // }

            // int totalRobberSkillLevel = robbersSkillLevels.Sum();
            // Console.WriteLine(totalRobberSkillLevel);
        }