123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- function ShopDestination(startx, starty) {
- var position = {x : startx, y: starty};
- this.isConsumed = false;
- var shopInventory = [
- {type: "potion", cost: 5},
- {type: "weapon1", cost: 10},
- {type: "weapon2", cost: 50},
- {type: "weapon3", cost: 100},
- {type: "weapon4", cost: 250},
- {type: "weapon5", cost: 500},
- {type: "weapon6", cost: 1000}
- ];
- var delay = 75;
- this.init = function(canvas) {
- };
- this.update = function(canvas) {
- };
- this.draw = function(context, offset) {
- context.beginPath();
- context.strokeStyle = "#8B4513";
- context.rect(position.x - 5, position.y - 5, 10, 10);
- context.stroke();
- };
- this.getPosition = function() {
- return position;
- }
- this.visit = function(hero) {
- hero.actionDelay(delay);
- var itemRequest = hero.shop(shopInventory);
- if(itemRequest != null) {
- hero.deductCoins(itemRequest.cost);
- hero.markMemory(itemRequest.type);
- console.log(hero.getName() + " bought " + itemRequest.type + " for " + itemRequest.cost);
- switch(itemRequest.type) {
- case "weapon1":
- case "weapon2":
- case "weapon3":
- case "weapon4":
- case "weapon5":
- case "weapon6":
- hero.upgradeWeapon();
- break;
- case "potion":
- hero.addHeart(2 * Math.floor(4 * Math.random() + 1) + 2);
- break;
- }
- }
- return this;
- }
- this.getType = function() {
- return "shop";
- }
- this.mouseMove = function(canvas, x, y) {
- };
- this.getName = function() {
- return this.getType();
- }
- this.getLevel = function() {
- return 1;
- }
- }
|