Added in some debug commands. Reformatted some Console text. Added in an entry into RetrieveInventory that shows an empty inventory.

This commit is contained in:
Tanner Van Teeffelen 2025-07-10 05:22:45 +00:00
parent b44401c8d7
commit 0d65f1e71f
10 changed files with 28 additions and 19 deletions

22
Main.cs
View file

@ -10,34 +10,22 @@ class Program
List<Item> allItems = ItemLoader.LoadAllItems("data/items.json"); List<Item> allItems = ItemLoader.LoadAllItems("data/items.json");
Player user = new("Tanner", [], 100, 90, 20, 20); Player user = new("Tanner", [], 100, 90, 20, 20);
Console.WriteLine($"{user.Name} has {user.CurrentHealth}/{user.MaxHealth} Hit Points.\n"); user.DisplayStats();
Console.WriteLine($"{user.Name} has {user.CurrentMPoints}/{user.MaxMPoints} Mana Points.\n");
user.Inventory.Add(allItems.FirstOrDefault(m => m.Name == "Potion")); user.Inventory.Add(allItems.FirstOrDefault(m => m.Name == "Potion"));
user.Inventory.Add(allItems.FirstOrDefault(m => m.Name == "Super Potion")); user.Inventory.Add(allItems.FirstOrDefault(m => m.Name == "Super Potion"));
user.Inventory.Add(allItems.FirstOrDefault(m => m.Name == "Hyper Potion")); user.Inventory.Add(allItems.FirstOrDefault(m => m.Name == "Hyper Potion"));
user.Inventory.Add(allItems.FirstOrDefault(m => m.Name == "Elixir")); user.Inventory.Add(allItems.FirstOrDefault(m => m.Name == "Elixir"));
Console.WriteLine($"{user.Name}'s current inventory:");
foreach (var inv in user.RetrieveInventory())
{
Console.WriteLine($"{inv.Key}: {inv.Value}");
}
Console.WriteLine("Do you want to use your Potion? (Y/N)"); Console.WriteLine("Do you want to use your Potion? (Y/N)");
string input = Console.ReadLine().ToUpper(); string? input = Console.ReadLine().ToUpper();
Console.WriteLine("\n");
if (input == "Y") if (input == "Y")
{ {
user.UseHealingItem((HealingItem)user.Inventory.FirstOrDefault(m => m.Name == "Potion")); user.UseHealingItem((HealingItem)user.Inventory.FirstOrDefault(m => m.Name == "Potion"));
user.Inventory.Remove(user.Inventory.FirstOrDefault(m => m.Name == "Potion"));
} }
Console.WriteLine($"{user.Name} has {user.CurrentHealth}/{user.MaxHealth} Hit Points.\n"); user.DisplayStats();
Console.WriteLine($"\n{user.Name}'s current inventory:");
foreach (var inv in user.RetrieveInventory())
{
Console.WriteLine($"{inv.Key}: {inv.Value}");
}
} }
} }

Binary file not shown.

Binary file not shown.

View file

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("MiniRPG")] [assembly: System.Reflection.AssemblyCompanyAttribute("MiniRPG")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8ceb9a2dd8d39872b5e938a69e814fca0b69edd3")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b44401c8d7d108f0c10a5464d7c3d52644511ce0")]
[assembly: System.Reflection.AssemblyProductAttribute("MiniRPG")] [assembly: System.Reflection.AssemblyProductAttribute("MiniRPG")]
[assembly: System.Reflection.AssemblyTitleAttribute("MiniRPG")] [assembly: System.Reflection.AssemblyTitleAttribute("MiniRPG")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View file

@ -1 +1 @@
7baa8b6508c62e19ef199636745e63b875d03ba084ae694d983c02c6913ea1bb c3f2c804e2ee64e4e07e15b987abb29b0956207f6714fc9b00396faa7781a1ea

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -20,6 +20,11 @@ public class Player
//Returns the players inventory in a Dictionary. //Returns the players inventory in a Dictionary.
public Dictionary<string, int> RetrieveInventory() public Dictionary<string, int> RetrieveInventory()
{ {
if (Inventory == null || Inventory.Count == 0)
{
Console.WriteLine("Empty");
return new Dictionary<string, int>();
}
return Inventory return Inventory
.GroupBy(item => item.Name) .GroupBy(item => item.Name)
.ToDictionary(group => group.Key, group => group.Count()); .ToDictionary(group => group.Key, group => group.Count());
@ -34,5 +39,21 @@ public class Player
} else { } else {
CurrentHealth += item.HealingAmount; CurrentHealth += item.HealingAmount;
} }
Inventory.Remove(Inventory.FirstOrDefault(m => m.Name == item.Name));
Console.WriteLine($"Used one {item.Name}. Regained {item.HealingAmount} Health.\n");
}
//#####DEBUG METHODS#####//
//Display stats about the Player.
public void DisplayStats(){
Console.WriteLine($"Player Name: {Name}");
Console.WriteLine($"Health: {CurrentHealth}/{MaxHealth}");
Console.WriteLine($"Mana: {CurrentMPoints}/{MaxMPoints}\n");
Console.WriteLine("Current Inventory: ");
foreach (var inv in RetrieveInventory())
{
Console.WriteLine($"{inv.Key}: {inv.Value}");
}
} }
} }