list - C# Crafting Logic -
there many similar questions none definitive answer. using unity3d engine create game. have set inventory system methods add items, remove items , check if inventory contains amount of item.
what want on every update, loop through items , if player has required items crafting recipe, show add button list player can click on craft new item.
i thought use dictionary store items , quantities needed. this:
public static dictionary<string, int> sword = new dictionary<string, int>() { {"stone", 2}, {"wood", 1} }; public static dictionary<string, int> plank = new dictionary<string, int>() { {"wood", 5} };
but need way store of recipes , loop through them. dictionary of dictionaries. loop through of crafting item names. can similar this?
public static dictionary<string, dictionary> recipes = new dictionary<string, int>() { {"wood sword", sword}, {"wood plank", plank} };
i want able define recipes in 1 class file , loop through them in another.
i don't have experience c# not @ using lists , dictionaries appreciate suggestions , help.
thanks!
well.. coming specs came this:
public enum ingredient = { wood, stone, water, gold/*and on*/ }; public class recipeitem { public ingredient ingredient{ get; set;} public int amount {get; set;} } public class recipe { public string name {get; set;} public list<recipeitem> recipeitems {get;set;} }
somewhere in code when defining recipes:
var recipes = new list<recipe>(){ new recipe(){ name = "wood sword", recipeitems = new list<recipeitem>(){ new recipeitem(){ ingredient = wood, amount = 1 }, new recipeitem(){ ingredient = stone, amount = 5 } } }, new recipe(){ name = "plank", recipeitems = new list<recipeitem>(){ new recipeitem(){ ingredient = wood, amount = 5 } } } // more recipes };
ps: recommend spend few days on learning basics of c#
Comments
Post a Comment