-
-
Save ajcomeau/802f60046b51488388f5f3cff3ccdf03 to your computer and use it in GitHub Desktop.
Eat function from Rogue C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private bool Eat(char? ListItem) | |
| { | |
| bool retValue = false; | |
| List<Inventory> items; | |
| if (!InvDisplay) | |
| { | |
| // Verify the player has something they can eat. | |
| items = (from inv in CurrentPlayer.PlayerInventory | |
| where inv.ItemCategory == Inventory.InvCategory.Food | |
| select inv).ToList(); | |
| if (items.Count > 0) | |
| { | |
| // If there's something edible, show the inventory | |
| // and let the player select it. Set to return and exit. | |
| DisplayInventory(); | |
| cStatus = "Please select something to eat."; | |
| ReturnFunction = Eat; | |
| } | |
| else | |
| // Otherwise, they'll be hungry for awhile. | |
| cStatus = "You don't have anything to eat."; | |
| } | |
| else | |
| { | |
| // Get the selected item. | |
| items = (from InventoryLine in | |
| Inventory.InventoryDisplay(CurrentPlayer.PlayerInventory) | |
| where InventoryLine.ID == ListItem | |
| select InventoryLine.InvItem).ToList(); | |
| if (items.Count > 0) | |
| { | |
| // Call the appropriate delegate and remove the item | |
| // from inventory. | |
| items[0].MainFunction(CurrentPlayer, items[0]); | |
| CurrentPlayer.PlayerInventory.Remove(items[0]); | |
| RestoreMap(); | |
| retValue = true; | |
| } | |
| else | |
| { | |
| // Process non-existent option. | |
| cStatus = "Please select something to eat."; | |
| RestoreMap(); | |
| retValue = false; | |
| } | |
| } | |
| return retValue; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment