/**
 * Created by JanJJ on 18.10.2016.
 */

var maze = {};

maze.config = {
    selectorMap: '.js-map',
    SelectorLoadingIcon: '.js-map-loading-icon ',

    chars: {
        0: '&nbsp;',
        1: '#',
        2: '&copy;'
    },

    splitChar: "-"

};


maze.loadMap = function (map) {
    $.each(map, function (index, value) {
        var singleLine = "";
        singleLine += maze.createStructure('', index, 'start');

        for (var i = 0; i < value.length; i++) {
            singleLine += maze.createStructure(maze.config.chars[value[i]], index, i);
        }

        singleLine += maze.createStructure('', 'map', index, 'end');
        $(maze.config.selectorMap).append(singleLine);
    })
};

maze.createStructure = function (character, x, y) {
    var env;
    var candyclass;
    if (character == "&copy;")
        candyclass = "class='candy'";
    if (y === "start") {
        env = '<div '+candyclass+' id="' + x + '">' + character;
    } else if (y === "end") {
        env = character + '</div>';
    } else {
        env = '<span '+candyclass+' id="' + x + maze.config.splitChar + y + '">' + character + '</span>';
    }
    return env;
};


function loadJson() {
    var url = location.protocol + '//' + location.host + location.pathname + 'api/maze?x=17&y=17';
    $(maze.config.SelectorLoadingIcon).show();
    $(maze.config.selectorMap).html('');
    $.get(url, function (response) {
        $(maze.config.SelectorLoadingIcon).hide();
        console.log(response);
        maze.loadMap(response);
    });
}
$(function () {
    loadJson();
});
@@ -1527,16 +1527,405 @@
   %7D);%0A%7D%0A
+%0Afunction saveScore(name, points, timeInSeconds) %7B%0A    var url = location.protocol + '//' + location.host + location.pathname + 'api/highscore';%0A    $.ajax(%7B%0A        type: %22POST%22,%0A        url: url,%0A        dataType: 'json',%0A        data: JSON.stringify(%7B%0A            name: name,%0A            score: points,%0A            level: 1,%0A            elapsedTime: timeInSeconds%0A        %7D)%0A    %7D);%0A%7D%0A%0A
 $(functi

add saveScore Javascript function