function selectWord(en, fr) {
    switch (LANG) {
        case 'fr':
            return fr;
        default:
            return en;
    }
}

function newGame(father, level, game = new Game(father, level)) {
    if (father.scene.getIndex('Game') !== -1) {
        father.scene.remove('Game');
    }
    father.scene.add('Game', game);
}

function chooseTarget(robot, list) {
    let minDist = WIDTH_MAP * 2;
    let l = [];
    list.forEach(function (item) {
        if (item !== robot) {
            let hypot = Math.hypot(item.x - robot.x, item.y - robot.y);
            if (minDist >= hypot) {
                if (minDist > hypot) {
                    minDist = hypot;
                    l = [];
                }
                l.push(item);
            }
        }
    });
    if (l.length > 1) {
        return l[Math.floor(Math.random() * (l.length + 1))];
    } else {
        return l[0];
    }
}

function toJson(name, value, end = false) {
    let val;
    switch (typeof value) {
        case "string":
            val = '"' + name.toString() + '":"' + value + '"';
            break;
        default:
            //console.log(typeof value);
            val = '"' + name.toString() + '":' + value;
            break;
    }
    if (!end)
        val += ','
    return val;
}

function endLineJson(json) {
    if (json.length > 0) {
        if (json[json.length - 1] === ",") {
            json = json.substr(0, json.length - 1);
        }
    }
    return json;
}