Esempio n. 1
0
        /// <summary>
        /// This function is called when the user enters a command.
        /// </summary>
        /// <param name="input">The string to be operated upon.</param>
        public void HandleInput(string input)
        {
            //execute depending on the GameState
            switch (gm)
            {
            case GameState.GettingPlayerInfo:
                //say hello
                player.name = mainWindow.inputText.Text;
                write("Welcome, ", "Black");
                write(player.name, "MediumOrchid", true);
                write(" to Realm 2.", "Black", true);
                cw.Show();
                mainWindow.IsEnabled = false;
                break;

            case GameState.Main:
                writeStats();
                string[] args = input.Split();
                if (args[0] == "help")
                {
                    Command.help();
                }
                if (args[0] == "save")
                {
                    FileIO.SaveGame(map, player);
                }
                else
                {
                    try
                    {
                        if (!currentplace.ExecuteCommand(args[0], args[1]))
                        {
                            write("You cannot '" + input + "' here.", "Red");
                        }
                        else
                        {
                            Place newplace = map.getPlace(new Tuple <int, int>(player.position.x, player.position.y));
                            //if we moved
                            if (!newplace.location.Equals(currentplace.location))
                            {
                                currentplace = newplace;
                                currentplace.checkCombat();
                                write("Current Place: ", "Black");
                                write(currentplace.name, "Blue", true);
                                write(currentplace.desc, "Black");
                            }
                        }
                    }
                    catch (IndexOutOfRangeException)
                    {
                        Log.Write("Could not execute command (too few arguments?).", LogType.ERROR);
                        if (args[0] != "help" && args[0] != "save")
                        {
                            write("You cannot '" + input + "' here.", "Red");
                        }
                    }
                }
                break;

            case GameState.SunPalace:
                break;

            case GameState.BCitadel:
                if (mainWindow.inputText.Text.ToLower() == "fight")
                {
                    for (int i = 0; i < 5; i++)
                    {
                        EnterCombat(new Slime());
                    }
                }
                else
                {
                    write("That's expected of a weakling", "Red");
                }
                break;

            case GameState.Dead:
                write(player.backpack.Count > 0 ? "You wake up in an unfamiliar location with your pockets empty and one of your posessions missing." : "You wake up in an unfamiliar location with your pockets empty.", "Red");
                currentplace = map.getPlace(new Tuple <int, int>(player.position.x, player.position.y));
                write("Current Place: ", "Black");
                write(currentplace.name, "Blue", true);
                write(currentplace.desc, "Black");
                gm = GameState.Main;
                break;

            case GameState.Frozen:
                //LEAVE THIS BLANK
                break;
            }
            //if the Player's position isn't null, set the currentPlace varable to the Player's current location
            if (player.position != null)
            {
                currentplace = map.getPlace(new Tuple <int, int>(player.position.x, player.position.y));
            }
        }