Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. /*
  2. * robot.js
  3. *
  4. * You'll need three keys in order to unlock the
  5. * Algorithm: the red key, the green key, and the
  6. * blue key. Unfortunately, all three of them are
  7. * behind human-proof barriers.
  8. *
  9. * The plan is simple: reprogram the maintenance
  10. * robots to grab the key and bring it through
  11. * the barrier to us.
  12. *
  13. * Let's try it on the red key first.
  14. */
  15.  
  16. function getRandomInt(min, max) {
  17. return Math.floor(Math.random() * (max - min + 1)) + min;
  18. }
  19.  
  20. function startLevel(map) {
  21. // Hint: you can press R or 5 to "rest" and not move the
  22. // player, while the robot moves around.
  23.  
  24. map.placePlayer(map.getWidth()-2, map.getHeight()-2);
  25. var player = map.getPlayer();
  26.  
  27. map.defineObject('robot', {
  28. 'type': 'dynamic',
  29. 'symbol': 'R',
  30. 'color': 'gray',
  31. 'onCollision': function (player, me) {
  32. me.giveItemTo(player, 'redKey');
  33. },
  34. 'behavior': function (me) {
  35. // Available commands: me.move(direction)
  36. // and me.canMove(direction)
  37. if (player.atLocation(40-1, 20)) {
  38. me.move('left');
  39. }
  40. if (player.atLocation(40+1, 20)) {
  41. me.move('right');
  42. }
  43. if (player.atLocation(40, 20+1)) {
  44. me.move('down');
  45. }
  46. if (player.atLocation(40, 20-1)) {
  47. me.move('up');
  48. }
  49.  
  50.  
  51.  
  52.  
  53. }
  54. });
  55.  
  56.  
  57.  
  58.  
  59.  
  60. map.defineObject('v', {
  61. 'type': 'dynamic',
  62. 'symbol': 'v',
  63. 'color': 'red',
  64. 'onCollision': function (player, me) {
  65. player.setColor('#0ff');
  66. },
  67. });
  68.  
  69.  
  70. map.defineObject('>', {
  71. 'type': 'dynamic',
  72. 'symbol': '>',
  73. 'color': 'red'
  74. });
  75. map.defineObject('^', {
  76. 'type': 'dynamic',
  77. 'symbol': '^',
  78. 'color': 'red'
  79. });
  80. map.defineObject('<', {
  81. 'type': 'dynamic',
  82. 'symbol': '<',
  83. 'color': 'red'
  84. });
  85.  
  86. map.placeObject(40-1, 20, '<');
  87. map.placeObject(40+1, 20, '>');
  88. map.placeObject(40, 20+1, 'v');
  89. map.placeObject(40, 20-1, '^');
  90.  
  91. map.defineObject('X', {
  92. 'type': 'dynamic',
  93. 'symbol': 'X',
  94. 'color': 'red',
  95.  
  96. 'behavior': function (me) {
  97.  
  98.  
  99. }
  100. });
  101.  
  102. map.defineObject('barrier', {
  103. 'symbol': '░',
  104. 'color': 'purple',
  105. 'impassable': true,
  106. 'passableFor': ['robot']
  107. });
  108.  
  109. map.placeObject(0, map.getHeight() - 1, 'exit');
  110. map.placeObject(1, 1, 'robot');
  111. map.placeObject(map.getWidth() - 2, 8, 'redKey');
  112. map.placeObject(map.getWidth() - 2, 9, 'barrier');
  113.  
  114. for (var x = 0; x < map.getWidth(); x++) {
  115. map.placeObject(x, 0, 'block');
  116. if (x != map.getWidth() - 2) {
  117. map.placeObject(x, 9, 'block');
  118. }
  119. }
  120.  
  121. for (var y = 1; y < 9; y++) {
  122. map.placeObject(0, y, 'block');
  123. map.placeObject(map.getWidth() - 1, y, 'block');
  124. }
  125. }
  126.  
  127. function validateLevel(map) {
  128. map.validateExactlyXManyObjects(1, 'exit');
  129. map.validateExactlyXManyObjects(1, 'robot');
  130. map.validateAtMostXObjects(1, 'redKey');
  131. }
  132.  
  133. function onExit(map) {
  134. if (!map.getPlayer().hasItem('redKey')) {
  135. map.writeStatus("We need to get that key!");
  136. return false;
  137. } else {
  138. return true;
  139. }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement