Example #1
0
        public void LoadGame()
        {
            if (LoadGameString != null)
            {
                PlayerState state = null;
                NewGameString = LoadGameString?.Invoke();

                if (!string.IsNullOrEmpty(NewGameString))
                {
                    state = JsonConvert.DeserializeObject <PlayerState>(NewGameString);
                    Player.LocationName = state.Location;
                    Player.Score        = state.Score;
                    Player.Moves        = state.Moves;
                    OnLocationChanged?.Invoke(this, Player.LocationName);
                    OnScoreChanged?.Invoke(this, Player.Score);
                    OnMovesChanged?.Invoke(this, Player.Moves);
                }

                else
                {
                    Output.WriteLine("Restore failed. No save file exists yet.");
                    return;
                }
            }
            else
            {
                Output.WriteLine("Restore failed. This game is not setup to load games.");
            }
        }
Example #2
0
 public void Restart()
 {
     //IsRunning = false;
     //mIsRestarting = true;
     Output.Clear();
     Player.LocationName = World.GetStartingLocation();
     Player.Score        = 0;
     Player.Moves        = 0;
     OnLocationChanged?.Invoke(this, Player.LocationName);
     OnScoreChanged?.Invoke(this, 0);
     OnMovesChanged?.Invoke(this, 0);
 }
Example #3
0
        private void InputInputReceivedHandler(object sender, string inputString)
        {
            Room previousRoom  = Player.Location;
            int  previousScore = Player.Score;

            if (IsWaitingForYesNo)
            {
                string response = inputString.Trim().ToUpper();
                if (response == "YES" || response == "Y")
                {
                    YesPrompt?.Invoke();
                    IsWaitingForYesNo = false;
                    return;
                }
                else if (response == "NO" || response == "N")
                {
                    NoPrompt?.Invoke();
                    IsWaitingForYesNo = false;
                    return;
                }
                else
                {
                    Output.Write("Please answer yes or no.> ");
                    return;
                }
            }

            if (IsWaitingForNumber)
            {
                int    result;
                string response = inputString.Trim();
                if (int.TryParse(response, out result))
                {
                    mNumberPrompt(result);
                    IsWaitingForNumber = false;
                    OnScoreChanged?.Invoke(this, Player.Score);
                    return;
                }
                else
                {
                    Output.WriteLine("Please enter a whole number.> ");
                    return;
                }
            }

            if (CommandManager.PerformCommand(this, inputString.Trim()))
            {
                Player.Moves++;
                OnMovesChanged?.Invoke(this, Player.Moves);

                if (previousRoom != Player.Location)
                {
                    CommandManager.PerformCommand(this, "LOOK");
                    OnLocationChanged?.Invoke(this, Player.Location.Name);
                }

                if (previousScore != Player.Score)
                {
                    OnScoreChanged?.Invoke(this, Player.Score);
                }
            }
            else
            {
                Output.WriteLine("That's not a verb I recognize.");
            }
        }