Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. function AbstractUpgrade(name, price = 0, requiredUpgrades = new Array()) {
  2. this.name = name;
  3. this.price = price;
  4. this.requiredUpgrades = requiredUpgrades;
  5. this.lock = true;
  6.  
  7. this.unlock = function() {
  8. // Vérifie si le joueur dispose de la somme nécessaire pour débloquer cette amélioration
  9. if (game.getPlayer().getBalance() < price) {
  10. return;
  11. }
  12.  
  13. // Vérifie si toutes les améliorations nécessaires ont été débloquées
  14. for (var i = 0; i < requiredUpgrades.length; i++) {
  15. if (requiredUpgrades[i].isLocked()) {
  16. return;
  17. }
  18. }
  19.  
  20. this.doAction();
  21.  
  22. this.lock = false;
  23. }
  24.  
  25. this.doAction = function() {
  26. // à redéfinir
  27. }
  28.  
  29. this.getName = function() {
  30. return this.name;
  31. }
  32.  
  33. this.isLocked = function() {
  34. return this.lock;
  35. }
  36.  
  37. }
  38.  
  39. /* Objets héritant de AbstractUpgrade */
  40.  
  41. function EnrollmentUpgrade() {}
  42. function BluePrintUpgrade() {}
  43. function KnowledgeTransferUpgrade() {}
  44.  
  45. function SuperPumpUpgrade() {
  46. this.doAction = function() {
  47. game.getPlayer().setCurrentProduction(2);
  48. }
  49. }
  50.  
  51. function MegaPumpUpgrade() {
  52. this.doAction = function() {
  53. game.getPlayer().setCurrentProduction(5);
  54. }
  55. }
  56.  
  57. function GigaPumpUpgrade() {
  58. this.doAction = function() {
  59. game.getPlayer().setCurrentProduction(10);
  60. }
  61. }
  62.  
  63. /* Prototyping */
  64. EnrollmentUpgrade.prototype = new AbstractUpgrade();
  65. BluePrintUpgrade.prototype = new AbstractUpgrade();
  66. KnowledgeTransferUpgrade.prototype = new AbstractUpgrade();
  67. SuperPumpUpgrade.prototype = new AbstractUpgrade();
  68. MegaPumpUpgrade.prototype = new AbstractUpgrade();
  69. GigaPumpUpgrade.prototype = new AbstractUpgrade();
  70.  
  71. /* Initialisation */
  72. var enrollmentUpgrade = new EnrollmentUpgrade("upgrade_enrollment", 20);
  73. var bluePrintUpgrade = new BluePrintUpgrade("upgrade_blue_print", 200);
  74. var knowledgeTransferUpgrade = new KnowledgeTransferUpgrade("upgrade_knowledge_transfer", 2000);
  75. var superPumpUpgrade = new SuperPumpUpgrade("upgrade_super_pump", 100);
  76. var megaPumpUpgrade = new MegaPumpUpgrade("upgrade_mega_pump", 1000, [superPumpUpgrade]);
  77. var gigaPumpUpgrade = new GigaPumpUpgrade("upgrade_giga_pump", 10000 [megaPumpUpgrade]);
  78.  
  79. const UPGRADES = [enrollmentUpgrade, bluePrintUpgrade, knowledgeTransferUpgrade, superPumpUpgrade, megaPumpUpgrade, gigaPumpUpgrade];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement