Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 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. map.defineObject('myRobot', {
  31. 'type': 'dynamic',
  32. 'symbol': 'R',
  33. 'color': 'blue',
  34. 'behavior': function (me) {
  35. // Available commands: me.move(direction)
  36. // and me.canMove(direction)
  37. me.move('down')
  38. map.placeObject(map.getWidth() - 2, 10, 'blueKey')
  39. }
  40. });
  41. map.placeObject(map.getWidth() - 2, 7, 'myRobot')
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. }
  83. });
  84.  
  85. map.defineObject('barrier', {
  86. 'symbol': '░',
  87. 'color': 'purple',
  88. 'impassable': true,
  89. 'passableFor': ['robot']
  90. });
  91.  
  92. map.placeObject(0, map.getHeight() - 1, 'exit');
  93. map.placeObject(1, 1, 'robot');
  94. map.placeObject(map.getWidth() - 2, 8, 'blueKey');
  95. map.placeObject(map.getWidth() - 2, 9, 'barrier');
  96.  
  97. var autoGeneratedMaze = new ROT.Map.DividedMaze(map.getWidth(), 10);
  98. autoGeneratedMaze.create( function (x, y, mapValue) {
  99. // don't write maze over robot or barrier
  100. if ((x == 1 && y == 1) || (x == map.getWidth() - 2 && y >= 8)) {
  101. return 0;
  102. } else if (mapValue === 1) { //0 is empty space 1 is wall
  103. map.placeObject(x,y, 'block');
  104. } else {
  105. map.placeObject(x,y,'empty');
  106. }
  107. });
  108. }
  109.  
  110. function validateLevel(map) {
  111. map.validateExactlyXManyObjects(1, 'exit');
  112. map.validateExactlyXManyObjects(1, 'robot');
  113. map.validateAtMostXObjects(1, 'blueKey');
  114. }
  115.  
  116. function onExit(map) {
  117. if (!map.getPlayer().hasItem('blueKey')) {
  118. map.writeStatus("We need to get that key!");
  119. return false;
  120. } else {
  121. return true;
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement