Just throwing up my solutions to the javascript game found at: http://alexnisnevich.github.io/untrusted/
My solutions are colored in red, indicating areas where you can edit code.

Chapter 1 – cellBlockA:

I deleted everything… it worked.

for (y = 3; y <= map.getHeight() – 10; y++) {
}
for (x = 5; x <= map.getWidth() – 5; x++) {
}

Chapter 2 – theLongWayOut

I placed the exit next to the player, and deleted the maze.

function startLevel(map) {
map.placePlayer(7, 5);

var maze = new ROT.Map.DividedMaze(map.getWidth(), map.getHeight());
var maze = new ROT.Map.DividedMaze(1,1)
maze.create( function (x, y, mapValue) {

// don’t write maze over player
if (map.getPlayer().atLocation(x,y)) {
return 0;
}

else if (mapValue === 1) { //0 is empty space 1 is wall
map.placeObject(x,y, ‘block’);
}
else {
map.placeObject(x,y,’empty’);
}
});

map.placeObject(map.getWidth()-4, map.getHeight()-4, ‘block’);
map.placeObject(map.getWidth()-6, map.getHeight()-4, ‘block’);
map.placeObject(map.getWidth()-5, map.getHeight()-5, ‘block’);
map.placeObject(map.getWidth()-5, map.getHeight()-3, ‘block’);
map.placeObject(8,5,’exit’)
map.placeObject(map.getWidth()-5, map.getHeight()-4, ‘exit’);
}

Chapter 3 – validationEngaged

I shifted the map over 3 spaces along the X-axis. Keeps the same number of blocks, and leaves a gap to move through. Bolded the numbers I changed.

/************************
* validationEngaged.js *
************************
*
* They’re really on to us now! The validateLevel function
* has been activated to enforce constraints on what you can
* do. In this case, you’re not allowed to remove any blocks.
*
* They’re doing all they can to keep you here. But you
* can still outsmart them.
*/

function startLevel(map) {
map.placePlayer(map.getWidth()-7, map.getHeight()-5);

for (y = 10; y <= map.getHeight() – 3; y++) {
map.placeObject(5, y, ‘block’);
map.placeObject(map.getWidth() – 5, y, ‘block’);
}

for (x = 2; x <= map.getWidth() – 8; x++) {
map.placeObject(x, 10, ‘block’);
map.placeObject(x, map.getHeight() – 3, ‘block’);
}

map.placeObject(7, 5, ‘exit’);
}

function validateLevel(map) {
numBlocks = 2 * (map.getHeight()-13) + 2 * (map.getWidth()-10);

map.validateAtLeastXObjects(numBlocks, ‘block’);
map.validateExactlyXManyObjects(1, ‘exit’);
}

Chapter 4 – multiplicity

Pretty much the same solution as Chapter 2. Just placed the exit next to player again.

/*******************
* multiplicity.js *
*******************
*
* Out of one cell and into another. They’re not giving you
* very much to work with here, either. Ah, well.
*
* Level filenames can be hints, by the way. Have I
* mentioned that before?
*
* No more cells after this one. I promise.
*/

function startLevel(map) {

map.placePlayer(map.getWidth()-5, map.getHeight()-4);

for (y = 7; y <= map.getHeight() – 3; y++) {
map.placeObject(7, y, ‘block’);
map.placeObject(map.getWidth() – 3, y, ‘block’);
}
map.placeObject(40,20,’exit’)
for (x = 7; x <= map.getWidth() – 3; x++) {
map.placeObject(x, 7, ‘block’);
map.placeObject(x, map.getHeight() – 3, ‘block’);
}

map.placeObject(map.getWidth() – 5, 5, ‘exit’);
}

Chapter 5 – minesweeper

Mark the positions of the mines, by changing the color of the square.

/******************
* 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)
&& (x != map.getWidth() – 5 || y != 5)) {
// don’t place mine over exit or player!
map.placeObject(x, y, ‘mine’);
map.setSquareColor(x, y, ‘#EEE’);
}
}

map.placeObject(2, map.getHeight() – 1, ‘exit’);
}

function validateLevel(map) {
map.validateAtLeastXObjects(40, ‘mine’);
map.validateExactlyXManyObjects(1, ‘exit’);
}

Untrusted Javascript Game Solutions – Chapters 1-5
Tagged on:                     

Leave a Reply

Your email address will not be published.