Exemplo n.º 1
0
        private void Loop()
        {
            //  Declare block variables
            string option;

            // Inicialize turn counter
            turns = 0;

            // Create agents to store in a list
            if (agents == null)
            {
                CreateAgents();
            }

            // Ensure console doesn't get cluttered up
            Console.Clear();

            // Plays a simple tune
            Songs.TuneHappy();

            // show map
            PrintMap();
            // by filling
            foreach (Agents agent in agents)
            {
                FillBoard(setts.y, agents, new int[2] {
                    agent.X, agent.Y
                });
            }

            // Show initial screen
            Render.IntroScreen();

            do
            {
                // Counts number of turns that passed
                turns++;

                // Get user choice
                option = Console.ReadLine();

                switch (option)
                {
                case "1":
                    Console.Clear();
                    Render.MenuOp();
                    break;

                case "2":
                    Console.Clear();
                    foreach (Agents agent in agents)
                    {
                        PrintMap();
                        FillBoard(setts.y, agents, new int[2]
                        {
                            agent.X, agent.Y
                        });
                        Console.WriteLine($"X: {agent.X}\nY: {agent.Y}");
                        Console.WriteLine($"turn number: {turns}");

                        // If agent is Ai controlled...
                        if (agent.Ai)
                        {
                            Console.WriteLine(agent);
                            agent.Move(agent, setts.BoardSize, agents);

                            Thread.Sleep(1200);
                        }

                        // ... or if is player controlled
                        else
                        {
                            char dir;
                            do
                            {
                                // Asks for input, converts input
                                Render.AskInput();

                                // Store input
                                // Convert to lowercase
                                // and convert to char
                                dir = Convert.ToChar
                                          (Console.ReadLine().ToLower()[0]);
                            } while (dir != 'a' && dir != 'w' && dir != 's'
                                     &&
                                     dir != 'd' && dir != 'q' && dir != 'e' &&
                                     dir != 'z' && dir != 'c');

                            agent.Move
                                (agent, setts.BoardSize, agents, dir);
                            //Render.PressKey();
                        }

                        // Check if there aren't any agent...
                        //... with bool infected as false
                        if (!agents.Exists(x => x.Infected == false))
                        {
                            break;
                        }
                    }
                    // Show last agent movement
                    PrintMap();
                    // fill
                    foreach (Agents agent in agents)
                    {
                        FillBoard(setts.y, agents, new int[2]
                        {
                            agent.X, agent.Y
                        });
                    }

                    Render.IntroScreen();
                    break;

                case "3":
                    // Insert option
                    FileManager.Save(setts.GetAllVars(), agents);
                    Render.IntroScreen();
                    break;

                default:
                    Console.WriteLine("Invalid");
                    Render.IntroScreen();
                    break;
                }

                // Shuffle list
                agents = ShuffleAgentsList(agents);

                if (!agents.Exists(x => x.Infected == false))
                {
                    turns = setts.T;
                }

                // Continue loop while turns played is less than max turns or...
                //... still exists agents that are not infected
            } while (turns > setts.T);
            Render.AllHumansDead();
        }