Created
January 24, 2021 02:10
-
-
Save Untrusted-Game/3274310a082a519fc2a9060dacd7fa2d to your computer and use it in GitHub Desktop.
Solution to level 7 in Untrusted: http://alex.nisnevich.com/untrusted/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************* | |
* colors.js * | |
************* | |
* | |
* You're almost at the exit. You just need to get past this | |
* color lock. | |
* | |
* Changing your environment is no longer enough. You must | |
* learn to change yourself. I've sent you a little something | |
* that should help with that. | |
*/ | |
function startLevel(map) { | |
map.placePlayer(0, 12); | |
map.placeObject(5, 12, 'phone'); | |
// The function phone lets you call arbitrary functions, | |
// as defined by player.setPhoneCallback() below. | |
// The function phone callback is bound to Q or Ctrl-6. | |
map.getPlayer().setPhoneCallback(function () { | |
var player = map.getPlayer(); | |
if (player.getColor() == '#0f0') { | |
//if I am green | |
player.setColor('#f00'); //make me red | |
} else if (player.getColor() == '#f00') { | |
//if I am red | |
player.setColor('#ff0'); //make me yellow | |
} else if (player.getColor() == '#ff0') { | |
//if I am yellow | |
player.setColor('#0f0'); //make me green | |
} | |
/* | |
I had a semantic error, but eventually straightened it out | |
I could use a switch statement, but didn't think to do so initially | |
Twisted Code (sometimes called macks2008 or macks2010) was here | |
*/ | |
}); | |
map.defineObject('redLock', { | |
symbol: '☒', | |
color: "#f00", // red | |
impassable: function(player, object) { | |
return player.getColor() != object.color; | |
} | |
}); | |
map.defineObject('greenLock', { | |
symbol: '☒', | |
color: "#0f0", // green | |
impassable: function(player, object) { | |
return player.getColor() != object.color; | |
} | |
}); | |
map.defineObject('yellowLock', { | |
symbol: '☒', | |
color: "#ff0", // yellow | |
impassable: function(player, object) { | |
return player.getColor() != object.color; | |
} | |
}); | |
for (var x = 20; x <= 40; x++) { | |
map.placeObject(x, 11, 'block'); | |
map.placeObject(x, 13, 'block'); | |
} | |
map.placeObject(22, 12, 'greenLock'); | |
map.placeObject(25, 12, 'redLock'); | |
map.placeObject(28, 12, 'yellowLock'); | |
map.placeObject(31, 12, 'greenLock'); | |
map.placeObject(34, 12, 'redLock'); | |
map.placeObject(37, 12, 'yellowLock'); | |
map.placeObject(40, 12, 'exit'); | |
for (var y = 0; y < map.getHeight(); y++) { | |
if (y != 12) { | |
map.placeObject(40, y, 'block'); | |
} | |
for (var x = 41; x < map.getWidth(); x++) { | |
map.setSquareColor(x, y, '#080'); | |
} | |
} | |
} | |
function validateLevel(map) { | |
map.validateExactlyXManyObjects(1, 'exit'); | |
} | |
function onExit(map) { | |
if (!map.getPlayer().hasItem('phone')) { | |
map.writeStatus("We need the phone!"); | |
return false; | |
} else { | |
return true; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment