private void FishAction() { // get location int location = _gameSurvivor.IslandLocationID; // get fish in that location, if any List <SurvivorObject> fishesInLocation = new List <SurvivorObject>(); List <GameObject> objectsInLocation = _gameUniverse.GetGameObjectsByIslandLocationId(location); foreach (GameObject gameObject in objectsInLocation) { if (gameObject is SurvivorObject) { SurvivorObject survivorObject = gameObject as SurvivorObject; if (survivorObject.Type == SurvivorObjectType.Fish) { fishesInLocation.Add(survivorObject); } } } // randomly chose a fish if (fishesInLocation.Count() != 0) { int numOfFishes = fishesInLocation.Count(); int fishId; if (numOfFishes > 1) { Random rnd = new Random(); fishId = rnd.Next(1, numOfFishes); } else { fishId = 0; } SurvivorObject caughtFish = _gameUniverse.GetGameObjectById(fishesInLocation[fishId].Id) as SurvivorObject; // // note: survivor object is added to list and the island location is set to 0 // _gameSurvivor.Inventory.Add(caughtFish); caughtFish.IslandLocationId = 0; // // update experience points, health, and lives // _gameSurvivor.ExperiencePoints += caughtFish.ExperiencePoints; _gameSurvivor.Health += caughtFish.HealthPoints; _gameSurvivor.Lives += caughtFish.Lives; // // display confirmation message // _gameConsoleView.DisplayConfirmSurvivorObjectAddedToInventory(caughtFish); } else if (fishesInLocation.Count() == 0) { _gameConsoleView.DisplayFishingErrorMessage(); } }
public int DisplayGetGameObjectToLookAt() { int gameObjectId = 0; bool validGameObjectId = false; // // get a list of game onjects in the current space-time location // List <GameObject> gameObjectsInIslandLocation = _gameUniverse.GetGameObjectsByIslandLocationId(_gameSurvivor.IslandLocationID); if (gameObjectsInIslandLocation.Count > 0) { DisplayGamePlayScreen("Look at a Object", Text.GameObjectsChooseList(gameObjectsInIslandLocation), ActionMenu.ObjectMenu, ""); while (!validGameObjectId) { // // get an integer from the player // GetInteger($"Enter the Id number of the object you wish to look at: ", 0, 0, out gameObjectId); // // validate integer as a valid game object id and in current location // if (_gameUniverse.IsValidGameObjectByLocationId(gameObjectId, _gameSurvivor.IslandLocationID)) { validGameObjectId = true; } else { ClearInputBox(); DisplayInputErrorMessage("It appears you entered an invalid game object id. Please try again."); } } } else { ClearInputBox(); DisplayGamePlayScreen("Look at a Object", "It appears there are no game objects here.", ActionMenu.ObjectMenu, ""); } return(gameObjectId); }