Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. @invalid-email-address Anonymous created this gist May 7, 2014.
    95 changes: 95 additions & 0 deletions untrusted-lvl17-solution.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,95 @@
    /***************
    * pointers.js *
    ***************
    *
    * You! How are you still alive?
    *
    * Well, no matter. Good luck getting through this
    * maze of rooms - you'll never see me or the Algorithm again!
    */

    function startLevel(map) {
    function shuffle(o){ //v1.0 [http://bit.ly/1l6LGQT]
    for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i),
    x = o[--i], o[i] = o[j], o[j] = x);
    return o;
    };

    map.createFromGrid(
    ['+++++++++++++++++++++++++++++++++++++++++++++',
    '++o *++++o *++++o *++++o *++++o *++++o *+++++',
    '+* @ o++* o++* o++* o++* o++* o++++',
    '++o *++++o *++++o *++++o *++++o *++++o *+++++',
    '+++++++++++++++++++++++++++++++++++++++++++++',
    '+++++* o++++* o++++* o++++* o++++* o++++* o++',
    '++++o *++o *++o *++o *++o *++o *+',
    '+++++* o++++* o++++* o++++* o++++* o++++* o++',
    '+++++++++++++++++++++++++++++++++++++++++++++',
    '++o *++++o *++++o *++++o *++++o *++++o *+++++',
    '+* o++* o++* o++* o++* o++* o++++',
    '++o *++++o *++++o *++++o *++++o *++++o *+++++',
    '+++++++++++++++++++++++++++++++++++++++++++++',
    '+++++* o++++* o++++* o++++* o++++* o++++* o++',
    '++++o *++o *++o *++o *++o *++o *+',
    '+++++* o++++* o++++* o++++* o++++* o++++* o++',
    '+++++++++++++++++++++++++++++++++++++++++++++',
    '++o *++++o *++++o *++++o *++++o *++++o *+++++',
    '+* o++* o++* o++* o++* o++* E o++++',
    '++o *++++o *++++o *++++o *++++o *++++o *+++++',
    '+++++++++++++++++++++++++++++++++++++++++++++'],
    {
    '@': 'player',
    'E': 'exit',
    '+': 'block',
    'o': 'teleporter',
    '*': 'trap',
    }, 2, 2);

    var canvas = map.getCanvasContext();

    var teleportersAndTraps = map.getDynamicObjects();
    teleportersAndTraps = shuffle(teleportersAndTraps);

    for (i = 0; i < teleportersAndTraps.length; i+=2) {
    var t1 = teleportersAndTraps[i];
    var t2 = teleportersAndTraps[i+1];

    // Point each teleporter to either another teleporter
    // or a trap
    if (t1.getType() == 'teleporter') {
    t1.setTarget(t2);
    }
    if (t2.getType() == 'teleporter') {
    t2.setTarget(t1);
    }

    // TODO find a way to remove the API docs
    // wouldn't want the 'good doctor' to find
    // out about map.getCanvasCoords()...
    if (t1.getType() == 'teleporter' && t2.getType() == 'teleporter') {

    var c1 = map.getCanvasCoords(t1),
    c2 = map.getCanvasCoords(t2);

    canvas.beginPath();
    var colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00'];
    canvas.i = canvas.i || 0;
    canvas.strokeStyle = colors[canvas.i];
    canvas.i = (canvas.i + 1) % 4;
    console.log(canvas.strokeStyle);

    canvas.lineTo(c1.x, c1.y);
    canvas.lineTo(c2.x, c2.y);
    canvas.stroke();
    }




    }
    }

    function validateLevel(map) {
    map.validateExactlyXManyObjects(1, 'exit');
    }