SHARE
TWEET

Untitled

a guest May 25th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 PX = map.getPlayer().getX();
  36.     var PY = map.getPlayer().getY()-10;
  37.     var MX = me.getX();
  38.     var MY = me.getY();
  39.    
  40.     if (PX == MX && PY > MY) {
  41.         me.move('down');
  42.     }
  43.     else if (PX == MX && PY <= MY) {
  44.         me.move('up');
  45.     }
  46.     else if (PX > MX) {
  47.           me.move('right');
  48.     }
  49.     else if (PX < MX) {
  50.         me.move('left');
  51.     }
  52.         }
  53.     });
  54.  
  55.     map.defineObject('barrier', {
  56.         'symbol': '░',
  57.         'color': 'purple',
  58.         'impassable': true,
  59.         'passableFor': ['robot']
  60.     });
  61.  
  62.     map.placeObject(0, map.getHeight() - 1, 'exit');
  63.     map.placeObject(1, 1, 'robot');
  64.     map.placeObject(map.getWidth() - 2, 8, 'redKey');
  65.     map.placeObject(map.getWidth() - 2, 9, 'barrier');
  66.  
  67.     for (var x = 0; x < map.getWidth(); x++) {
  68.         map.placeObject(x, 0, 'block');
  69.         if (x != map.getWidth() - 2) {
  70.             map.placeObject(x, 9, 'block');
  71.         }
  72.     }
  73.  
  74.     for (var y = 1; y < 9; y++) {
  75.         map.placeObject(0, y, 'block');
  76.         map.placeObject(map.getWidth() - 1, y, 'block');
  77.     }
  78. }
  79.  
  80. function validateLevel(map) {
  81.     map.validateExactlyXManyObjects(1, 'exit');
  82.     map.validateExactlyXManyObjects(1, 'robot');
  83.     map.validateAtMostXObjects(1, 'redKey');
  84. }
  85.  
  86. function onExit(map) {
  87.     if (!map.getPlayer().hasItem('redKey')) {
  88.         map.writeStatus("We need to get that key!");
  89.         return false;
  90.     } else {
  91.         return true;
  92.     }
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top