Guest User

Untitled

a guest
May 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 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. if(me.canMove('right')){me.move('right')}
  36. if(me.canMove('down')){me.move('down')}
  37. // Available commands: me.move(direction)
  38. // and me.canMove(direction)
  39.  
  40.  
  41.  
  42. }
  43. });
  44.  
  45. map.defineObject('barrier', {
  46. 'symbol': '░',
  47. 'color': 'purple',
  48. 'impassable': true,
  49. 'passableFor': ['robot']
  50. });
  51.  
  52. map.placeObject(0, map.getHeight() - 1, 'exit');
  53. map.placeObject(1, 1, 'robot');
  54. map.placeObject(map.getWidth() - 2, 8, 'redKey');
  55. map.placeObject(map.getWidth() - 2, 9, 'barrier');
  56.  
  57. for (var x = 0; x < map.getWidth(); x++) {
  58. map.placeObject(x, 0, 'block');
  59. if (x != map.getWidth() - 2) {
  60. map.placeObject(x, 9, 'block');
  61. }
  62. }
  63.  
  64. for (var y = 1; y < 9; y++) {
  65. map.placeObject(0, y, 'block');
  66. map.placeObject(map.getWidth() - 1, y, 'block');
  67. }
  68. }
  69.  
  70. function validateLevel(map) {
  71. map.validateExactlyXManyObjects(1, 'exit');
  72. map.validateExactlyXManyObjects(1, 'robot');
  73. map.validateAtMostXObjects(1, 'redKey');
  74. }
  75.  
  76. function onExit(map) {
  77. if (!map.getPlayer().hasItem('redKey')) {
  78. map.writeStatus("We need to get that key!");
  79. return false;
  80. } else {
  81. return true;
  82. }
  83. }
Add Comment
Please, Sign In to add comment