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); }
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); }
static void Main() { int numberOfRobbedCitizens = 0; int numberOfRobbersCaught = 0; Console.CursorVisible = false; Initialize.Start(); //List<Person> persons = People.TownPeople; //lite info Console.WriteLine("Om en rånare blir tagen av en polis blir det ett 'A'nhållen\n" + "Om en invånare blir rånad blir det ett 'H'old-up\n" + "Om rånare blir tagen blir det ett stillastående 'F'ånge\n" + "Efter 20 händelser kommer rånaren tillbaks in i spelet\n" + "'P'oliser, 'I'nvånare, 'R'ånare\n" + "Tryck vart som helst för att fortsätta.."); Console.ReadKey(); Console.Clear(); //MoveDirection(persons, out int[] oldDirections); while (true) { //MoveDirection(People.TownPeople, out int[] directions); //CheckDirection(oldDirections, directions); Hiscores.GetScores(); //hämtar highscores Prison.CheckPrison(); //kollar fängelset om det är någon rånare som ska läggas till i spelplanen People.MoveAround(); //alla utom dom i fängelset ska röra sig People.CheckCollision(out int robbed, out int caught); // kollar om någon står på samma plats som någon annan, och skickar tillbaks hur många som blivit rånade/tagna ConsoleFunctions.ShowLocations(); //visar vart alla står numberOfRobbedCitizens += robbed; numberOfRobbersCaught += caught; ConsoleFunctions.PrintInfo(GameField.GameHeight + 2, 0, $"Number of Robbers caught: {numberOfRobbersCaught}\n" + $"Number of Citizens robbed: {numberOfRobbedCitizens}, Robbers in prison: {(Prison.Prisoners>0 ? $"{Prison.Prisoners}, next release: {Prison.NextRelease()/5}" : "none")} \n" + $"Number of robbers not in prison: {People.RobbersIngame} "); Thread.Sleep(300); ConsoleFunctions.ResetDrawnGameMap(); // istället för console clear skriver programmet ett " " där det finns en bokstav (mindre flicker) GameField.ResetField(); // nollställer 2d arrayen så de gamla bokstäverna inte skrivs ut igen } }