using System.Collections.Generic;
public static bool GameRunning = true;
public static void Main()
Junk_Code.QuickInventory();
Junk_Code.Merch_QuickInventory();
public static class Inventory
public static List<Item> items = new List<Item>();
public static int money = 0;
public static void Add_Item(string name, int quantity, int _value)
foreach (Item i in items)
i.itemQuantity += quantity;
items.Add(new Item(name, quantity, _value));
public static void Add_Item(Item item, int quantity)
foreach (Item i in items)
if (i.itemName == item.itemName)
i.itemQuantity += quantity;
items.Add(new Item(item.itemName, quantity, item.itemValue));
public static void Remove_Item(string name, int quantity)
foreach (Item i in items)
if (i.itemQuantity >= quantity)
i.itemQuantity -= quantity;
public static void Print_Inventory()
Sort_By_Item_Name sbin = new Sort_By_Item_Name();
Console.WriteLine("Current money: $" + money);
foreach (Item i in items)
Console.WriteLine(counter + ": " + i.itemName + ":(" + i.itemQuantity + ") $" + i.itemValue + "(each)");
private static int number;
private static string numStr;
private static bool _continue = true;
public static void View_Menu()
Sell_Item.freshEnter = true;
Sell_Item._continue = true;
Console.WriteLine("1. Sell Menu");
Console.WriteLine("2. Buy Menu");
Console.WriteLine("3. Exit game");
Console.WriteLine("\n Type number:");
numStr = Console.ReadLine();
if (Int32.TryParse(numStr, out number))
Merchant_Inventory.Print_Inventory();
Console.WriteLine("Goodbye");
Program.GameRunning = false;
public static class Sell_Item
private static int numForName;
private static string numStrName;
private static int numForQuantity;
private static string numStrQuant;
public static bool _continue = true;
public static bool freshEnter = true;
public static void Sell()
Inventory.Print_Inventory();
Console.WriteLine((Inventory.items.Count + 1) + ". Exit");
Console.WriteLine("Enter the number of the item to sell:");
numStrName = Console.ReadLine();
if (Int32.TryParse(numStrName, out numForName))
if (numForName + 1 == Inventory.items.Count + 1)
if (numForName < Inventory.items.Count && numForName > -1)
Console.Write("Selling " + Inventory.items[numForName].itemName);
if (Inventory.items[numForName].itemQuantity > 1)
Console.Write("s." + "\n");
Console.Write("." + "\n");
if (Inventory.items[numForName].itemQuantity > 1)
Console.WriteLine("Out of " + Inventory.items[numForName].itemQuantity + ", how many do you want to sell?");
numStrQuant = Console.ReadLine();
Int32.TryParse(numStrQuant, out numForQuantity);
if (numForQuantity > 0 && numForQuantity <= Inventory.items[numForName].itemQuantity)
Console.Write("Sold " + numForQuantity + " " + Inventory.items[numForName].itemName);
Console.Write("s." + "\n");
Console.Write("." + "\n");
Inventory.money += (Inventory.items[numForName].itemValue * numForQuantity);
Inventory.Remove_Item(Inventory.items[numForName].itemName, numForQuantity);
Console.WriteLine("New Inventory: \n");
Console.WriteLine("Sold the " + Inventory.items[numForName].itemName + ".");
Inventory.money += Inventory.items[numForName].itemValue;
Inventory.Remove_Item(Inventory.items[numForName].itemName, 1);
Console.WriteLine("New Inventory: \n");
Console.WriteLine("Invalid entry \n");
public static class Buy_Item
public class Item : IComparable<Item>
public Item(string name, int quantity, int _val)
public int CompareTo(Item i)
return this.itemQuantity.CompareTo(i.itemQuantity);
public class Sort_By_Item_Name : IComparer<Item>
public int Compare(Item x, Item y)
return x.itemName.CompareTo(y.itemName);
public static class Merchant_Inventory
public static List<Item> items = new List<Item>();
public static int money = 0;
public static void Add_Item(string name, int quantity, int _value)
foreach (Item i in items)
i.itemQuantity += quantity;
items.Add(new Item(name, quantity, _value));
public static void Add_Item(Item item, int quantity)
foreach (Item i in items)
if (i.itemName == item.itemName)
i.itemQuantity += quantity;
items.Add(new Item(item.itemName, quantity, item.itemValue));
public static void Remove_Item(string name, int quantity)
foreach (Item i in items)
if (i.itemQuantity >= quantity)
i.itemQuantity -= quantity;
public static void Print_Inventory()
Sort_By_Item_Name sbin = new Sort_By_Item_Name();
Console.WriteLine("Current money: $" + money);
foreach (Item i in items)
Console.WriteLine(counter + ": " + i.itemName + ":(" + i.itemQuantity + ") $" + i.itemValue + "(each)");
public static class Junk_Code
public static void QuickInventory()
Inventory.Add_Item(All_Items.allItems[0], 5);
Inventory.Add_Item(All_Items.allItems[1], 1);
Inventory.Add_Item(All_Items.allItems[3], 7);
Inventory.Add_Item(All_Items.allItems[2], 3);
Console.WriteLine("Player inventory build done");
public static void Merch_QuickInventory()
Random rand = new Random();
int numOfItems = rand.Next(2,5);
for(int x = 0; x < numOfItems; x++){
quantOfItems = rand.Next(1, 8);
numOfItemName = rand.Next(0, All_Items.allItems.Count);
Merchant_Inventory.items.Add(new Item(All_Items.allItems[numOfItemName].itemName, quantOfItems, All_Items.allItems[numOfItemName].itemValue));
Console.WriteLine("Merchant build done");
public static class All_Items
public static List<Item> allItems = new List<Item>();
public static void Build_Items()
allItems.Add(new Item("Carrot", 1, 3));
allItems.Add(new Item("Banana", 1, 5));
allItems.Add(new Item("Pizza", 1, 15));
allItems.Add(new Item("Salmon", 1, 12));
allItems.Add(new Item("Artichoke", 1, 7));
allItems.Add(new Item("Broccoli", 1, 3));
Console.WriteLine("Item build done");