# 分享 Untrusted - 遊戲題解

qiukun · 2015年08月11日 · 最后由 qiukun 回复于 2015年08月11日 · 2279 次阅读

Trusted 是一個代碼解謎遊戲，用 Javascript 來過關的。

## Ceil Block A

``````//for(y = 3; y <= map.getHeight() - 10; y++) {
//    map.placeObject(5, y, 'block');
//    map.placeObject(map.getWidth() - 5, y, 'block');
//}
//
//for(x = 5; x <= map.getWidth() - 5; x++) {
//    map.placeObject(x, 3, 'block');
//    map.placeObject(x, map.getHeight() - 10, 'block');
//}
``````

## The Long Way Out

``````maze.create = function() {};
``````

``````map.placeObject(0, 0, "exit");
``````

## Validation Engaged

``````for(y = 0; y <= map.getHeight() - 3; y++) {
map.placeObject(5, y, 'block');
map.placeObject(map.getWidth() - 5, y, 'block');
}

for(x = 0; x <= map.getWidth() - 5; x++) {
map.placeObject(x, 3, 'block');
map.placeObject(x, map.getHeight() - 3, 'block');
}
``````

## Multiplicity

``````map.placeObject(20, 10, 'exit');
``````

## Minesweeper

``````map.setSquareColor(x, y, "#ff7800");
``````

## Drones 101

``````map.placeObject(30, 12, 'block');
map.placeObject(31, 11, 'block');
``````

## Colors

``````var player = map.getPlayer();

var color = player.getColor();
switch(color) {
case "#0f0":
player.setColor("#f00");
break;
case "#f00":
player.setColor("#ff0");
break;
case "#ff0":
player.setColor("#0f0");
break;
}
``````

“哎呀，天！他是惦記弟弟了。……可我還不知道呢！那麼這是他老人家的狗？很高興。……你把它帶去吧。……這條小狗怪不錯的。……挺伶俐。……一口就把這傢伙的手指咬破了！哈哈哈哈！……咦，你幹嗎發抖？嗚嗚，……嗚嗚。……它生氣了，小壞蛋，……好一條小狗……”

## Fording the River

23333333333333！做這題的時候差點沒把自己瀏覽器卡死。

``````map.defineObject("noah", {
'type': 'dynamic',
'symbol': 'a',
'color': '#420',
'transport': true,
'behavior': function(me) {
}
});
``````

``````for(var x = 0; x < map.getWidth(); x++) {
for(var y = 5; y < 15; y++) {
map.placeObject(x, y, 'noah');
}
}
``````

## Ambush

``````this.onCollision = function() {};
``````

## Robot

``````if(me.canMove("down")) me.move("down");
else me.move("right");
``````

``````var road = "ddddrrrrrrrrrrrrrrrrrrrrrrrrrrrrrruurrrrrrrrrrrrrrrrrddddddd";
this.cur = this.cur === undefined ? 0 : (this.cur + 1);

``````

## Robot Maze

``````var direct = {
"d": "down",
"u": "up",
"l": "left",
"r": "right"
};

// dfs...
if(undefined === this.dfs) {
this.ans = "";
this.step = 0;

var vis = [];
for(var i = 0; i < 100; i++) {
vis.push([]);
for(var j = 0; j < 100; j++) vis[i].push(false);
}

var dir = [
[ 0, -1, "u", "#f00" ],
[ 0, 1, "d", "#0f0" ],
[ -1, 0, "l", "#00f" ],
[ 1, 0, "r", "#fff" ]
];

this.dfs = function(x, y) {
if(x === map.getWidth() - 2 && y === 8) {
return true;
}
vis[y][x] = true;

for(var i = 0; i < 4; i++) {
var newx = x + dir[i][0];
var newy = y + dir[i][1];

if(newx < 0 || newy < 0 ||
newx >= map.getWidth() ||
newy >= map.getHeight() ||
vis[newy][newx] ||
map.getObjectTypeAt(newx, newy) === "block"
) continue;

var oldans = this.ans;
this.ans += dir[i][2];

if(!this.dfs(newx, newy)) {
this.ans = oldans;
} else {
map.setSquareColor(x, y, dir[i][3]);

return true;
}
}

return false;
};

this.dfs(1, 1);
this.ans += "dd";
}

if(this.step >= this.ans.length) return;
me.move(direct[this.ans[this.step++]]);
``````

## Exceptional Crossing

《訂製死神》：這個時候讓死神笑就可以了。

``````player.killedBy() = (0);
``````

## Lasers

``````// using canvas to draw the line
var ctx = map.getCanvasContext();
ctx.beginPath();
ctx.strokeStyle = 'white';
ctx.lineWidth = 5;
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();

createLaser = abc;
``````

``````function abc() {
for(var i = 0; i < 25; i++) {
map.createLine([1, 1], [2, 2], function(player) {
//... Ahahaha
});

var ctx = map.getCanvasContext();
ctx.beginPath();
ctx.strokeStyle = 'red';
ctx.lineWidth = 5;
ctx.moveTo(1, 1);
ctx.lineTo(2, 2);
ctx.stroke();
}
}
``````

## Pointers

``````var dict = "0123456789ABCDEF";
if(t1.getType() === "teleporter" && t2.getType() === "teleporter") {
var color = "#" + dict[Math.ceil(Math.random() * 15)] +
dict[Math.ceil(Math.random() * 15)] +
dict[Math.ceil(Math.random() * 15)];

map.setSquareColor(t1.getX(), t1.getY(), color);
map.setSquareColor(t2.getX(), t2.getY(), color);
}
``````

## Super Dr. Eval Bros

``````map.defineObject("❤", {
impassable: function() {
return true;
},
symbol: "❤"
});
map.placeObject(20, 12, "❤");
map.placeObject(21, 12, "❤");
map.placeObject(22, 12, "❤");
map.placeObject(23, 12, "❤");
map.placeObject(24, 12, "❤");
map.placeObject(25, 12, "❤");
map.placeObject(26, 12, "❤");
map.placeObject(27, 12, "❤");
map.placeObject(28, 12, "❤");
map.placeObject(29, 12, "❤");
``````

## Boss Fight

If you can read this, you are cheating!

But really, you don't need this console to play the game. Walk around using arrow keys (or Vim keys), and pick up the computer (⌘). Then the fun begins!

``````map.defineObject("保命的", {
impassable: function() {
return true;
},
symbol: "❤",
onCollision: function() {
}
});

for(var i = 0; i < map.getWidth(); i++) {
map.placeObject(i, 9, "保命的");
}
``````

``````map.getPlayer().setPhoneCallback(function() {
var bosses = [];
var bullets = [];
var objects = map.getDynamicObjects();
for(var i = 0; i < objects.length; i++) {
if(objects[i].getType() == "boss") {
bosses.push(objects[i]);
} else {
bullets.push(objects[i]);
}
}
for(var i = 0; i < Math.min(bosses.length, bullets.length); i++) {
bullets[i]._destroy = bosses[i]._destroy;
}

if(bosses.length === 0) {
map.placeObject(map.getPlayer().getX(), map.getPlayer().getY() + 1,
'theAlgorithm');
}
});
``````

## End of the Line

``````if(!game.map.finalLevel) {
game._moveToNextLevel();
}
``````

``````if(game.map.finalLevel) {
game._moveToNextLevel();
}
``````

## Credits

#1 楼 @rei 获得了作者授权