Exemple #1
0
        static void PrintOutBoard()
        {
            Console.Clear();
            List <string> happeningsInCity  = new List <string>();
            bool          pauseAfterMeeting = true;

            for (int y = 0; y < Program.SizeOfBoardY; y++)
            {
                if (y == 0)
                {
                    pauseAfterMeeting = false;
                    happeningsInCity.Clear();
                    MeetingsPerUpdate = 0;
                }
                for (int x = 0; x < Program.SizeOfBoardX; x++)
                {
                    bool someOneMet = false;
                    NumberOfCitizensOnThisPosition       = 0;
                    NumberOfPolicesOnThisPosition        = 0;
                    NumberOfThiefsOnThisPosition         = 0;
                    NumberOfThiefsArrestedOnThisPosition = 0;
                    NumberOfRobbedCitizensOnThisPosition = 0;
                    NumberOfReleasedThiefs = 0;

                    foreach (Person person in City)
                    {
                        if (person.XPosition == x && person.YPosition == y)
                        {
                            if (person is Police)
                            {
                                List <Police> listOfPolicesOnThisPosition = ((Police)person).ListOfPolicesOnSpot(x, y);
                                Person.PoliceFindsThiefsAndCitizens(x, y, listOfPolicesOnThisPosition);
                            }
                            else if (person is Thief)
                            {
                                if (((Thief)person).InPrison == false)
                                {
                                    Person.ThiefFindsThiefsAndCitizens(x, y);
                                }
                            }
                            else if (person is Citizen)
                            {
                                ((Citizen)person).CitizensOnThisPosition(x, y);
                            }
                            if ((NumberOfPolicesOnThisPosition + NumberOfThiefsOnThisPosition + NumberOfCitizensOnThisPosition) > 1)
                            {
                                someOneMet = true;
                            }

                            if (!someOneMet)
                            {
                                if (person is Police)
                                {
                                    Console.ForegroundColor = ConsoleColor.DarkBlue;
                                    Console.Write("P");
                                    Console.ForegroundColor = ConsoleColor.White;
                                }
                                if (person is Thief)
                                {
                                    if (((Thief)person).InPrison == true)
                                    {
                                        { Console.Write(" "); }
                                    }
                                    else
                                    {
                                        Console.ForegroundColor = ConsoleColor.DarkRed;
                                        Console.Write("T");
                                        Console.ForegroundColor = ConsoleColor.White;
                                    }
                                }
                                if (person is Citizen)
                                {
                                    Console.ForegroundColor = ConsoleColor.Green;
                                    Console.Write("M");
                                    Console.ForegroundColor = ConsoleColor.White;
                                }
                            }

                            break;
                        }
                    }

                    if (!someOneMet)
                    {
                        Console.Write(" ");
                    }
                    if (someOneMet)
                    {
                        Program.MeetingsPerUpdate++;
                        happeningsInCity = SaveInformationAboutHappeningsInCity(happeningsInCity);
                        Console.Write("X");
                        pauseAfterMeeting = true;
                    }
                }
                Console.WriteLine();
            }

            if (Prison.Any <Thief>())
            {
                CheckIfPrisonersShouldBeFree();
            }

            if ((pauseAfterMeeting && happeningsInCity.Any <string>()) || NumberOfReleasedThiefs > 0)
            {
                PrintOutInformation(happeningsInCity);
                Console.WriteLine();
                PrintCounterOnRobbedAndCatched();
                PrintOutPrison();
                Thread.Sleep(2000);
            }
        }