Guest User

Untitled

a guest
Dec 10th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  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. if (me.canMove('down')){
  31. me.move('down');
  32. }
  33. else {
  34. me.move('right');
  35. }
  36. }
  37. });
  38.  
  39. map.defineObject('barrier', {
  40. 'symbol': '░',
  41. 'color': 'purple',
  42. 'impassable': true,
  43. 'passableFor': ['robot']
  44. });
  45.  
  46. map.placeObject(0, map.getHeight() - 1, 'exit');
  47. map.placeObject(1, 1, 'robot');
  48. map.placeObject(map.getWidth() - 2, 8, 'blueKey');
  49. map.placeObject(map.getWidth() - 2, 9, 'barrier');
  50.  
  51. var autoGeneratedMaze = new ROT.Map.DividedMaze(map.getWidth(), 10);
  52. autoGeneratedMaze.create( function (x, y, mapValue) {
  53. // don't write maze over robot or barrier
  54. if ((x == 1 && y == 1) || (x == map.getWidth() - 2 && y >= 8)) {
  55. return 0;
  56. } else if (mapValue === 1) { //0 is empty space 1 is wall
  57. map.placeObject(x,y, 'block');
  58. } else {
  59. map.placeObject(x,y,'empty');
  60. }
  61. });
  62. }
  63.  
  64. function validateLevel(map) {
  65. map.validateExactlyXManyObjects(1, 'exit');
  66. map.validateExactlyXManyObjects(1, 'robot');
  67. map.validateAtMostXObjects(1, 'blueKey');
  68. }
  69.  
  70. function onExit(map) {
  71. if (!map.getPlayer().hasItem('blueKey')) {
  72. map.writeStatus("We need to get that key!");
  73. return false;
  74. } else {
  75. return true;
  76. }
  77. }
Add Comment
Please, Sign In to add comment