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); }
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); }
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) } }
public static void TryToCatchRobber(List <Robber> robbers, List <Cop> cops, out int robbersCaught) { robbersCaught = 0; foreach (Robber robber in robbers) { if (!robber.StolenGoods.Any()) // om rånaren inte har något i sin inventory är han ännu inte en rånare (eller har avtjänat sitt straff) { continue; } Cop cop = cops[Initialize.rand.Next(cops.Count)]; cop.TakeGoodsFromRobber(robber); // en slumpad polis tar rånarens saker (om det är flera på samma ställe) robber.TimesCaught++; cop.RobbersBusted++; GameField.AddMarker(robber.VerticalPosition, robber.HorizontalPosition, 'A'); ConsoleFunctions.ShowLocations(); SomeoneBusted(cop, robber); //RobberCaughtPrint(gameField, cop, robber, width, height); //gammal kod! robbersCaught++; } }
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); }