Guest User

Untitled

a guest
Jul 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  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.  
  35.  
  36. map.setSquareColor(x,y,'#fff');
  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. }
Add Comment
Please, Sign In to add comment