Created
September 30, 2017 12:27
-
-
Save anonymous/030262e0e3578ca8cde6409cd8db6e78 to your computer and use it in GitHub Desktop.
Solution to level 9 in Untrusted: http://alex.nisnevich.com/untrusted/
This file contains hidden or 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
/********************** | |
* fordingTheRiver.js * | |
********************** | |
* | |
* And there's the river. Fortunately, I was prepared for this. | |
* See the raft on the other side? | |
* | |
* Everything is going according to plan. | |
*/ | |
function startLevel(map) { | |
var raftDirection = 'down'; | |
map.placePlayer(map.getWidth()-1, map.getHeight()-1); | |
var player = map.getPlayer(); | |
map.defineObject('raft', { | |
'type': 'dynamic', | |
'symbol': '▓', | |
'color': '#420', | |
'transport': true, // (prevents player from drowning in water) | |
'behavior': function (me) { | |
me.move(raftDirection); | |
} | |
}); | |
map.defineObject('water', { | |
'symbol': '░', | |
'color': '#44f', | |
'onCollision': function (player) { | |
player.killedBy('drowning in deep dark water'); | |
} | |
}); | |
for (var x = 0; x < map.getWidth(); x++) { | |
for (var y = 5; y < 15; y++) { | |
map.placeObject(x, y, 'water'); | |
} | |
} | |
map.placeObject(20, 5, 'raft'); | |
map.placeObject(0, 2, 'exit'); | |
map.placeObject(0, 1, 'block'); | |
map.placeObject(1, 1, 'block'); | |
map.placeObject(0, 3, 'block'); | |
map.placeObject(1, 3, 'block'); | |
var functionList = {}; | |
functionList['joker'] = function () { | |
var raftDirection = 'up'; | |
//map.writeStatus("So,raftDirection is " + raftDirection); | |
//raft.behavior(); | |
map.raft.move(raftDirection); | |
//object.move(direction) | |
}; | |
map.defineObject('raft2', { | |
'type': 'dynamic', | |
'symbol': '▓', | |
'color': '#420', | |
'transport': true, // (prevents player from drowning in water) | |
'behavior': function (me) { | |
me.move(raftDirection); | |
} | |
}); | |
map.placeObject(20, 5, 'raft2'); | |
map.defineObject('raft3', { | |
'type': 'dynamic', | |
'symbol': '▓', | |
'color': '#420', | |
'transport': true, // (prevents player from drowning in water) | |
'behavior': function (me) { | |
me.move(raftDirection); | |
} | |
}); | |
map.placeObject(20, 5, 'raft3'); | |
map.defineObject('raft4', { | |
'type': 'dynamic', | |
'symbol': '▓', | |
'color': '#420', | |
'transport': true, // (prevents player from drowning in water) | |
'behavior': function (me) { | |
me.move(raftDirection); | |
} | |
}); | |
map.placeObject(20, 5, 'raft4'); | |
map.defineObject('raft5', { | |
'type': 'dynamic', | |
'symbol': '▓', | |
'color': '#420', | |
'transport': true, // (prevents player from drowning in water) | |
'behavior': function (me) { | |
me.move(raftDirection); | |
} | |
}); | |
map.placeObject(20, 5, 'raft5'); | |
map.defineObject('raft6', { | |
'type': 'dynamic', | |
'symbol': '▓', | |
'color': '#420', | |
'transport': true, // (prevents player from drowning in water) | |
'behavior': function (me) { | |
me.move(raftDirection); | |
} | |
}); | |
map.placeObject(20, 5, 'raft6'); | |
map.defineObject('raft7', { | |
'type': 'dynamic', | |
'symbol': '▓', | |
'color': '#420', | |
'transport': true, // (prevents player from drowning in water) | |
'behavior': function (me) { | |
me.move(raftDirection); | |
} | |
}); | |
map.placeObject(20, 5, 'raft7'); | |
map.defineObject('raft8', { | |
'type': 'dynamic', | |
'symbol': '▓', | |
'color': '#420', | |
'transport': true, // (prevents player from drowning in water) | |
'behavior': function (me) { | |
me.move(raftDirection); | |
} | |
}); | |
map.placeObject(20, 5, 'raft8'); | |
map.defineObject('raft9', { | |
'type': 'dynamic', | |
'symbol': '▓', | |
'color': '#420', | |
'transport': true, // (prevents player from drowning in water) | |
'behavior': function (me) { | |
me.move(raftDirection); | |
} | |
}); | |
map.placeObject(20, 5, 'raft9'); | |
map.defineObject('raft10', { | |
'type': 'dynamic', | |
'symbol': '▓', | |
'color': '#420', | |
'transport': true, // (prevents player from drowning in water) | |
'behavior': function (me) { | |
me.move(raftDirection); | |
} | |
}); | |
map.placeObject(20, 5, 'raft10'); | |
map.getPlayer().setPhoneCallback(functionList["joker"]); | |
} | |
function validateLevel(map) { | |
map.validateExactlyXManyObjects(1, 'exit'); | |
map.validateExactlyXManyObjects(1, 'raft'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment