shopdestination.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. function ShopDestination(startx, starty) {
  2. var position = {x : startx, y: starty};
  3. this.isConsumed = false;
  4. var shopInventory = [
  5. {type: "potion", cost: 5},
  6. {type: "weapon1", cost: 10},
  7. {type: "weapon2", cost: 50},
  8. {type: "weapon3", cost: 100},
  9. {type: "weapon4", cost: 250},
  10. {type: "weapon5", cost: 500},
  11. {type: "weapon6", cost: 1000}
  12. ];
  13. var delay = 75;
  14. this.init = function(canvas) {
  15. };
  16. this.update = function(canvas) {
  17. };
  18. this.draw = function(context, offset) {
  19. context.beginPath();
  20. context.strokeStyle = "#8B4513";
  21. context.rect(position.x - 5, position.y - 5, 10, 10);
  22. context.stroke();
  23. };
  24. this.getPosition = function() {
  25. return position;
  26. }
  27. this.visit = function(hero) {
  28. hero.actionDelay(delay);
  29. var itemRequest = hero.shop(shopInventory);
  30. if(itemRequest != null) {
  31. hero.deductCoins(itemRequest.cost);
  32. hero.markMemory(itemRequest.type);
  33. console.log(hero.getName() + " bought " + itemRequest.type + " for " + itemRequest.cost);
  34. switch(itemRequest.type) {
  35. case "weapon1":
  36. case "weapon2":
  37. case "weapon3":
  38. case "weapon4":
  39. case "weapon5":
  40. case "weapon6":
  41. hero.upgradeWeapon();
  42. break;
  43. case "potion":
  44. hero.addHeart(2 * Math.floor(4 * Math.random() + 1) + 2);
  45. break;
  46. }
  47. }
  48. return this;
  49. }
  50. this.getType = function() {
  51. return "shop";
  52. }
  53. this.mouseMove = function(canvas, x, y) {
  54. };
  55. this.getName = function() {
  56. return this.getType();
  57. }
  58. this.getLevel = function() {
  59. return 1;
  60. }
  61. }