shop.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* handles shop values and prices */
  2. class Shop {
  3. /* initialize */
  4. constructor() {
  5. /* data types */
  6. this.SPAWN_SPEED = 0;
  7. this.SPAWN_VALUE = 1;
  8. this.COLLECTORS = 2;
  9. this.COLLECTOR_SPEED = 3;
  10. this.SPAWN_LIMIT = 4;
  11. /* counters of current levels */
  12. this.counters = [0, 0, 0, 0, 0];
  13. /* prices to buy levels */
  14. this.prices = [5, 15, 27, 41, 58, 70, 93, 120];
  15. /* actual data sorted like data types */
  16. this.data = [
  17. [120, 60, 35, 22, 15, 10, 9, 7, 6],
  18. [1, 2, 3, 5, 7, 10, 13, 16, 20],
  19. [0, 1, 2, 4, 6, 9, 13, 16, 20],
  20. [180, 168, 156, 138, 129, 120, 105, 90, 60],
  21. [10, 15, 20, 25, 30, 35, 40, 45, 50],
  22. ];
  23. } /* constructor */
  24. /* return current level data,
  25. * offset is used to display data of previous/next levels
  26. * -1 is previous level, +1 is next level etc
  27. */
  28. get_data(data_type, counter_offset = 0) {
  29. return this.data[data_type][
  30. this.counters[data_type]+counter_offset
  31. ];
  32. }
  33. /* increase the level of specified data type
  34. * in the case of collectors, return how many
  35. * new collectors to create
  36. */
  37. increase_data(data_type) {
  38. /* check for level limit */
  39. if (this.counters[data_type] < 8) {
  40. /* increase level */
  41. this.counters[data_type]++;
  42. /* return new collectors to create */
  43. if (data_type == this.COLLECTORS) {
  44. return this.get_data(this.COLLECTORS)
  45. -this.get_data(this.COLLECTORS, -1);
  46. }
  47. } /* level limit */
  48. } /* increase level */
  49. /* return the level itself of speified data type */
  50. get_counter(data_type) {
  51. return this.counters[data_type];
  52. }
  53. /* return cost of next level of data type */
  54. cost(data_type) {
  55. return this.prices[ this.counters[data_type] ];
  56. }
  57. } /* shop */