In my class, PlayerInventory i have a method called buy and sell. i have an int in the parameter called statItem. It is to be used as a place holder for items in my object player.
public void Buy(PlayerStats player, string myName, int myItem, int statItem)
{
Console.WriteLine("{0} Costs {1:C} per unit.", myName, myItem);
int MaxPurchase = player.Money / myItem;
Console.WriteLine("You can afford {0} units.", MaxPurchase);
Console.WriteLine("How many units would you like to purchase?");
string Purchasex = Console.ReadLine();
int ammount = int.Parse(Purchasex);
player.Money -= (myItem * ammount);
statItem += ammount;
Console.WriteLine("You have Purchased {0} units at {1:C} per unit.", ammount, myItem);
Console.ReadLine();
}
In the method BuyMerchandise/SellMerchandise i have a switch and i replaced the statItem parameter with player.LuxuryWatches, player.LuxuryHandbags etc.
Console.WriteLine("What would you like to purchase? \n");
ViewInventory(player);
switch (GetChoice())
{
case "1":
Price(player);
Buy(player, "Luxury Watches", _LuxuryWatches, player.LuxuryWatches);
break;
case "2":
Price(player);
Buy(player, "Luxury Handbags", _LuxuryHandbags, player.LuxuryHandbags);
break;
This is not passing the value back to thevariablein the player object.
If i replace statItem with player.LuxuryWatch for example it does pass the value back to the object. But i would prefer to use a parameter so i can use one method and change the parameter for each one of the ten items.
public void Buy(PlayerStats player, string myName, int myItem)
{
Console.WriteLine("{0} Costs {1:C} per unit.", myName, myItem);
int MaxPurchase = player.Money / myItem;
Console.WriteLine("You can afford {0} units.", MaxPurchase);
Console.WriteLine("How many units would you like to purchase?");
string Purchasex = Console.ReadLine();
int ammount = int.Parse(Purchasex);
player.Money -= (myItem * ammount);
player.LuxuryWatches += ammount;
Console.WriteLine("You have Purchased {0} units at {1:C} per unit.", ammount, myItem);
Console.ReadLine();
}