I'm creating a JavaScript game, and I'm getting stuck. When the player obtains X amount of gold, a middle column appears (you've unlocked the shop, yay!), and when you obtain more gold than an item costs, it will appear (except special conditions where it requires more than just gold of course).
Right now, I'm stuck on the base foundation of the system, and I would like to hear some suggestions before I move on.
function _shop() {
this.items = [
{
effect : function() { engine.player.revive(true); },
"price" : 100,
"name" : "Heal"
}
];
}
The shop holds an array of item objects, some will be holdable, some will be instant use (currently working on instant use).
Now, here's how the item is called:
in my elements.js file --
addShopItem : function(gold) {
console.log(engine.shop.items.length);
for (var i = 0; i < engine.shop.items.length; i++) {
if (engine.shop.items[i]["price"] <= gold) {
document.getElementById("items").innerHTML += "<br />"+engine.shop.items[i].name;
}
}
},
Which is called by going raiding (irrelevant, won't post that code, it's going to change to the engine's trigger function with flags based on the item object.
Now my question is:
- Is this a good way to handle an dynamic shop system?
- What's the best way to link this to a player object? (My initial guess is an object
inventory
inside the parent?