Beispiel #1
0
        void SetUp()
        {
            //Sets up the simulation.
            mapSizeX = 100;
            mapSizeY = 25;
            int    numCops      = 5;
            int    numRobbers   = 5;
            int    numCivilians = 10;
            Random rnd          = new Random();

            List <Person> citizens = new List <Person>();
            List <Robber> prison   = new List <Robber>();

            //Populate the City.
            for (int i = 0; i < numCops; i++)
            {
                Cop cop = new Cop(rnd.Next(mapSizeX), rnd.Next(mapSizeY));
                citizens.Add(cop);
            }
            for (int i = 0; i < numRobbers; i++)
            {
                Robber robber = new Robber(rnd.Next(mapSizeX), rnd.Next(mapSizeY));
                citizens.Add(robber);
            }
            for (int i = 0; i < numCivilians; i++)
            {
                Civilian civilian = new Civilian(rnd.Next(mapSizeX), rnd.Next(mapSizeY));
                citizens.Add(civilian);
            }

            Simulate(citizens, prison);
        }
Beispiel #2
0
        static void SomeoneBusted(Cop cop, Robber robber)
        {
            int copClocks          = cop.SiezedItems.OfType <Item>().Where(x => x.ItemName == "Clock").Count();
            int copCash            = cop.SiezedItems.OfType <Item>().Where(x => x.ItemName == "Cash").Count();
            int copKeys            = cop.SiezedItems.OfType <Item>().Where(x => x.ItemName == "Keys").Count();
            int copPhone           = cop.SiezedItems.OfType <Item>().Where(x => x.ItemName == "Phone").Count();
            int offsetFromTop      = 4;
            int middlePositionLeft = GameField.GameWidth / 2;

            string[] toPrint = { "========================",
                                 " A cop has busted ",
                                 " a robber! ",
                                 " This is his current ",
                                 " inventory. ",            "========================",
                                 $" Clock x {copClocks}",
                                 $" Cash x {copCash}",
                                 $" Keys x {copKeys}",
                                 $" Phone x {copPhone}",
                                 " ",
                                 "========================" };
            int      lastLine   = toPrint.Length;
            int      lastColumn = middlePositionLeft + toPrint[0].Length + 1; //när looten ska försvinna behöver den funktionen veta hur långa raderna var, (jag har gjort alla raden lika långa)


            ConsoleFunctions.PrintWho(robber);
            ConsoleFunctions.PrintInfoStatScreen(toPrint, offsetFromTop, middlePositionLeft);
            Thread.Sleep(5000);
            Prison.PrisonTimerTick();
            Prison.PutRobberInJail(robber); // råraren hamnar i finkan, men får inte sin tid plussad då han egentligen inte har suttit inne än
            ConsoleFunctions.ResetPartialScreen(offsetFromTop, middlePositionLeft, offsetFromTop + lastLine, offsetFromTop + lastColumn);
            Console.SetCursorPosition(0, GameField.GameHeight + 1);
        }
Beispiel #3
0
        Robber Arrest(int x, int y, List <Person> citizens)
        {
            //Returns the arrested Robber.
            Robber robber = new Robber(0, 0);
            Person cop    = new Person();

            bool robberFound = false;
            bool copFound    = false;

            //Find the Cop and Robber in question.
            foreach (Person person in citizens)
            {
                if (person.xPos == x && person.yPos == y)
                {
                    string type = person.GetType().Name;
                    switch (type)
                    {
                    case "Robber":
                        if (!robberFound)
                        {
                            robber      = (Robber)person;
                            robberFound = true;
                        }
                        break;

                    case "Cop":
                        if (!copFound)
                        {
                            cop      = person;
                            copFound = true;
                        }
                        break;
                    }
                    if (robberFound && copFound)
                    {
                        break;
                    }
                }

                //Remove all items from Robber and give to Cop.
                if (robber.Inventory.Any())
                {
                    foreach (string item in robber.Inventory)
                    {
                        cop.Inventory.Add(item);
                        robber.Inventory.Remove(item);
                    }
                }
            }
            //Return the arrested Robber.
            return(robber);
        }
Beispiel #4
0
        public static void TryRobbing(List <Robber> robbers, List <Citizen> citizens, out int robbedCitizens)
        {
            robbedCitizens = 0;

            foreach (Citizen citizen in citizens)
            {
                bool multipleRobbersCanRobTheSameCitizen = true;
                if (!citizen.Belongings.Any()) // om inte medborgaren har något på sig kan han inte bli rånad
                {
                    continue;
                }
                if (multipleRobbersCanRobTheSameCitizen)
                {
                    foreach (Robber r in robbers)
                    {
                        if (citizens.First().Equals(citizen))
                        {
                            GameField.AddMarker(citizen.VerticalPosition, citizen.HorizontalPosition, 'H');
                            ConsoleFunctions.ShowLocations();
                        }
                        r.StealFrom(citizen);
                        r.PeopleRobbed++;
                        robbedCitizens++;
                        citizen.TimesRobbed++;

                        Event.SomeoneRobbed(citizen, r);
                    }
                }
                else
                {
                    if (citizens.First().Equals(citizen))
                    {
                        GameField.AddMarker(citizen.VerticalPosition, citizen.HorizontalPosition, 'H');
                        ConsoleFunctions.ShowLocations();
                    }
                    Robber robber = robbers[Initialize.rand.Next(robbers.Count)]; // en slumpad rånare rånar personen
                    robber.StealFrom(citizen);
                    robber.PeopleRobbed++;
                    citizen.TimesRobbed++;
                    robbedCitizens++;

                    Event.SomeoneRobbed(citizen, robber);
                }
            }
        }
Beispiel #5
0
        public static void SomeoneRobbed(Citizen citizen, Robber robber)
        {
            int robberClocks       = robber.StolenGoods.OfType <Item>().Where(x => x.ItemName == "Clock").Count();
            int robberCash         = robber.StolenGoods.OfType <Item>().Where(x => x.ItemName == "Cash").Count();
            int robberKeys         = robber.StolenGoods.OfType <Item>().Where(x => x.ItemName == "Keys").Count();
            int robberPhone        = robber.StolenGoods.OfType <Item>().Where(x => x.ItemName == "Phone").Count();
            int citizenClocks      = citizen.Belongings.OfType <Item>().Where(x => x.ItemName == "Clock").Count();
            int citizenCash        = citizen.Belongings.OfType <Item>().Where(x => x.ItemName == "Cash").Count();
            int citizenKeys        = citizen.Belongings.OfType <Item>().Where(x => x.ItemName == "Keys").Count();
            int citizenPhone       = citizen.Belongings.OfType <Item>().Where(x => x.ItemName == "Phone").Count();
            int offsetFromTop      = 4;
            int middlePositionLeft = GameField.GameWidth / 2;

            string[] toPrint = { "========================",
                                 " A robber has stolen ",
                                 " from a citizen! ",
                                 " This is their current ",
                                 " inventories. ",
                                 "======ROBBER============",
                                 $" Clock x {robberClocks}",
                                 $" Cash x {robberCash}",
                                 $" Keys x {robberKeys}",
                                 $" Phone x {robberPhone}",
                                 " ",
                                 "======CITIZEN===========",
                                 $" Clock x {citizenClocks}",
                                 $" Cash x {citizenCash}",
                                 $" Keys x {citizenKeys}",
                                 $" Phone x {citizenPhone}",
                                 " ",
                                 "========================" };

            int lastLine   = offsetFromTop + toPrint.Length;
            int lastColumn = middlePositionLeft + toPrint[0].Length + 1;

            ConsoleFunctions.PrintWho(citizen); //visar en pil brevid personen som det hände något med

            ConsoleFunctions.PrintInfoStatScreen(toPrint, offsetFromTop, middlePositionLeft);


            Thread.Sleep(5000);
            ConsoleFunctions.ResetPartialScreen(offsetFromTop, middlePositionLeft, lastLine, lastColumn);
            Prison.PrisonTimerTick();
            Console.SetCursorPosition(0, GameField.GameHeight + 1);
        }
Beispiel #6
0
        static void PrintHiScores(int offset, Citizen mostRobbed, Robber mostRobberies,
                                  Robber mostTimesCaught, Robber robberMostItems, Cop copMostItems, Cop mostRobbersBusted)
        {
            int i            = 0;
            int placeOnRight = Console.WindowWidth - offset;

            while (i <= 10)
            {
                if (i == 0)
                {
                    ConsoleFunctions.ColoredText("[C10]Most robbed", placeOnRight, i);
                    ConsoleFunctions.ColoredText($"[C6]ID:[C10] {mostRobbed.ID}[C15], score:[C12] {mostRobbed.TimesRobbed}  ", placeOnRight, i + 1);
                }
                else if (i == 2)
                {
                    ConsoleFunctions.ColoredText("[C10]Most robberies", placeOnRight, i);
                    ConsoleFunctions.ColoredText($"[C6]ID:[C10] {mostRobberies.ID}[C15], score:[C12] {mostRobberies.PeopleRobbed}  ", placeOnRight, i + 1);
                }
                else if (i == 4)
                {
                    ConsoleFunctions.ColoredText("[C10]Most caught", placeOnRight, i);
                    ConsoleFunctions.ColoredText($"[C6]ID:[C10] {mostTimesCaught.ID}[C15], score:[C12] {mostTimesCaught.TimesCaught}  ", placeOnRight, i + 1);
                }
                else if (i == 6)
                {
                    ConsoleFunctions.ColoredText("[C10]Most items [C12](robber)", placeOnRight, i);
                    ConsoleFunctions.ColoredText($"[C6]ID:[C10] {robberMostItems.ID}[C15], score:[C12] {robberMostItems.StolenGoods.Count} ", placeOnRight, i + 1);
                }
                else if (i == 8)
                {
                    ConsoleFunctions.ColoredText("[C10]Most items [C9](cop)", placeOnRight, i);
                    ConsoleFunctions.ColoredText($"[C6]ID:[C10] {copMostItems.ID}[C15], score:[C12] {copMostItems.SiezedItems.Count}  ", placeOnRight, i + 1);
                }
                else if (i == 10)
                {
                    ConsoleFunctions.ColoredText("[C10]Most robbers busted", placeOnRight, i);
                    ConsoleFunctions.ColoredText($"[C6]ID:[C10] {mostRobbersBusted.ID}[C15], score:[C12] {mostRobbersBusted.RobbersBusted}  ", placeOnRight, i + 1);
                }
                i += 2; // plussar på med 2, så nästa utskrift hamnar under  id, score (dvs 2 rader under den förra)
            }
        }
Beispiel #7
0
        public static void GetScores()
        {
            //placerar highscores första bokstav 22 rutor från kanten till höger
            int hiscoreOffset = 22;
            //vem har blivit rånad mest
            int     mostTimesRobbed   = People.TownPeople.OfType <Citizen>().Max(x => x.TimesRobbed);
            Citizen mostRobbedCitizen = People.TownPeople.OfType <Citizen>().First(x => x.TimesRobbed == mostTimesRobbed);



            //vem har rånat flest

            int    mostRobberies          = People.TownPeople.OfType <Robber>().Max(x => x.PeopleRobbed);
            Robber mostRobberiesCommitted = People.TownPeople.OfType <Robber>().First(x => x.PeopleRobbed == mostRobberies);



            //vilken rånare som har blivit tagen flest gånger
            int    mostTimesCaught  = People.TownPeople.OfType <Robber>().Max(x => x.TimesCaught);
            Robber mostCaughtRobber = People.TownPeople.OfType <Robber>().First(x => x.TimesCaught == mostTimesCaught);

            //vilken rånare har mest items i sin inventory
            int    mostCurrentItemsStolen = People.TownPeople.OfType <Robber>().Max(x => x.StolenGoods.Count);
            Robber robberWithMostitems    = People.TownPeople.OfType <Robber>().First(x => x.StolenGoods.Count == mostCurrentItemsStolen);

            //vilken polis har mest items i sin inventory
            int mostItemsSiezed  = People.TownPeople.OfType <Cop>().Max(x => x.SiezedItems.Count);
            Cop copWithMostItems = People.TownPeople.OfType <Cop>().First(x => x.SiezedItems.Count == mostItemsSiezed);


            //vilken polis som har tagit flest rånare
            int mostRobbersCaugh         = People.TownPeople.OfType <Cop>().Max(x => x.RobbersBusted);
            Cop copWithMostRobbersCaught = People.TownPeople.OfType <Cop>().First(x => x.RobbersBusted == mostRobbersCaugh);

            //skriver ut highscores uppe till höger
            PrintHiScores(hiscoreOffset, mostRobbedCitizen, mostRobberiesCommitted,
                          mostCaughtRobber, robberWithMostitems, copWithMostItems, copWithMostRobbersCaught);
        }
Beispiel #8
0
 public static void PutRobberInJail(Robber r)
 {
     Jail.Add(r);
 }
Beispiel #9
0
 public void TakeGoodsFromRobber(Robber robber)
 {
     SiezedItems.AddRange(robber.StolenGoods);
     robber.StolenGoods.Clear();
 }