private GoAction TryToGo(List <Oobject> availlableObjects) { GoAction goAction = null; string direction = sentence.GetDirection(); List <Oobject> objectsToGo = sentence.GetObjectsInSentence(availlableObjects); switch (direction) { case Sentence.DIRECTION_NOT_EXISTING: if (objectsToGo.Count == 1) { goAction = new GoAction(player, world, objectsToGo[0]); } else if (objectsToGo.Count > 1) { requestNewSentenceAndTellsProblem(sayWhereDoYouWantToGo); } else { requestNewSentenceAndTellsProblem(sayNoDirectionFound); } break; case Sentence.TOO_MANY_DIRECTIONS: requestNewSentenceAndTellsProblem(sayTooManyDirections); break; default: goAction = new GoAction(player, world, direction); break; } return(goAction); }
public Action GetAction(List <Oobject> availlableObjects, Sentence fullSentence) { bool sentenceUnderstood = false; string playerInput; sentence = fullSentence; while (!sentenceUnderstood) { String[] verbs = sentence.GetVerbs(); if (verbs.Length > 1) { requestNewSentenceAndTellsProblem(sayTooManyVerbs); } else if (verbs.Length < 1) { requestNewSentenceAndTellsProblem(sayNoVerbFound); } else { string verb = verbs[0]; switch (verb) { case Go.ROOTVERB: GoAction goAction = TryToGo(availlableObjects); if (goAction != null) { return(goAction); } break; case Quit.ROOTVERB: if (sentence.IsEmpty()) { return(null); } else { requestNewSentenceAndTellsProblem(sayIfYouWantToQuit); } break; default: break; } } } return(null); }