Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 67 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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.setSquareColor(x, y, '#aaa');
  35.         }
  36.     }
  37.  
  38.     map.placeObject(2, map.getHeight() - 1, 'exit');
  39. }
  40.  
  41. function validateLevel(map) {
  42.     map.validateAtLeastXObjects(40, 'mine');
  43.     map.validateExactlyXManyObjects(1, 'exit');
  44. }
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