SHARE
TWEET

Untitled

a guest Sep 17th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /******************
  2.  * minesweeper.js *
  3.  ******************
  4.  *
  5.  * So much for Asimov's Laws. They're actually trying to kill
  6.  * you now. Not to be alarmist, but the floor is littered
  7.  * with mines. Rushing for the exit blindly may be unwise.
  8.  * I need you alive, after all.
  9.  *
  10.  * If only there was some way you could track the positions
  11.  * of the mines...
  12.  */
  13.  
  14. function getRandomInt(min, max) {
  15.     return Math.floor(Math.random() * (max - min + 1)) + min;
  16. }
  17.  
  18. function startLevel(map) {
  19.     for (x = 0; x < map.getWidth(); x++) {
  20.         for (y = 0; y < map.getHeight(); y++) {
  21.             map.setSquareColor(x, y, '#f00');
  22.         }
  23.     }
  24.  
  25.     map.placePlayer(map.getWidth() - 5, 5);
  26.  
  27.     for (var i = 0; i < 75; i++) {
  28.         var x = getRandomInt(0, map.getWidth() - 1);
  29.         var y = getRandomInt(0, map.getHeight() - 1);
  30.         if ((x != 2 || y != map.getHeight() - 1)
  31.             && (x != map.getWidth() - 5 || y != 5)) {
  32.             // don't place mine over exit or player!
  33.             map.placeObject(x, y, 'mine');
  34. map.placeObject(map.getWidth()-12, map.getHeight()-10, 'computer');
  35. map.placeObject(map.getWidth()-10, map.getHeight()-10, 'computer');
  36. map.setSquareColor(x, y, '#00');
  37.         }
  38.     }
  39.  
  40.     map.placeObject(2, map.getHeight() - 1, 'exit');
  41. }
  42.  
  43. function validateLevel(map) {
  44.     map.validateAtLeastXObjects(40, 'mine');
  45.     map.validateExactlyXManyObjects(1, 'exit');
  46. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top