Game15 test

by Alexander Shpak

HTML

<canvas id="canvas"></canvas>

JavaScript

function anim(canvas, fps, clear) {
    var interval = null;
    var update = null;
    var draw = null;
    this.setDraw = function (func) {
        draw = func;
    };
    this.setUpdate = function (func) {
        update = func;
    };
    var step = function () {
        if (clear) {
            context.clearRect(0, 0, canvas.width, canvas.height);
        }
        if (update !== null) {
            update();
        }
        if (draw !== null) {
            draw();
        }
    };
    this.stop = function () {
        clearInterval(interval);
    };
    this.play = function () {
        if (draw !== null) {
            draw();
        }
        interval = setInterval(step, 1000 / fps);
    };
}

function saveItem() {
    var key = null;
    this.init = function (k, defaultValue) {
        key = k;
        if (!window.localStorage.getItem(key)) {
            window.localStorage.setItem(key, defaultValue);
            value = defaultValue;
        }
    };
    this.save = function (v) {
        window.localStorage.removeItem(key);
        window.localStorage.setItem(key, v);
    };
    this.load = function () {
        return window.localStorage.getItem(key);
    };
    this.clear = function () {
        return window.localStorage.removeItem(key);
    };
}

function game15() {
    var cellView = null;
    var numView = null;
    var clicks = 0;
    var arr = [
        [1, 2, 3, 4],
        [5, 6, 7, 8],
        [9, 10, 11, 12],
        [13, 14, 15, 0]
    ];

    function getNull() {
        for (var i = 0; i < 4; i++) {
            for (var j = 0; j < 4; j++) {
                if (arr[j][i] === 0) {
                    return {
                        "x": i,
                            "y": j
                    };
                }
            }
        }
    };

    function getRandomBool() {
        if (Math.floor(Math.random() * 2) === 0) {
            return true;
        } else {
            return false;
        }
    }
    this.getClicks =...