/// <summary>
        /// Constructor of the GameController class
        /// </summary>
        /// <param name="rows"> Width of the room </param>
        /// <param name="cols"> Height of the board</param>
        /// <param name="lvl"> The starting level </param>
        public GameLoopController(int rows, int cols, int lvl = 1, int hp = 0)
        {
            // Creates a new SaveManager
            saves = new SavesManager();
            // Starts the stopGameToken to false
            stopGameToken = false;

            // Sets the current level to the one given
            CurrentLevel = lvl;

            // Creates a new Scene with the dimensions given
            scene = new SceneManager(cols, rows);

            // Generates all the objects of the game
            scene.GenerateNewScene(CurrentLevel, hp);

            // Creates a new Renderer to display information
            graphics = new Renderer(scene.Room, scene.Player, CurrentLevel);

            // Starts the main Update for the game
            ScheduledUpdate();
        }
Exemple #2
0
        /// <summary>
        /// Checks passed arguments through the console
        /// </summary>
        /// <param name="args"> Arguments passed through console </param>
        private void GameStart(string[] args)
        {
            // Creates integer variable rows
            int rows;
            // Creates integer variable cols
            int cols;

            SavesManager saves = new SavesManager();

            // Checks if the input arguments are valid
            if (args[0] == "-l")
            {
                // Stores all the variables from the same
                (int row, int col, int lvl, int hp)savedVariables =
                    saves.LoadSave(args[1]);

                // Checks of any of the variables is 0
                if (savedVariables.row == 0 || savedVariables.col == 0 ||
                    savedVariables.lvl == 0 || savedVariables.hp == 0)
                {
                    // Displays an error message to the user
                    Console.WriteLine("No save was found or is corrupted\n");
                    ErrorMessage();
                }
                else
                {
                    // Starts the main menu
                    InitializeMainMenu(savedVariables.row, savedVariables.col,
                                       savedVariables.lvl, savedVariables.hp);
                }
            }
            // Checks if the input arguments are invalid
            else if (args == null || args.Length == 0 ||
                     args[0] != "-r" && args[2] != "-c" &&
                     args[0] != "-c" && args[2] != "-r")
            {
                // Displays error message
                ErrorMessage();
            }
            // Checks if the input arguments are valid
            else if (args[0] == "-r" && args[2] == "-c")
            {
                // Checks if the input arguments can't be converted to integers
                if (!int.TryParse(args[1], out rows))
                {
                    // Displays error message
                    ErrorMessage();
                    // Terminates method execution
                    return;
                }
                // Checks if the input arguments can't be converted to integers
                if (!int.TryParse(args[3], out cols))
                {
                    // Displays error message
                    ErrorMessage();
                    // Terminates method execution
                    return;
                }
                // Initializes the MainMenu
                InitializeMainMenu(rows, cols);
            }
            // Checks if the input arguments are valid
            else if (args[0] == "-c" && args[2] == "-r")
            {
                // Checks if the input arguments can't be converted to integers
                if (!int.TryParse(args[3], out rows))
                {
                    // Displays error message
                    ErrorMessage();
                    // Terminates method execution
                    return;
                }
                // Checks if the input arguments can't be converted to integers
                if (!int.TryParse(args[1], out cols))
                {
                    // Displays error message
                    ErrorMessage();
                    // Terminates method execution
                    return;
                }
                // Initializes the MainMenu
                InitializeMainMenu(rows, cols);
            }
        }