public void Parse(String pCmdStr, aDisplayer display) { String strResult = "Do not understand"; char[] charSeparators = new char[] { ' ' }; pCmdStr = pCmdStr.ToLower(); String[] parts = pCmdStr.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); // tokenise the command // process the tokens if (parts.Length > 0) // Check incase nothing was entered { switch (parts[0]) { case "pick": if (parts[1] == "up") { Debug.Log("Got Pick up"); strResult = "Got Pick up"; if (parts.Length == 3) { String param = parts[2]; } // do pick up command // GameModel.Pickup(); } break; case "go": switch (parts[1]) { case "north": Debug.Log("Got go North"); // strResult = "Got Go North"; GameModel.go(GameModel.DIRECTION.North); break; case "south": Debug.Log("Got go South"); strResult = "Got Go South"; break; default: Debug.Log(" do not know how to go there"); strResult = "Do not know how to go there"; break; } // end switch strResult = GameModel.currentPlayer.CurrentScene.Description; display(strResult); break; default: Debug.Log("Do not understand"); strResult = "Do not understand"; break; } // end switch } // return strResult; } // Parse
public void Parse(String pCmdStr, aDisplayer display) { //List index[0] = text if no SceneObject is present //List index[1] = text after SceneObject is picked up //List index[2] = text if a SceneObject is present String strResult = "Do not understand"; Area lcCurrentArea = GameModel.CurrentPlayer.CurrentArea; char[] charSeparators = new char[] { ' ' }; pCmdStr = pCmdStr.ToLower(); String[] parts = pCmdStr.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); // tokenise the command if (parts.Length > 0) { // process the tokens switch (parts[0]) { //case "pick": // if (parts[1] == "up") // { // Debug.Log("Got Pick up"); // if (GameModel.CurrentPlayer.CurrentScene.SceneObject != null) // { // strResult = GameModel.CurrentPlayer.CurrentScene.LstStoryText[1]; // GameModel.Pickup(GameModel.CurrentPlayer.CurrentScene.SceneObject); // GameModel.RemoveItemFromScene(GameModel.CurrentPlayer.CurrentScene.SceneObject); // } // else // { // strResult = "There is nothing to pick up"; // } // if (parts.Length == 3) // { // String param = parts[2]; // }// do pick up command // } // display(strResult); // break; case "go": GameModel.DIRECTION lcDirection; switch (parts[1]) { case "north": Debug.Log("Got go North"); lcDirection = GameModel.DIRECTION.North; GoDirection(lcCurrentArea, lcDirection); strResult = Arrive(lcCurrentArea, strResult); break; case "south": Debug.Log("Got go South"); lcDirection = GameModel.DIRECTION.South; GoDirection(lcCurrentArea, lcDirection); strResult = Arrive(lcCurrentArea, strResult); break; case "east": Debug.Log("Got go East"); lcDirection = GameModel.DIRECTION.East; GoDirection(lcCurrentArea, lcDirection); strResult = Arrive(lcCurrentArea, strResult); break; case "west": Debug.Log("Got go West"); lcDirection = GameModel.DIRECTION.West; GoDirection(lcCurrentArea, lcDirection); strResult = Arrive(lcCurrentArea, strResult); break; default: Debug.Log(" do not know how to go there"); strResult = "Do not know how to go there"; break; } display(strResult); break; case "show": switch (parts[1]) { case "Game": GameManager.instance.setActiveCanvas("cnvGame"); break; case "inventory": GameManager.instance.setActiveCanvas("cnvInventory"); break; case "map": GameManager.instance.setActiveCanvas("cnvMap"); break; } //call function from scene inherited scene object, two types of scenes // yes/no scene // pickup item scene // yes/no displays different text upon yes or no // pick up simply places item in your inventory array //if (GameManager.instance.activeCanvas == cnvGame) display(strResult); break; default: Debug.Log("Do not understand"); strResult = "Do not understand"; break; }// end switch } // return strResult; }// Parse
public void Parse(String pCmdStr, aDisplayer display) //Making a public method { String strResult = "Do not understand"; //Creating a string variable and giving it the the string "Do not understand" char[] charSeparators = new char[] { ' ' }; //looks for spaces in the entered command pCmdStr = pCmdStr.ToLower(); //transform all characters to lower case in the entered commands String[] parts = pCmdStr.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); //Splitting up the users entered commands into single word values // process the tokens if (parts.Length > 0) { switch (parts[0]) //switch statement { case "pick": //If the first word is 'pick' then perform the code below. if (parts[1] == "up") //If the secound part is 'up' then store the data in the unity log { Debug.Log("Got Pick up"); //Set the unity log value to got pick up strResult = "Got Pick up"; //Set the strResult to got pick up if (parts.Length == 3) { //see if the length is 3 words long String param = parts[2]; // Create a variable named param } // do pick up command // GameModel.Pickup(); } break; //end of the case statement case "go": //if the first word is 'go' then perform the code below switch (parts[1]) //Switch through the secound value { case "north": //If the secound part is north then store the data in the unity log Debug.Log("Got go North"); //set the unity log value to got go north // strResult = "Got Go North"; //set the strResult to got go north GameModel.go(GameModel.DIRECTION.North); //go to the gamemodel and select the direction.north break; //end of case statement for north case "south": //if the secound part is south then store the data in the unity log Debug.Log("Got go South"); //set the unity log value to got go south //strResult = "Got Go South"; //set the strResult to got go south GameModel.go(GameModel.DIRECTION.South); //go to the game model and select the direction.south break; //end of case statement for south case "west": //if the secound part is west then store the data in the unity log Debug.Log("Got go West"); //set the unity log to got go west //strResult = "Got Go West"; //set the strResult to got go west GameModel.go(GameModel.DIRECTION.West); //go to the game model and select the direction.west break; //end of case statement for west case "east": //if the secound part is east the store the data in the unity log Debug.Log("Got go East"); //set the unity log to got go east //strResult = "Got Go East"; //set the strResult to got go east GameModel.go(GameModel.DIRECTION.East); //go to the game model and select the direction.east break; //end of case statement for east default: //if the value does not match, display next piece of code Debug.Log(" do not know how to go there"); //display this message in the unity log strResult = "Do not know how to go there"; //set strResult to do no know how to go there break; //end of statment } // end switch strResult = GameModel.currentPlayer.CurrentScene.Description; display(strResult); //display strResult results break; //end of case statement default: Debug.Log("Do not understand"); //display this message in the unity log strResult = "Do not understand"; //set the strResult to do not understand break; //end of statement }// end switch } // return strResult; } // Parse
public void Parse(String pCmdStr, aDisplayer display) { String strResult = "Do not understand"; char[] charSeparators = new char[] { ' ' }; pCmdStr = pCmdStr.ToLower(); String[] parts = pCmdStr.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); // switch statement is a control statement that selects a switch section to execute from a list of candidates. // switch statement includes one or more switch sections. Each switch section contains one or more case labels followed by one or more statements. // a switch is created that reads parts[0] which is the first part of the text input. 1 is the second part of the input. // a case of "pick" being parts[0] is created which will be used later to define the inventory actions. switch (parts[0]) { case "pick": if (parts[1] == "up") { Debug.Log("Got Pick up"); strResult = "Got Pick up"; if (parts.Length == 3) { String param = parts[2]; } } break; // this here is where I am working on bringing in actions towards NPCs. //case "do": // switch(parts[1]) // { // case "excuse": // Debug.Log("Got Do Excuse"); // GameModel.word(GameModel.WORD.Excuse); // break; // } // break; // here a case of go is created. this handles the directions with the second switch representing the direction that the player has chosen // to go in. (such as north, south, east and west. case "go": switch (parts[1]) { case "north": Debug.Log("Got go North"); GameModel.go(GameModel.DIRECTION.North); break; case "south": Debug.Log("Got go South"); GameModel.go(GameModel.DIRECTION.South); break; case "west": Debug.Log("Got go West"); GameModel.go(GameModel.DIRECTION.West); break; case "east": Debug.Log("Got go East"); GameModel.go(GameModel.DIRECTION.East); break; default: Debug.Log(" do not know how to go there"); strResult = "Do not know how to go there"; break; } strResult = GameModel.currentPlayer.CurrentScene.Description; display(strResult); break; default: Debug.Log("Do not understand"); strResult = "Do not understand"; break; } }