Guest User

Untitled

a guest
Jun 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 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. var player = map.getPlayer();
  36. if (player.getColor()==="#f00")
  37. me.move('left');
  38. else
  39. if (player.getColor()==="#0f0")
  40. me.move('down');
  41. else
  42. if (player.getColor()==="#ff0")
  43. me.move('right');
  44. else
  45. if (player.getColor()==="#f0f")
  46. me.move('up');
  47.  
  48.  
  49.  
  50. }
  51. });
  52.  
  53.  
  54.  
  55. map.getPlayer().setPhoneCallback(function () {
  56. var player = map.getPlayer();
  57. if (player.getColor()==="#f00")
  58. player.setColor("#0f0");
  59. else
  60. if (player.getColor()==="#0f0")
  61. player.setColor("#ff0");
  62. else
  63. if (player.getColor()==="#ff0")
  64. player.setColor("#f0f");
  65. else
  66. if (player.getColor()==="#f0f")
  67. player.setColor("#f00");
  68.  
  69.  
  70.  
  71.  
  72. {
  73.  
  74.  
  75. }
  76. });
  77.  
  78. map.defineObject('barrier', {
  79. 'symbol': '░',
  80. 'color': 'purple',
  81. 'impassable': true,
  82. 'passableFor': ['robot']
  83. });
  84.  
  85. map.placeObject(0, map.getHeight() - 1, 'exit');
  86. map.placeObject(1, 1, 'robot');
  87. map.placeObject(map.getWidth() - 2, 8, 'redKey');
  88. map.placeObject(map.getWidth() - 2, 9, 'barrier');
  89.  
  90. for (var x = 0; x < map.getWidth(); x++) {
  91. map.placeObject(x, 0, 'block');
  92. if (x != map.getWidth() - 2) {
  93. map.placeObject(x, 9, 'block');
  94. }
  95. }
  96.  
  97. for (var y = 1; y < 9; y++) {
  98. map.placeObject(0, y, 'block');
  99. map.placeObject(map.getWidth() - 1, y, 'block');
  100. }
  101. }
  102.  
  103. function validateLevel(map) {
  104. map.validateExactlyXManyObjects(1, 'exit');
  105. map.validateExactlyXManyObjects(1, 'robot');
  106. map.validateAtMostXObjects(1, 'redKey');
  107. }
  108.  
  109. function onExit(map) {
  110. if (!map.getPlayer().hasItem('redKey')) {
  111. map.writeStatus("We need to get that key!");
  112. return false;
  113. } else {
  114. return true;
  115. }
  116. }
Add Comment
Please, Sign In to add comment