コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Let's Rob a Bank!");
            Console.WriteLine("------------------------");
            Console.WriteLine("Bank Security Info");

            //create a new bank to rob
            Bank newHeist = new Bank();

            newHeist.bankRecon();

            Console.WriteLine();

            Hacker Heidi = new Hacker()
            {
                Name          = "Heidi",
                SkillLevel    = 50,
                PercentageCut = 10
            };
            Hacker Jayson = new Hacker()
            {
                Name          = "Jayson",
                SkillLevel    = 49,
                PercentageCut = 10
            };
            Muscle Sarah = new Muscle()
            {
                Name          = "Heidi",
                SkillLevel    = 50,
                PercentageCut = 10
            };
            Muscle Drew = new Muscle()
            {
                Name          = "Drew",
                SkillLevel    = 61,
                PercentageCut = 10
            };
            LockSpecialist Steve = new LockSpecialist()
            {
                Name          = "Steve",
                SkillLevel    = 90,
                PercentageCut = 10
            };
            LockSpecialist Mo = new LockSpecialist()
            {
                Name          = "Mo",
                SkillLevel    = 95,
                PercentageCut = 10
            };

            List <IRobber> rolodex = new List <IRobber>
            {
                Heidi,
                Jayson,
                Sarah,
                Drew,
                Steve,
                Mo
            };

            foreach (IRobber robber in rolodex)
            {
                Console.WriteLine(robber);
            }

            Console.WriteLine("Enter New Team Member's name");
            string newName = Console.ReadLine();

            while (newName != "")
            {
                Console.WriteLine($@"Choose a number for {newName}'s speciality : 
1) Hacker (Disables alarms)
2) Muscle (Disarms guards)
3) Lock Specialist (cracks vault)");

                int newSpeciality = Int32.Parse(Console.ReadLine());

                while (newSpeciality != 1 && newSpeciality != 2 && newSpeciality != 3)
                {
                    Console.WriteLine("Please choose a number 1-3 DUM DUM.");
                    Console.Write($"Enter {newName}'s speciality: ");
                    newSpeciality = Int32.Parse(Console.ReadLine());
                }

                Console.Write($"Enter {newName}'s skill level: ");
                int newSkillLevel = Int32.Parse(Console.ReadLine());

                while (newSkillLevel < 0)
                {
                    Console.WriteLine("Skill level has to be a postive number, please try again.");
                    Console.Write($"Enter {newName}'s skill level: ");
                    newSkillLevel = Int32.Parse(Console.ReadLine());
                }

                Console.Write($"Enter {newName}'s percentage cut: ");
                int newPercentageCut = Int32.Parse(Console.ReadLine());

                if (newSpeciality == 1)
                {
                    Hacker newHacker = new Hacker()
                    {
                        Name          = newName,
                        SkillLevel    = newSkillLevel,
                        PercentageCut = newPercentageCut
                    };
                    rolodex.Add(newHacker);
                }
                if (newSpeciality == 2)
                {
                    Muscle newMuscle = new Muscle()
                    {
                        Name          = newName,
                        SkillLevel    = newSkillLevel,
                        PercentageCut = newPercentageCut
                    };
                    rolodex.Add(newMuscle);
                }
                if (newSpeciality == 3)
                {
                    LockSpecialist newLockSpecialist = new LockSpecialist()
                    {
                        Name          = newName,
                        SkillLevel    = newSkillLevel,
                        PercentageCut = newPercentageCut
                    };
                    rolodex.Add(newLockSpecialist);
                }

                Console.WriteLine("Enter New Team Member's name or press Enter to see list of fellow robbers");
                newName = Console.ReadLine();
            }

            foreach (IRobber robber in rolodex)
            {
                Console.WriteLine(robber);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //creat rolodex
            List <IRobber> rolodex = new List <IRobber>();
            int            i       = 1;
            //the criminals
            LockSpecialist Bob = new LockSpecialist()
            {
                Name          = "Bob",
                SkillLevel    = 35,
                PercentageCut = 35,
                Type          = "Lock Specialist",
                Index         = i++
            };
            LockSpecialist Sally = new LockSpecialist()
            {
                Name          = "Sally",
                SkillLevel    = 50,
                PercentageCut = 50,
                Type          = "Lock Specialist",
                Index         = i++
            };
            Muscle Jamar = new Muscle()
            {
                Name          = "Jamar",
                SkillLevel    = 45,
                PercentageCut = 35,
                Type          = "Muscle",
                Index         = i++
            };
            Muscle Larry = new Muscle()
            {
                Name          = "Larry",
                SkillLevel    = 65,
                PercentageCut = 65,
                Type          = "Muscle",
                Index         = i++
            };
            Hacker Langston = new Hacker()
            {
                Name          = "Langston",
                SkillLevel    = 75,
                PercentageCut = 50,
                Type          = "Hacker",
                Index         = i++
            };
            Hacker Quinton = new Hacker()
            {
                Name          = "Quinton",
                SkillLevel    = 45,
                PercentageCut = 40,
                Type          = "Hacker",
                Index         = i++
            };

            //add robbers to the Rolodex
            rolodex.Add(Bob);
            rolodex.Add(Sally);
            rolodex.Add(Jamar);
            rolodex.Add(Larry);
            rolodex.Add(Langston);
            rolodex.Add(Quinton);

            //create your criminals
            Console.WriteLine("Create a Criminal from the options below");
            Console.WriteLine("1.Hacker (Disables alarms)");
            Console.WriteLine("2.Muscle (Disarms guards)");
            Console.WriteLine("3.Lock Specialist (cracks vault)");
            Console.WriteLine();
            string userSelection;

            //do while to let user create some more criminals
            do
            {
                Console.Write("> ");
                string userChoice = Console.ReadLine();
                userSelection = userChoice;
                if (userSelection == "1")
                {
                    Console.WriteLine("Please create your Hacker");
                    Console.WriteLine();
                    Console.Write("Enter Skill Name: ");
                    string name = Console.ReadLine();
                    Console.Write("Enter Skill Level: ");
                    int skillLevel = int.Parse(Console.ReadLine());
                    Console.Write("Enter % needed out of 100: ");
                    int percentageCut = int.Parse(Console.ReadLine());
                    rolodex.Add(new Hacker()
                    {
                        Name          = name,
                        SkillLevel    = skillLevel,
                        PercentageCut = percentageCut,
                        Type          = "Hacker",
                        Index         = i++
                    });
                }
                if (userSelection == "2")
                {
                    Console.Write("Please create your Muscle");
                    Console.Write("Enter Skill Name: ");
                    string name = Console.ReadLine();
                    Console.Write("Enter Skill Level: ");
                    int skillLevel = int.Parse(Console.ReadLine());
                    Console.Write("Enter % needed out of 100: ");
                    int percentageCut = int.Parse(Console.ReadLine());
                    rolodex.Add(new Muscle()
                    {
                        Name          = name,
                        SkillLevel    = skillLevel,
                        PercentageCut = percentageCut,
                        Type          = "Muscle",
                        Index         = i++
                    });
                }
                if (userSelection == "3")
                {
                    Console.Write("Please create your Lock Specialist");
                    Console.Write("Enter Skill Name: ");
                    string name = Console.ReadLine();
                    Console.Write("Enter Skill Level: ");
                    int skillLevel = int.Parse(Console.ReadLine());
                    Console.Write("Enter % needed out of 100: ");
                    int percentageCut = int.Parse(Console.ReadLine());
                    rolodex.Add(new LockSpecialist()
                    {
                        Name          = name,
                        SkillLevel    = skillLevel,
                        PercentageCut = percentageCut,
                        Type          = "Lock Specialist",
                        Index         = i++
                    });
                }
            }while (userSelection != "");

            // create a bank with ints set to random
            Random rnd    = new Random();
            Bank   UsBank = new Bank()
            {
                CashOnHand         = rnd.Next(50_000, 1_000_001),
                AlarmScore         = rnd.Next(0, 101),
                VaultScore         = rnd.Next(0, 101),
                SecurityGuardScore = rnd.Next(0, 101)
            };
            // store and set bank
            Dictionary <string, int> banks = new Dictionary <string, int>();

            banks.Add("Guards", UsBank.SecurityGuardScore);
            banks.Add("Vault", UsBank.VaultScore);
            banks.Add("Alarm", UsBank.AlarmScore);
            var MostSecure = banks.Max(max => max.Key);
            var vH         = banks.Max(max => max.Value);

            Console.WriteLine($"Most Secure: {MostSecure} score of {vH}");
            var LeastSecure = banks.Min(min => min.Key);
            var vL          = banks.Max(max => max.Value);

            Console.WriteLine($"Least Secure: {LeastSecure} score of {vL}");

            // print out rolodex
            foreach (var robber in rolodex)
            {
                Console.WriteLine();
                Console.WriteLine("Criminal");
                Console.WriteLine("------------------");
                Console.WriteLine($"Name: {robber.Name}");
                Console.WriteLine($"Type: {robber.Type}");
                Console.WriteLine($"Skill Level: {robber.SkillLevel}");
                Console.WriteLine($"% due: {robber.PercentageCut}");
                Console.WriteLine($"Crew Member #: {robber.Index}");
                Console.WriteLine();
            }
            //number of criminals
            Console.WriteLine($"# of Criminals: {rolodex.Count}");

            //list to hold crew
            List <IRobber> crew = new List <IRobber>();

            Console.WriteLine("Enter the Crew Member #'s to add to your heist team");
            Console.WriteLine("Select at least 1 member from each group(hacker,muscle,lock specialist)");
            int userCrewInput;

            do
            {
                int userChoice = int.Parse(Console.ReadLine());
                userCrewInput = userChoice;
                foreach (IRobber Member in rolodex)
                {
                    if (userCrewInput == Member.Index)
                    {
                        crew.Add(Member);
                        Console.WriteLine("Add another Crew Member enter 0 when finished adding");
                    }
                    // Console.WriteLine("Thats not a number try again dummy!");
                }
            } while (userCrewInput != 0);
            foreach (var teamMate in crew)
            {
                Console.WriteLine($"Crew Member: {teamMate.Name}");
                Console.WriteLine($"Crew Member Speciality: {teamMate.Type}");
            }

            foreach (IRobber theif in crew)
            {
                theif.PerformSkill(UsBank);
            }
            UsBank.Security();
            if (UsBank.IsSecure)
            {
                Console.WriteLine("The heist failed!");
            }
            else
            {
                Console.WriteLine("WE'RE RICH ####!");
            }
        }
    }
コード例 #3
0
ファイル: Program.cs プロジェクト: aborgra/PlanHeist2
        static void Main(string[] args)
        {
            var  rolodex    = new List <IRobber> ();
            Bank targetBank = new Bank();

            var garrett = new Muscle()
            {
                Name          = "MMuscle",
                SkillLevel    = 100,
                PercentageCut = 20,
            };

            var willy = new LockSpecialist()
            {
                Name          = "Pick",
                SkillLevel    = 100,
                PercentageCut = 30,
            };

            var kevin = new Hacker()
            {
                Name          = "Kith",
                SkillLevel    = 100,
                PercentageCut = 10,
            };

            var namita = new Hacker()
            {
                Name          = "Hack",
                SkillLevel    = 100,
                PercentageCut = 20,
            };

            var mac = new LockSpecialist()
            {
                Name          = "MMac",
                SkillLevel    = 100,
                PercentageCut = 85,
            };

            rolodex.Add(garrett);
            rolodex.Add(namita);
            rolodex.Add(willy);
            rolodex.Add(mac);
            rolodex.Add(kevin);

            int    newCrewMemberSkillLevel;
            double newCrewMemberPercentageCut;

            Console.WriteLine($"Your crew has {rolodex.Count} members");

            while (true)
            {
                Console.WriteLine("Please enter a new crew member name:");
                var newCrewMemberName = Console.ReadLine();
                if (newCrewMemberName == "")
                {
                    break;
                }
                else
                {
                    while (true)
                    {
                        Console.WriteLine($"What is {newCrewMemberName}'s specialty: Hacker(Disables Alarms), Muscle (Disarms Guards), or Lock Specialist(Cracks Vaults)?");
                        var newCrewMemberSpecialty = Console.ReadLine();

                        if (newCrewMemberSpecialty.ToLower() == "muscle")
                        {
                            Muscle newMuscle = new Muscle()
                            {
                                Name = newCrewMemberName
                            };

                            while (true)
                            {
                                Console.WriteLine("Enter crew member's skill level (1-100)");
                                try {
                                    newCrewMemberSkillLevel = int.Parse(Console.ReadLine());
                                    break;
                                } catch (System.FormatException) {
                                    Console.WriteLine("Please enter a number (1-100)");
                                }
                            }
                            ;
                            newMuscle.SkillLevel = newCrewMemberSkillLevel;

                            while (true)
                            {
                                Console.WriteLine("Enter crew member's percentage cut (1-100)");
                                try {
                                    newCrewMemberPercentageCut = double.Parse(Console.ReadLine());
                                    break;
                                } catch {
                                    Console.WriteLine("Please enter a number (1-100)");
                                }
                            }
                            ;
                            newMuscle.PercentageCut = newCrewMemberPercentageCut;

                            rolodex.Add(newMuscle);
                            break;
                        }
                        else if (newCrewMemberSpecialty.ToLower() == "hacker")
                        {
                            Hacker newHacker = new Hacker()
                            {
                                Name = newCrewMemberName
                            };
                            while (true)
                            {
                                Console.WriteLine("Enter crew member's skill level (1-100)");
                                try {
                                    newCrewMemberSkillLevel = int.Parse(Console.ReadLine());
                                    break;
                                } catch (System.FormatException) {
                                    Console.WriteLine("Please enter a number (1-100)");
                                }
                            }
                            ;
                            newHacker.SkillLevel = newCrewMemberSkillLevel;

                            while (true)
                            {
                                Console.WriteLine("Enter crew member's percentage cut (1-100)");
                                try {
                                    newCrewMemberPercentageCut = double.Parse(Console.ReadLine());
                                    break;
                                } catch {
                                    Console.WriteLine("Please enter a number (1-100)");
                                }
                            }
                            ;
                            newHacker.PercentageCut = newCrewMemberPercentageCut;

                            rolodex.Add(newHacker);
                            break;
                        }
                        else if (newCrewMemberSpecialty.ToLower() == "lock specialist")
                        {
                            LockSpecialist newLockSpecialist = new LockSpecialist()
                            {
                                Name = newCrewMemberName
                            };
                            while (true)
                            {
                                Console.WriteLine("Enter crew member's skill level (1-100)");
                                try {
                                    newCrewMemberSkillLevel = int.Parse(Console.ReadLine());
                                    break;
                                } catch (System.FormatException) {
                                    Console.WriteLine("Please enter a number (1-100)");
                                }
                            }
                            ;
                            newLockSpecialist.SkillLevel = newCrewMemberSkillLevel;

                            while (true)
                            {
                                Console.WriteLine("Enter crew member's percentage cut (1-100)");
                                try {
                                    newCrewMemberPercentageCut = double.Parse(Console.ReadLine());
                                    break;
                                } catch {
                                    Console.WriteLine("Please enter a number (1-100)");
                                }
                            }
                            ;
                            newLockSpecialist.PercentageCut = newCrewMemberPercentageCut;

                            rolodex.Add(newLockSpecialist);
                            break;
                        }
                        else
                        {
                            Console.Clear();
                            Console.WriteLine("Please enter a valid specialty");
                        }
                    }
                }
            }
            Console.WriteLine($"Your crew has {rolodex.Count} members");

            Dictionary <string, int> bankScores = new Dictionary <string, int> ();

            Random rand               = new Random();
            var    alarmScore         = rand.Next(0, 101);
            var    vaultScore         = rand.Next(0, 101);
            var    securityGuardScore = rand.Next(0, 101);
            var    cashOnHand         = rand.Next(50000, 1000001);

            targetBank.AlarmScore         = alarmScore;
            targetBank.CashOnHand         = cashOnHand;
            targetBank.VaultScore         = vaultScore;
            targetBank.SecurityGuardScore = securityGuardScore;

            bankScores.Add("alarmScore", alarmScore);
            bankScores.Add("vaultScore", vaultScore);
            bankScores.Add("securityGuardScore", securityGuardScore);

            var orderedScores = bankScores.OrderBy(score => score.Value);

            var mostSecure  = orderedScores.Last();
            var leastSecure = orderedScores.First();

            Console.WriteLine($"Most secure:{mostSecure.Key} at {mostSecure.Value}");
            Console.WriteLine($"Least secure: {leastSecure.Key} at {leastSecure.Value}");

            foreach (var mem in rolodex)
            {
                Console.WriteLine($"{rolodex.IndexOf(mem)} {mem.ToString()}");
            }

            List <IRobber> crew = new List <IRobber> ();
            double         totalCutPercentage = 100;

            while (true)
            {
                string chosenMember;
                Console.WriteLine("Add member to crew?(Enter member #)");
                chosenMember = Console.ReadLine();

                if (chosenMember == "")
                {
                    break;
                }
                else
                {
                    foreach (var item in rolodex)
                    {
                        if (int.Parse(chosenMember) == rolodex.IndexOf(item))
                        {
                            crew.Add(item);
                            totalCutPercentage -= item.PercentageCut;
                            Console.WriteLine($"Cut left: {totalCutPercentage}");
                            rolodex.Remove(item);
                            break;
                        }
                    }
                    foreach (var item in rolodex)
                    {
                        if (item.PercentageCut < totalCutPercentage)
                        {
                            Console.WriteLine($"{rolodex.IndexOf(item)} {item.ToString()}");
                        }
                    }
                }
            }
            Console.WriteLine("Your assembled crew:");
            foreach (var mem in crew)
            {
                Console.WriteLine($"{mem.ToString()}");
            }
            Console.WriteLine("It's time to heist!");
            Console.WriteLine("------------------------------");

            foreach (var crewMember in crew)
            {
                crewMember.PerformSkill(targetBank);
            }
            double allCuts = 0;

            if (targetBank.IsSecure == true)
            {
                Console.WriteLine("You failed the heist.");
            }
            else
            {
                Console.WriteLine($"You did it!");
                Console.WriteLine($" ");

                foreach (var member in crew)
                {
                    var yourTake = (member.PercentageCut / 100) * targetBank.CashOnHand;
                    allCuts += yourTake;
                    Console.WriteLine($"{member.Name}: Your cut is ${yourTake.ToString("C")}.");
                    Console.WriteLine($"Remaining cut: {(targetBank.CashOnHand-allCuts).ToString("C")}");
                }
                Console.WriteLine($"Leader's cut: {(targetBank.CashOnHand-allCuts).ToString("C")}");
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var rolodex = new List <IRobber>();

            var Jay = new Hacker()
            {
                Name          = "Jay",
                SkillLevel    = 30,
                PercentageCut = 60
            };

            var Greg = new Hacker()
            {
                Name          = "Greg",
                SkillLevel    = 50,
                PercentageCut = 70
            };

            var Fee = new Muscle()
            {
                Name          = "Fee",
                SkillLevel    = 30,
                PercentageCut = 60
            };

            var Noob = new Muscle()
            {
                Name          = "Noob",
                SkillLevel    = 60,
                PercentageCut = 40
            };

            var Stu = new LockSpecialist()
            {
                Name          = "Stu",
                SkillLevel    = 30,
                PercentageCut = 70
            };

            var MiMi = new LockSpecialist()
            {
                Name          = "MiMi",
                SkillLevel    = 80,
                PercentageCut = 40
            };

            rolodex.Add(Jay);
            rolodex.Add(Greg);
            rolodex.Add(Fee);
            rolodex.Add(Noob);
            rolodex.Add(Stu);
            rolodex.Add(MiMi);



            while (true)
            {
                Console.WriteLine($"We have {rolodex.Count} crew members.");
                Console.WriteLine($"Enter a new crew member?");
                var crewMemberName = Console.ReadLine();
                if (crewMemberName == "")
                {
                    break;
                }
                else
                {
                    // Pick Member Specialty
                    Console.WriteLine($"What is {crewMemberName}'s Specialty?");
                    Console.WriteLine("Hacker (Disables Alarms)");
                    Console.WriteLine("Muscle (Disable Guards");
                    Console.WriteLine("Lock Specialist (Disables Vaults)");
                    var crewSpecialty = Console.ReadLine().ToLower();

                    while (true)
                    {
                        if (crewSpecialty == "muscle" || crewSpecialty == "hacker" || crewSpecialty == "lock specialist")
                        {
                            break;
                        }
                    }
                    Console.WriteLine($"What is {crewMemberName}'s skill level? (1-100");
                    int newMemberSkillLevel;


                    while (true)
                    {
                        newMemberSkillLevel = int.Parse(Console.ReadLine());
                        { break; }
                    }

                    Console.WriteLine($"What percentage of the cut does {crewMemberName}");
                    int crewMemberCut;

                    while (true)
                    {
                        crewMemberCut = int.Parse(Console.ReadLine());
                        { break; }
                    }

                    if (crewSpecialty == "hacker")
                    {
                        Hacker hacker = new Hacker()
                        {
                            Name          = $"{crewMemberName}",
                            SkillLevel    = newMemberSkillLevel,
                            PercentageCut = crewMemberCut
                        };
                        rolodex.Add(hacker);
                    }
                    else if (crewSpecialty == "muscle")
                    {
                        Muscle muscle = new Muscle()
                        {
                            Name          = $"{crewMemberName}",
                            SkillLevel    = newMemberSkillLevel,
                            PercentageCut = crewMemberCut
                        };
                        rolodex.Add(muscle);
                    }
                    else if (crewSpecialty == "lock specialist")
                    {
                        LockSpecialist lockSpecialist = new LockSpecialist()
                        {
                            Name          = $"{crewMemberName}",
                            SkillLevel    = newMemberSkillLevel,
                            PercentageCut = crewMemberCut
                        };
                        rolodex.Add(lockSpecialist);
                    }

                    // randomized 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}");

                    Bank bank = new Bank()
                    {
                        AlarmScore         = alarmScore,
                        VaultScore         = vaultScore,
                        SecurityGuardScore = securityGuardScore,
                        CashOnHand         = cashOnHand
                    };
                    Console.WriteLine($"Your crew has {rolodex.Count} members");

                    Dictionary <string, int> scores = new Dictionary <string, int>();
                    scores.Add("Alarm", alarmScore);
                    scores.Add("Vault", vaultScore);
                    scores.Add("Security Guard", securityGuardScore);

                    var ascendingScores = scores.OrderBy(score => score.Value);

                    var lowestScore = ascendingScores.First();

                    var highestScore = ascendingScores.Last();

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

                    Console.WriteLine($"Most Secure: {highestScore.Key}");

                    Console.WriteLine($"Least Secure: {lowestScore.Key}");

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

                    foreach (var robber in rolodex)
                    {
                        Console.WriteLine($"{rolodex.IndexOf(robber)}: {robber.Name} {robber.SkillLevel} {robber.PercentageCut}");
                    }

                    var crew = new List <IRobber>();

                    double totalCutPercentage = 100;


                    while (true)
                    {
                        try
                        {
                            // makes console more user friendly
                            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 chosenMember = Console.ReadLine();
                            if (chosenMember == "")
                            {
                                break;
                            }
                            else
                            {
                                foreach (var item in rolodex)
                                {
                                    if (int.Parse(chosenMember) == rolodex.IndexOf(item))
                                    {
                                        crew.Add(item);
                                        totalCutPercentage -= item.PercentageCut;
                                        Console.WriteLine($"Cut left: {totalCutPercentage}");
                                        rolodex.Remove(item);
                                        break;
                                    }
                                }
                                foreach (var item in rolodex)
                                {
                                    if (item.PercentageCut < totalCutPercentage)
                                    {
                                        Console.WriteLine($"{rolodex.IndexOf(item)} {item.ToString()}");
                                    }


                                    // 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 (totalCutPercentage - 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 = (totalCutPercentage * cashOnHand) / 100;
                        Console.WriteLine($"For setting up the heist you get what's leftover and walk away with ${leftover}. Good job!");
                    }
                }
            }
        }
コード例 #5
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!");
            }
        }
コード例 #6
0
        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}");
            }
        }