Exemple #1
0
        static void Main(string[] args)
        {
            var rolodex = new List <IRobber>();

            var Holden = new Hacker()
            {
                Name          = "Holden",
                SkillLevel    = 80,
                PercentageCut = 40
            };
            var William = new Hacker()
            {
                Name          = "William",
                SkillLevel    = 65,
                PercentageCut = 33
            };

            var Audrey = new Muscle()
            {
                Name          = "Audrey",
                SkillLevel    = 70,
                PercentageCut = 40
            };
            var Namita = new Muscle()
            {
                Name          = "Namita",
                SkillLevel    = 65,
                PercentageCut = 20
            };

            var Kevin = new LockSpecialist()
            {
                Name          = "Kevin",
                SkillLevel    = 70,
                PercentageCut = 25
            };
            var Taylor = new LockSpecialist()
            {
                Name          = "Taylor",
                SkillLevel    = 80,
                PercentageCut = 30
            };

            rolodex.Add(Holden);
            rolodex.Add(William);
            rolodex.Add(Audrey);
            rolodex.Add(Namita);
            rolodex.Add(Kevin);
            rolodex.Add(Taylor);

            while (true)
            {
                // Makes the console a bit more user-friendly by adding a break in the terminal
                Console.WriteLine("");

                //Print out how many operatives are in your rolodex
                Console.WriteLine($"There are currently {rolodex.Count} available operatives");

                // Makes the console a bit more user-friendly by adding a break in the terminal
                Console.WriteLine("");

                Console.WriteLine("Enter the name of a new possible crew member or press enter to contine.");
                var newMemberName = Console.ReadLine();
                //break out of while loop if blank name is entered
                if (string.IsNullOrEmpty(newMemberName))
                {
                    break;
                }
                else
                {
                    //Pick new member's specialty
                    Console.WriteLine($"What specialty do you want {newMemberName} to have?");
                    Console.WriteLine("Hacker (Disables alarms)");
                    Console.WriteLine("Muscle (Disarms guards)");
                    Console.WriteLine("Lock Specialist (Cracks vault)");
                    string newMemberSpecialty;
                    while (true)
                    {
                        newMemberSpecialty = Console.ReadLine().ToLower();

                        if (newMemberSpecialty == "hacker" || newMemberSpecialty == "muscle" || newMemberSpecialty == "lock specialist")
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Not a valid entry. Please choose Hacker, Muscle, or Lock Specialist");
                        }
                    }

                    //pick new member's skill level
                    Console.WriteLine($"What is {newMemberName}'s skill level? (1-100)");
                    int newMemberSkillLevel;
                    while (true)
                    {
                        try
                        {
                            newMemberSkillLevel = int.Parse(Console.ReadLine());

                            if (newMemberSkillLevel > 0 && newMemberSkillLevel <= 100)
                            {
                                break;
                            }
                            else
                            {
                                Console.WriteLine("Not a valid entry. Please enter a skill level between 1-100");
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Not a valid entry. Please enter a valid skill level between 1-100");
                        }
                    }

                    //new member's percentage cut
                    Console.WriteLine($"What percentage cut does {newMemberName} want? (1-50)");
                    int newMemberCut;
                    while (true)
                    {
                        try
                        {
                            newMemberCut = int.Parse(Console.ReadLine());

                            if (newMemberCut > 0 && newMemberCut <= 50)
                            {
                                break;
                            }
                            else
                            {
                                Console.WriteLine("Not a valid input, please choose an integer between 1-50");
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Not a valid input, please choose an integer between 1-50");
                        }
                    }

                    //create new instance off of information you entered
                    if (newMemberSpecialty == "hacker")
                    {
                        Hacker hacker = new Hacker()
                        {
                            Name          = $"{newMemberName}",
                            SkillLevel    = newMemberSkillLevel,
                            PercentageCut = newMemberCut
                        };

                        rolodex.Add(hacker);
                    }
                    else if (newMemberSpecialty == "muscle")
                    {
                        Muscle muscle = new Muscle()
                        {
                            Name          = $"{newMemberName}",
                            SkillLevel    = newMemberSkillLevel,
                            PercentageCut = newMemberCut
                        };

                        rolodex.Add(muscle);
                    }
                    else if (newMemberSpecialty == "lock specialist")
                    {
                        LockSpecialist lockSpecialist = new LockSpecialist()
                        {
                            Name          = $"{newMemberName}",
                            SkillLevel    = newMemberSkillLevel,
                            PercentageCut = newMemberCut
                        };

                        rolodex.Add(lockSpecialist);
                    }
                }
            }

            // Randomize variables for bank
            int alarmScore         = new Random().Next(0, 101);
            int vaultScore         = new Random().Next(0, 101);
            int securityGuardScore = new Random().Next(0, 101);
            int cashOnHand         = new Random().Next(50000, 1000001);

            Console.WriteLine($"cashOnHand {cashOnHand}");

            // Create new bank instance and apply randomized variables
            Bank bank = new Bank()
            {
                AlarmScore         = alarmScore,
                VaultScore         = vaultScore,
                SecurityGuardScore = securityGuardScore,
                CashOnHand         = cashOnHand
            };

            // Create dictionary to store randomized scores with corresponding labels
            Dictionary <string, int> scores = new Dictionary <string, int>();

            scores.Add("Alarm", alarmScore);
            scores.Add("Vault", vaultScore);
            scores.Add("Security Guard", securityGuardScore);

            // Order dictionary by ascending score values from lowest to highest
            var ascendingScores = scores.OrderBy(score => score.Value);

            // Store the first KeyValuePair in a variable, being the lowest
            var lowestScore = ascendingScores.First();
            // Store the last KeyValuePair in a variable, being the highest
            var highestScore = ascendingScores.Last();

            Console.WriteLine("-----------------------------------");
            // Console the most secure system
            Console.WriteLine($"Most secure: {highestScore.Key}");
            // Console the least secure system
            Console.WriteLine($"Least secure: {lowestScore.Key}");

            Console.WriteLine("-----------------------------------");

            // Console the index of each robber in your rolodex and their report
            foreach (var robber in rolodex)
            {
                Console.WriteLine($"{rolodex.IndexOf(robber)}: {robber}");
            }

            // Create a new list instance for your crew
            var crew = new List <IRobber>();
            // Set a variable equal to 100 to represent how much percentage of the take is left for new crew members
            int crewCutPercentageLeft = 100;

            while (true)
            {
                try
                {
                    // Makes the console a bit more user-friendly by adding a break in the terminal
                    Console.WriteLine("");

                    Console.WriteLine("Which robber would you like to add to your crew? (Index integer or press enter to continue)");
                    //Check to see if nothing is entered
                    var robberIndexString = Console.ReadLine();
                    if (string.IsNullOrEmpty(robberIndexString))
                    {
                        break;
                    }
                    else
                    {
                        var robberIndex = int.Parse(robberIndexString);

                        if (robberIndex < rolodex.Count || robberIndex >= 0)
                        {
                            //Add member to your crew
                            crew.Add(rolodex[robberIndex]);
                            //Subtract added member's percentage cut from crewCutPercentageLeft
                            crewCutPercentageLeft -= rolodex[robberIndex].PercentageCut;
                            //Remove new crew member from rolodex
                            rolodex.Remove(rolodex[robberIndex]);
                        }
                        else
                        {
                            Console.WriteLine("Please enter a valid index integer");
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("Invalid input. Please enter a valid index integer");
                }
                // Makes the console a bit more user-friendly by adding a break in the terminal
                Console.WriteLine("");
                // Display the securities again for better user experience
                Console.WriteLine("-----------------------------------");
                Console.WriteLine($"Most secure: {highestScore.Key}");
                Console.WriteLine($"Least secure: {lowestScore.Key}");
                Console.WriteLine("-----------------------------------");

                Console.WriteLine("Robbers available to add to your crew:");
                //  Display who's left you're able to add
                foreach (var robber in rolodex)
                {
                    if (crewCutPercentageLeft - robber.PercentageCut >= 0)
                    {
                        Console.WriteLine($"{rolodex.IndexOf(robber)}: {robber}");
                    }
                }
            }

            // Have each crew member in your crew perform their skill on the bank
            foreach (var crewMember in crew)
            {
                crewMember.PerformSkill(bank);
            }

            // Makes the console a bit more user-friendly by adding a break in the terminal
            Console.WriteLine("");

            // Check to see if the bank is still secure after the heist
            if (bank.IsSecure)
            {
                // Failure message:
                Console.WriteLine("Unfortunately everyone's hard work didn't pay off. Don't quit your day jobs!");
            }
            else
            {
                // Success message and report:
                Console.WriteLine($"Success! Your crew managed to get away with ${cashOnHand}!");
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("Everyone gets their piece of the pie:");
                Console.WriteLine("--------------------------------------");
                foreach (var crewMember in crew)
                {
                    // Calculate how much each crew member gets from the heist
                    double cut = (crewMember.PercentageCut * cashOnHand) / 100;
                    Console.WriteLine($"{crewMember.Name} walks away with ${cut}!");
                }
                // Makes the console a bit more user-friendly by adding a break in the terminal
                Console.WriteLine("");
                // Calculate what you walk away with for setting up the heist!
                double leftover = (crewCutPercentageLeft * cashOnHand) / 100;
                Console.WriteLine($"For setting up the heist you get what's leftover and walk away with ${leftover}. Good job!");
            }
        }
        static void Main(string[] args)
        {
            Hacker hacker1 = new Hacker()
            {
                Name          = "Faith",
                SkillLevel    = 25,
                PercentageCut = 40
            };
            Hacker hacker2 = new Hacker()
            {
                Name          = "Adam",
                SkillLevel    = 25,
                PercentageCut = 10
            };

            Muscle muscle1 = new Muscle()
            {
                Name          = "Joe",
                SkillLevel    = 90,
                PercentageCut = 5
            };

            Muscle muscle2 = new Muscle()
            {
                Name          = "Tyler",
                SkillLevel    = 20,
                PercentageCut = 5
            };
            LockSpecialist lockSpecialist1 = new LockSpecialist()
            {
                Name          = "Starkey",
                SkillLevel    = 45,
                PercentageCut = 25
            };
            LockSpecialist lockSpecialist2 = new LockSpecialist()
            {
                Name          = "Erik",
                SkillLevel    = 35,
                PercentageCut = 25
            };



            List <IRobber> rolodex = new List <IRobber>()
            {
                hacker1, hacker2, muscle1, muscle2, lockSpecialist1, lockSpecialist2
            };

            //LoopToken allows while loop to continuously, once changed to false.. loop terminates
            bool LoopToken = true;

            while (LoopToken == true)
            {
                Console.WriteLine($"Current number of operatives {rolodex.Count}");
                Console.WriteLine("------------------------");
                Console.WriteLine("Enter a new team member");
                string NewTeamMember = Console.ReadLine();
                Console.WriteLine("");
                if (NewTeamMember == "")
                {
                    LoopToken = false;
                }


                else
                {
                    Console.WriteLine("What is their specialty");
                    Console.WriteLine("1) Hacker (Disables alarms)");
                    Console.WriteLine("2) Muscle (Disarms guards)");
                    Console.WriteLine("3) Lock Specialist (cracks vault)");
                    string ChooseSpecialty = Console.ReadLine();
                    Console.WriteLine("");

                    Console.WriteLine("What is the team member's skill level? (a number between 1-100)");
                    string MemberSkill   = Console.ReadLine();
                    int    NewSkillLevel = int.Parse(MemberSkill);
                    Console.WriteLine("");

                    Console.WriteLine("What percentage do they get?");
                    string MemberCut    = Console.ReadLine();
                    int    NewMemberCut = int.Parse(MemberCut);
                    Console.WriteLine("");

                    if (ChooseSpecialty == "1")
                    {
                        rolodex.Add(new Hacker()
                        {
                            Name          = NewTeamMember,
                            SkillLevel    = NewSkillLevel,
                            PercentageCut = NewMemberCut,
                            Specialty     = ChooseSpecialty,
                        });
                        Console.WriteLine("You've added a new Hacker to the team!");
                    }
                    else if (ChooseSpecialty == "2")
                    {
                        rolodex.Add(new Muscle()
                        {
                            Name          = NewTeamMember,
                            SkillLevel    = NewSkillLevel,
                            PercentageCut = NewMemberCut,
                            Specialty     = ChooseSpecialty,
                        });
                        Console.WriteLine("You've added new Muscle to the team!");
                    }
                    else if (ChooseSpecialty == "3")
                    {
                        rolodex.Add(new LockSpecialist()
                        {
                            Name          = NewTeamMember,
                            SkillLevel    = NewSkillLevel,
                            PercentageCut = NewMemberCut,
                            Specialty     = ChooseSpecialty,
                        });

                        Console.WriteLine("You've added a new Lock Specialist to the team!");
                    }
                }
            }
            Bank       FirstBank = new Bank();
            List <int> BankItem  = new List <int>()
            {
                FirstBank.AlarmScore,
                FirstBank.VaultScore,
                FirstBank.SecurityGuardScore,
            };
            int MostSecure  = BankItem.Max();
            int LeastSecure = BankItem.Min();

            //Most Secure
            if (FirstBank.AlarmScore == MostSecure)
            {
                Console.WriteLine("Most secure: Alarm");
            }
            else if (FirstBank.VaultScore == MostSecure)
            {
                Console.WriteLine("Most secure: Vault");
            }
            else if (FirstBank.SecurityGuardScore == MostSecure)
            {
                Console.WriteLine("Most secure: Security Guard");
            }
            // least Secure
            if (FirstBank.AlarmScore == LeastSecure)
            {
                Console.WriteLine("Least Secure: Alarm");
            }

            else if (FirstBank.VaultScore == LeastSecure)
            {
                Console.WriteLine("Least Secure: Vault");
            }
            else if (FirstBank.SecurityGuardScore == LeastSecure)
            {
                Console.WriteLine("Least Secure: Security Guard");
            }
            Console.WriteLine("------------------------");
            Console.WriteLine("Team member options:");
            for (int i = 0; i < rolodex.Count(); i++)
            {
                Console.WriteLine($"{rolodex[i].Name}");
                Console.WriteLine($"{rolodex[i].SkillLevel}");
                Console.WriteLine($"{rolodex[i].PercentageCut}");
            }
        }