SHARE
TWEET

Untitled

a guest Apr 19th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * robotMaze.js
  3.  *
  4.  * The blue key is inside a labyrinth, and extracting
  5.  * it will not be easy.
  6.  *
  7.  * It's a good thing that you're a AI expert, or
  8.  * we would have to leave empty-handed.
  9.  */
  10.  
  11. function startLevel(map) {
  12.     // Hint: you can press R or 5 to "rest" and not move the
  13.     // player, while the robot moves around.
  14.  
  15.     map.getRandomInt = function(min, max) {
  16.         return Math.floor(Math.random() * (max - min + 1)) + min;
  17.     }
  18.  
  19.     map.placePlayer(map.getWidth()-1, map.getHeight()-1);
  20.     var player = map.getPlayer();
  21.  
  22.     map.defineObject('robot', {
  23.         'type': 'dynamic',
  24.         'symbol': 'R',
  25.         'color': 'gray',
  26.         'onCollision': function (player, me) {
  27.             me.giveItemTo(player, 'blueKey');
  28.         },
  29.         'behavior': function (me) {
  30.             map.getPlayer().setPhoneCallback(function () {
  31.         var player = map.getPlayer();
  32. if (player.getColor()=='#f00'){ // red into
  33. player.setColor('#0f0');
  34. return;} // green
  35.  
  36. if (player.getColor()=='#ff0'){ // yellow into
  37. player.setColor('#f00');
  38. return;} // red
  39.  
  40.  
  41.  
  42. if (player.getColor()=='#fff'){ // green into
  43. player.setColor('#ff0');
  44. return;}
  45.  
  46. if (player.getColor()=='#0f0'){ // green into
  47. player.setColor('#fff');
  48. return;} // yellow
  49.     });
  50.  
  51. if (player.getColor()=='#f00'){
  52. me.move('up');} // green=left
  53.  
  54. if (player.getColor()=='#ff0'){
  55. me.move('right')} // red=up
  56.  
  57.  
  58.  
  59. if (player.getColor()=='#fff'){
  60. me.move('down');} //white=down
  61.  
  62. if (player.getColor()=='#0f0'){
  63. me.move('left');} // yellow=right
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.         }
  110.     });
  111.  
  112.     map.defineObject('barrier', {
  113.         'symbol': '░',
  114.         'color': 'purple',
  115.         'impassable': true,
  116.         'passableFor': ['robot']
  117.     });
  118.  
  119.     map.placeObject(0, map.getHeight() - 1, 'exit');
  120.     map.placeObject(1, 1, 'robot');
  121.     map.placeObject(map.getWidth() - 2, 8, 'blueKey');
  122.     map.placeObject(map.getWidth() - 2, 9, 'barrier');
  123.  
  124.     var autoGeneratedMaze = new ROT.Map.DividedMaze(map.getWidth(), 10);
  125.     autoGeneratedMaze.create( function (x, y, mapValue) {
  126.         // don't write maze over robot or barrier
  127.         if ((x == 1 && y == 1) || (x == map.getWidth() - 2 && y >= 8)) {
  128.             return 0;
  129.         } else if (mapValue === 1) { //0 is empty space 1 is wall
  130.             map.placeObject(x,y, 'block');
  131.         } else {
  132.             map.placeObject(x,y,'empty');
  133.         }
  134.     });
  135. }
  136.  
  137. function validateLevel(map) {
  138.     map.validateExactlyXManyObjects(1, 'exit');
  139.     map.validateExactlyXManyObjects(1, 'robot');
  140.     map.validateAtMostXObjects(1, 'blueKey');
  141. }
  142.  
  143. function onExit(map) {
  144.     if (!map.getPlayer().hasItem('blueKey')) {
  145.         map.writeStatus("We need to get that key!");
  146.         return false;
  147.     } else {
  148.         return true;
  149.     }
  150. }
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