SHARE
TWEET

Untitled

a guest Mar 19th, 2019 60 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.             var moves = map.getAdjacentEmptyCells(me.getX(), me.getY());
  31.             // getAdjacentEmptyCells gives array of ((x, y), direction) pairs
  32.            
  33.             if (player.getX() < map.getWidth() - 2)
  34.             {
  35.                 me.move('left');
  36.             }
  37.             if (player.getX() > map.getWidth() - 2)
  38.             {
  39.                 me.move('right');
  40.             }
  41.             if (player.getY() < map.getHeight() - 2)
  42.             {
  43.                 me.move('up');
  44.             }
  45.             if (player.getY() > map.getHeight() - 2)
  46.             {
  47.                 me.move('down');
  48.             }
  49.            
  50.            
  51.  
  52.  
  53.  
  54.         }
  55.     });
  56.  
  57.     map.defineObject('barrier', {
  58.         'symbol': '░',
  59.         'color': 'purple',
  60.         'impassable': true,
  61.         'passableFor': ['robot']
  62.     });
  63.  
  64.     map.placeObject(0, map.getHeight() - 1, 'exit');
  65.     map.placeObject(1, 1, 'robot');
  66.     map.placeObject(map.getWidth() - 2, 8, 'blueKey');
  67.     map.placeObject(map.getWidth() - 2, 9, 'barrier');
  68.  
  69.     var autoGeneratedMaze = new ROT.Map.DividedMaze(map.getWidth(), 10);
  70.     autoGeneratedMaze.create( function (x, y, mapValue) {
  71.         // don't write maze over robot or barrier
  72.         if ((x == 1 && y == 1) || (x == map.getWidth() - 2 && y >= 8)) {
  73.             return 0;
  74.         } else if (mapValue === 1) { //0 is empty space 1 is wall
  75.             map.placeObject(x,y, 'block');
  76.         } else {
  77.             map.placeObject(x,y,'empty');
  78.         }
  79.     });
  80. }
  81.  
  82. function validateLevel(map) {
  83.     map.validateExactlyXManyObjects(1, 'exit');
  84.     map.validateExactlyXManyObjects(1, 'robot');
  85.     map.validateAtMostXObjects(1, 'blueKey');
  86. }
  87.  
  88. function onExit(map) {
  89.     if (!map.getPlayer().hasItem('blueKey')) {
  90.         map.writeStatus("We need to get that key!");
  91.         return false;
  92.     } else {
  93.         return true;
  94.     }
  95. }
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