예제 #1
0
    // Returns as string any Items for a scene or that there isnt any, plus includes current scene story attached to end.
    public string Show()
    {
        string lcOutput = "No items found in current Scene!\n\n" + GameManage.instance.app.model.currentScene.sceneStory;

        //Basically if there are no items for current scene (Items = 0) then return message + story and exit!
        if (GameManage.instance.app.model.currentScene.Item == "")
        {
            return(lcOutput);
        }

        // Instantiate a GetInventory class for purpose of using to check Items havnt already been pickup from this scene.
        GetInventory lcInventory = new GetInventory();

        if (lcInventory.Exists(GameManage.instance.app.model.currentScene.Item) == true)
        {
            return(lcOutput);
        }

        // If made it this far, then there is an Items available so return the string and infrom player how to pickup!
        lcOutput = "Item Found: " + GameManage.instance.app.model.currentScene.Item + "\n\n" + GameManage.instance.app.model.currentScene.sceneStory;
        return(lcOutput);
    }
    public float zAxis       = 0.0001f; // Default for android accelerometer but changed if bluestack detected

    // The parse method will process and handle errors for any command text input submitted for processing.
    public string Parse(string arg0)                    // arg0 is the command text passed over from the input text box in TextIO Scene.
    {
        try                                             // Try catch here so the event of any error, it will catch and return do not understand message
        {
            string lcOutput = "Do not understand!\n\n"; // Default Output Message + Current Storyline added below
            // Now append the current scene story to the default do not understand message
            lcOutput = lcOutput + GameManage.instance.app.model.currentScene.sceneStory;
            // Now check if player input just a commmand number not text.. and set cmdText to the text command mapped for that number
            string cmdText = ConvertIfNumberCommand(arg0);
            cmdText = cmdText.ToLower(); // declares the input command into a new variable and Converted to lower case
            bool Redirect = false;       //declares the Redirection variable in preparation for possible redirecting

            //Declares local temporary variable instances of certain classes required for command processing
            GetInventory lcInventory = new GetInventory(); // Used for inventory interactions
            GetItems     lcItems     = new GetItems();     // Used for scene Items checking and interactions
            // Chat command detection
            if (cmdText.Length >= 5)                       // check length for it having chat message
            {
                if (cmdText.Substring(0, 5) == "chat/")    //check the first 5 characters are the chat command
                {
                    // Send message to MQTT server
                    GameManage.instance.app.controller.gameServer.SendMessage("CHAT", cmdText.Substring(5, cmdText.Length - 5));
                    return(GameManage.instance.app.model.currentScene.sceneStory); // return story for game display
                }
            }

            Scenes lcScene = GameManage.instance.app.model.currentScene; // puts current scene into temporary local scene variable
Redo:                                                                    // The following for each loop jumps out to here in the event of redirection being true to reload the new redirection scene

            // loops through every story scene in the list of scenes created by The Story class instance.
            foreach (Scenes tmpScene in GameManage.instance.app.model.lstScenes)
            {
                // Check and identify if command text input contains the current scene being cycled throughs identifier
                if (cmdText.Contains(tmpScene.sceneIdentifier))
                {
                    // Check that current scenes help (available commands) contains the identifier for scene identified
                    // Or alternatively just continues if Redirect variable = True
                    if (lcScene.sceneHelp.Contains(tmpScene.sceneIdentifier) || Redirect == true)
                    {
                        // Checks the identified new scenes redirection item, if any, exist or not in players inventory
                        if (lcInventory.Exists(tmpScene.RedirectionItem) == false)
                        {
                            GameManage.instance.app.controller.gameServer.SendMessage("LEFT", "Selected " + tmpScene.sceneIdentifier.ToUpper() + " and Left Chat!");
                            // Add previous scene to history of scene list that keeps record of players route in game
                            GameManage.instance.app.model.lstSceneHistory.Add(lcScene.sceneIdentifier);
                            // If didnt exist in player inventory, set current scene to found identified scene
                            GameManage.instance.app.model.currentScene = tmpScene;
                            // Set temporary output variable and return the newly navigated scenes story
                            lcOutput = tmpScene.sceneStory;
                            //Increase players score each time scene changes
                            GameManage.instance.app.model.PlayerScore = GameManage.instance.app.model.PlayerScore + 100;

                            GameManage.instance.app.controller.gameServer.connect(GameManage.instance.app.model.currentScene.sceneImageName);
                            return(lcOutput); // Returns new current scenes story
                        }
                        else
                        {
                            // If redirection item for identified scene exited in players inventory set command to the
                            // Redirection scene identifier for the identified scene, then start loop process again.
                            cmdText  = tmpScene.RedirectionScene.ToLower(); // Changed command to redirection scene command
                            Redirect = true;                                // lets us know its doing a redirect for when reloops
                            goto Redo;                                      // goes back to top of loop to start loop again using new cmdtext
                        }
                    }
                }
            }

            // In the event command was not a navigational to a new scene, it might be a common scene command, processed here
            if (lcScene.sceneHelp.Contains(cmdText) == true) // Check Available command supports it, or if its the pickup command
            {
                switch (cmdText)                             // Select case switch statement to identify common scene commands
                {
                case "exit":                                 // Exit game case back to start scene
                    //Send left game and chat to the subscribed chat
                    GameManage.instance.app.controller.gameServer.SendMessage("LEFT", "Exited Game and Left Chat!");
                    GameManage.instance.app.controller.gameServer.UnSubscribeNow(); // unsubscribe
                    SceneManager.LoadScene("Start");                                // load start scene
                    return("");

                case "save":                                           // Save game case
                    Save();                                            // Caller to a sub task for saving
                    lcOutput = "Game Saved!\n\n" + lcScene.sceneStory; // set Output variable = message + Scene Story
                    break;                                             // Exit switch

                case "load":                                           // load game case
                    //Send left chat and loaded game to the subscribed chat
                    GameManage.instance.app.controller.gameServer.SendMessage("LEFT", "Loaded Game and Left Chat!");
                    Load();                                                // Caller to load sub task
                    lcScene  = GameManage.instance.app.model.currentScene; // set local variable for scene
                    lcOutput = "Game Loaded!\n\n" + lcScene.sceneStory;    // Same as previously described above.
                    //Connect to newly loaded scenes chat
                    GameManage.instance.app.controller.gameServer.connect(GameManage.instance.app.model.currentScene.sceneImageName);
                    break;

                case "items":                      // show inventory items player has
                    lcOutput = lcInventory.Show(); // set Output variable to inventory data + story
                    break;

                case "find":                   // find and show items for scene
                    lcOutput = lcItems.Show(); // set Output variable to scene items if any + story
                    break;

                case "back":                                                                           // Will change scene to the last scene identifier added to the scene history list
                    int    LastSceneInt = GameManage.instance.app.model.lstSceneHistory.Count - 1;     // gets last scene identifier position in list
                    string LastScene    = GameManage.instance.app.model.lstSceneHistory[LastSceneInt]; // gets Last Scene
                    //Send left chat and went back to the subscribed chat
                    GameManage.instance.app.controller.gameServer.SendMessage("LEFT", "Selected BACK and Left Chat!");
                    // Remove the scene from history list since they going back to it
                    GameManage.instance.app.model.lstSceneHistory.RemoveAt(LastSceneInt);
                    //Set the scene being loaded back to by getting it from the locla list
                    foreach (Scenes tmpScenes in GameManage.instance.app.model.lstScenes)
                    {
                        // Finds matching Scene identifier and loads the scene its going back to
                        if (tmpScenes.sceneIdentifier == LastScene)
                        {
                            GameManage.instance.app.model.currentScene = tmpScenes;
                        }
                    }
                    // Anti cheat for score (Back and forward cheat) When player goes back lose 200 points!
                    GameManage.instance.app.model.PlayerScore = GameManage.instance.app.model.PlayerScore - 200;
                    lcOutput = GameManage.instance.app.model.currentScene.sceneStory;     // set Output variable
                    //Join the chat for scene player went back too
                    GameManage.instance.app.controller.gameServer.connect(GameManage.instance.app.model.currentScene.sceneImageName);
                    break;

                case "pickup":
                    lcOutput = lcInventory.ItemAdd(GameManage.instance.app.model.currentScene.Item);     // add item to the players inventory list
                    break;
                }
            }
            return(lcOutput); // Return whatever the output is now set to...
        }
        catch (Exception)     // if any error just return the default do not understand message + story
        {
            string lcOutput = "Do not understand!\n\n";
            lcOutput = lcOutput + GameManage.instance.app.model.currentScene.sceneStory;
            return(lcOutput);
        }
    }