Skip to content

Instantly share code, notes, and snippets.

@ajcomeau
Created December 18, 2025 04:20
Show Gist options
  • Select an option

  • Save ajcomeau/802f60046b51488388f5f3cff3ccdf03 to your computer and use it in GitHub Desktop.

Select an option

Save ajcomeau/802f60046b51488388f5f3cff3ccdf03 to your computer and use it in GitHub Desktop.
Eat function from Rogue C#
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