Example #1
0
 /// <summary>
 /// Sets up the initial state of the board.
 /// </summary>
 internal void SetUpApp()
 {
     SetParameters();
     Logger.SetGlobals((int)Parameters["ladybirds"], (int)Parameters["greenflies"]);
     BuildWorld((int)Parameters["rows"], (int)Parameters["columns"], (int)Parameters["ladybirds"], (int)Parameters["greenflies"]);
     Console_Helper.Draw(Game_Manager.Instance.Grid);
 }
Example #2
0
        /// <summary>
        /// Sets initial value of variables. Needed before starting a new run.
        /// </summary>
        internal void SetParameters()
        {
            int  ladybirds, greenflies, rows, columns;
            bool keepgoing;

            do
            {
                keepgoing               = false;
                ladybirds               = Console_Helper.GetInitialValues("Ladybirds", default_ladybirds);
                greenflies              = Console_Helper.GetInitialValues("Greenflies", default_greenflies);
                Logger.ladybirds_count  = ladybirds;
                Logger.greenflies_count = greenflies;
                int min_cells = ladybirds + greenflies;
                rows    = Console_Helper.GetInitialValues("rows", (int)Math.Sqrt(min_cells));
                columns = Console_Helper.GetInitialValues("columns", (int)Math.Ceiling((double)((min_cells / rows) + 1)));
                if (rows * columns < ladybirds + greenflies)
                {
                    keepgoing = true;
                    Console.Clear();
                    Console.WriteLine("Wrong Input Provided. The number of Ladybirds and Greenflies requested is higher than the number of cells. \nPlease try again.");
                    Console.ReadLine();
                }
            } while (keepgoing);
            Parameters = new Hashtable
            {
                { "ladybirds", ladybirds },
                { "greenflies", greenflies },
                { "rows", rows },
                { "columns", columns }
            };
        }
Example #3
0
 /// <summary>
 /// Game Mode initiates a version of the Game of Life where the grid is printed and the user controls the time steps.
 /// </summary>
 internal void RunGameMode()
 {
     SetUpApp();
     while (Console.ReadKey().Key != ConsoleKey.X)
     {
         Update();
         Console_Helper.Draw(Grid);
         Logger.Observe();
         Logger.Frameshot();
     }
     Logger.ReportStats();
     Logger.SaveFrameshots();
 }
Example #4
0
        /// <summary>
        /// Scientific Mode initiates a version of the Game of Life where everything is done in the back end.
        /// Game of life is run multiple times until only one species is alive on the board.
        /// </summary>
        internal void RunScientificMode()
        {
            SetParameters();
            int count = Console_Helper.GetPositiveInt("How many iterations would you like?");

            for (int i = 0; i < count; i++)
            {
                Logger.SetGlobals((int)Parameters["ladybirds"], (int)Parameters["greenflies"]);
                BuildWorld((int)Parameters["rows"], (int)Parameters["columns"], (int)Parameters["ladybirds"], (int)Parameters["greenflies"]);
                while (Logger.greenflies_count != 0 && Logger.ladybirds_count != 0)
                {
                    Game_Manager.Instance.Update();
                    Logger.Observe();
                    Logger.Frameshot();
                }
                Logger.SaveFrameshots();
                Logger.ReportStats();
            }
        }
Example #5
0
        /// <summary>
        /// Run the main menu of the application.
        /// </summary>
        internal void RunApp()
        {
            string game_mode = Console_Helper.GetMode();

            if (game_mode == "1")
            {
                RunGameMode();
            }
            else if (game_mode == "2")
            {
                RunScientificMode();
            }
            else if (game_mode == "3")
            {
                Console_Helper.Help();
            }
            else if (game_mode == "4")
            {
                Environment.Exit(0);
            }
        }