Skip to content

Instantly share code, notes, and snippets.

@seanmcelroy
Last active August 29, 2015 13:58
Show Gist options
  • Save seanmcelroy/10083042 to your computer and use it in GitHub Desktop.
Save seanmcelroy/10083042 to your computer and use it in GitHub Desktop.
untrusted-lvl5-solution.js
/******************
* minesweeper.js *
******************
*
* So much for Asimov's Laws. They're actually trying to kill
* you now. Not to be alarmist, but the floor is littered
* with mines. Rushing for the exit blindly may be unwise.
* I need you alive, after all.
*
* If only there was some way you could track the positions
* of the mines...
*/
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function startLevel(map) {
for (x = 0; x < map.getWidth(); x++) {
for (y = 0; y < map.getHeight(); y++) {
map.setSquareColor(x, y, '#f00');
}
}
map.placePlayer(map.getWidth() - 5, 5);
for (var i = 0; i < 75; i++) {
var x = getRandomInt(0, map.getWidth() - 1);
var y = getRandomInt(0, map.getHeight() - 1);
if (x != 2 || y != map.getHeight() - 1) {
// don't place mine over exit!
map.placeObject(x, y, 'mine', '#f00');
map.setSquareColor(x,y,'#000');
}
}
map.placeObject(2, map.getHeight() - 1, 'exit');
}
function validateLevel(map) {
map.validateAtLeastXObjects(40, 'mine');
map.validateExactlyXManyObjects(1, 'exit');
}
@itslenny
Copy link

itslenny commented Apr 9, 2014

I'm going through your answers and comparing them to mine. It's funny how I solved some of them differently. This one was exceptionally weird looking back at it... I just moved the mines off the screen.

for(ii = 0; ii < 39; ii++){
    map.placeObject(ii, 1, 'mine', '#f00');
}
break;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment