Esempio n. 1
0
        public static void GetRunningArguments()
        {
            Console.CursorVisible = true;

            string ArgInput = "";

            while (!(ArgInput.Contains("start")))
            {
                Console.Clear();

                Console.WriteLine("PAUSED: Enter Arguments -\n Include variable name to toggle state:\n\nPlayerControl:\t{0}\n\nGraphicsOn:\t{1}\n\nDrawGameInfo:\t{2}\n\nInclude 'Start' to begin.\n\nInput:\n", GameVars.PlayerControl, GameVars.GraphicsOn, GameVars.DrawGameInfo);

                ArgInput = Console.ReadLine();
                ArgInput = ArgInput.ToLower();

                if (ArgInput.Contains("playercontrol"))
                {
                    GameVars.PlayerControl = !(GameVars.PlayerControl);
                    if (GameVars.PlayerControl == true)
                    {
                        GameVars.TickRate = 50;
                    }
                    else
                    {
                        GameVars.TickRate = 0;
                    };
                }

                if (ArgInput.Contains("graphicson"))
                {
                    GameVars.GraphicsOn = !(GameVars.GraphicsOn);
                }

                if (ArgInput.Contains("drawgameinfo"))
                {
                    GameVars.DrawGameInfo = !(GameVars.DrawGameInfo);
                }

                if (ArgInput.Contains("playback"))
                {
                    GameVars.Reset();

                    GameVars.PlayerControl = false;
                    GameVars.GraphicsOn    = true;
                    GameVars.PlayingBack   = !(GameVars.PlayingBack);
                }
            }

            Console.CursorVisible = false;

            Console.Clear();
        }
Esempio n. 2
0
        public static void PlayGame()
        {
            Console.Clear();

            GameVars.Reset();

            while (Player.Alive)               // Loop for as long as player is alive (from Player.Alive bool == true).
            {
                if (GameVars.PlayerControl)    // If the boolean represent acceptance of user input is 'true', call GetPlayerInput (for debugging).
                {
                    Controls.GetPlayerInput(); // For debugging purposes, allows user input and changes Players 'NextDirection' string. (Also handles other inputs, such as 'P' for pause menu.)
                }
                else if (GameVars.PlayingBack)
                {
                    Machine.PlaybackBestInputs();
                }
                else // If the boolean is 'false', call method for the machine to 'play' the game without user input.
                {
                    Controls.CheckPause(); // Manual check for 'P' key to pause, as GetPlayerInput is not called to handle it.
                    Machine.LearnFromRandom(); // Method for computer to choose random direction for player.
                }

                Controls.HandlePlayerDirection();  // Run method to handle input, given as NextDirection string.

                Physics.CalculateVerticalMotion(); // Method to calculate vertical motion - checks falling due to gravity, and upward motion due to V_Speed (jumping).

                if (GameVars.GraphicsOn)           // Boolean to decide whether game graphics should be rendered - graphics OFF improves runspeed significantly due to Console.Write functions being very slow.
                {
                    Graphics.DrawLevelToScreen();  // Graphics method to draw the correct level portion to screen, relative to player position in-level and on-screen.
                    Graphics.DrawPlayerToScreen(); // Graphics method to draw the player's sprite to the on-screen X and Y co-ordinates.
                }

                if (GameVars.DrawGameInfo)
                {
                    Graphics.DrawInfo(); // Write program data to info bar on screen. (ie Fitness, Frame No. etc.)
                }

                System.Threading.Thread.Sleep(5); // Tick every X milliseconds (Wait between advancing frame, and running game loop logic).

                GameVars.CurrentFrame += 1;       //Advance Frame counter after tick.
                CalculateFitness();               // Determine 'fitness' value of current level run, dependant on rightmost distance travelled, and the current frame ('time' taken).
            }
        }