module.exports = { generateMap: function(width, height) { var map = []; var utilMap = []; var i = 0; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","4","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","4","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","4","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","4","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","4","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","4","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; var g = [6,5,4,3,2]; for(var k=0;kwidth-7 || h>height-7) { map[w][h] = "0"; //border water } } } /* groundtypes g = ground w = water */ // //Set ground type for(var w=0;w=width-1 || h>=height-1) && (map[w-1][h]==i || map[w][h-1]==i || map[w][h+1]==i || map[w+1][h]==i || map[w+1][h+1]==i || map[w-1][h-1]==i || map[w+1][h-1]==i || map[w-1][h+1]==i)) { map[w][h] = (i-1)+""; //set ground } } } } var cssMap = addCssClass(map); return {"cssMap":cssMap, "utilMap":utilMap}; } }; function rand(p) { if(p > Math.random()*100) return true; return false; } function addCssClass(map) { var cssMap = []; for(var w=0;w=map.length-1 || h>=map[w].length-1)) spClass = "water"; else if((map[w][h-1]=="0" && map[w][h]=="1" && map[w][h+1]=="2" && map[w-1][h+1]=="1") || (map[w-1][h-1]=="0" && map[w][h]=="1" && map[w+1][h]=="2" && map[w+1][h-1]=="1") || (map[w+1][h]=="2" && map[w][h]=="1" && map[w][h+1]=="2")) { if(map[w][h+1]=="2" && map[w+1][h]=="2") { if(map[w-1][h+1]=="1" && map[w+1][h-1]=="2") spClass = "topDown_1"; else if(map[w+1][h-1]=="1" && map[w-1][h+1]=="2") spClass = "leftRight_1"; else if(map[w+1][h-1]=="2" && map[w-1][h+1]=="2") spClass = "leftRightTT_1"; else spClass = "leftRightT_1"; } else spClass = "leftRightT_1"; } else if((map[w][h+1]=="0" && map[w][h]=="1" && map[w][h-1]=="2" && map[w-1][h-1]=="1") || (map[w-1][h]=="0" && map[w][h]=="1" && map[w+1][h]=="2" && map[w+1][h+1]=="1") || (map[w+1][h]=="2" && map[w][h]=="1" && map[w][h-1]=="2")) { if(map[w][h-1]=="2" && map[w+1][h]=="2") { if(map[w-1][h-1]=="1" && map[w+1][h+1]=="2") spClass = "topDown_1"; else if(map[w+1][h+1]=="1" && map[w-1][h-1]=="2") spClass = "rightLeft_1"; else if(map[w-1][h-1]=="2" && map[w+1][h-1]=="2") spClass = "rightLeftTT_1"; else spClass = "rightLeftT_1"; } else spClass = "rightLeftT_1"; } else if((map[w][h-1]=="0" && map[w][h]=="1" && map[w][h+1]=="2" && map[w+1][h+1]=="1") || (map[w+1][h]=="0" && map[w][h]=="1" && map[w-1][h]=="2" && map[w-1][h-1]=="1") || (map[w-1][h]=="2" && map[w][h]=="1" && map[w][h+1]=="2")) { if(map[w][h+1]=="2" && map[w-1][h]=="2") { if(map[w+1][h+1]=="1" && map[w-1][h-1]=="2") spClass = "downTop_1"; else if(map[w-1][h-1]=="1" && map[w+1][h+1]=="2") spClass = "leftRight_1"; else if(map[w-1][h-1]=="2" && map[w+1][h+1]=="2") spClass = "rightLeftBB_1"; else spClass = "rightLeftB_1"; } else spClass = "rightLeftB_1"; } else if((map[w+1][h]=="0" && map[w][h]=="1" && map[w-1][h]=="2" && map[w-1][h+1]=="1") || (map[w][h+1]=="0" && map[w][h]=="1" && map[w][h-1]=="2" && map[w+1][h-1]=="1") || (map[w-1][h]=="2" && map[w][h]=="1" && map[w][h-1]=="2")) { if(map[w][h-1]=="2" && map[w-1][h]=="2") { if(map[w+1][h-1]=="1" && map[w-1][h+1]=="2") spClass = "downTop_1"; else if(map[w-1][h+1]=="1" && map[w+1][h-1]=="2") spClass = "rightLeft_1"; else if(map[w-1][h+1]=="2" && map[w-1][h+1]=="2") spClass = "leftRightBB_1"; else spClass = "leftRightB_1"; } else spClass = "leftRightB_1"; } else if(map[w][h-1]=="3" && map[w][h]=="2" && map[w-1][h]=="3") spClass = "rightLeftBU_2"; else if(map[w][h-1]=="4" && map[w][h]=="3" && map[w-1][h]=="4") spClass = "rightLeftBU_3"; else if(map[w][h-1]=="6" && map[w][h]=="5" && map[w-1][h]=="6") spClass = "rightLeftBU_5"; else if(map[w][h+1]=="3" && map[w][h]=="2" && map[w-1][h]=="3") spClass = "leftRightBU_2"; else if(map[w][h+1]=="4" && map[w][h]=="3" && map[w-1][h]=="4") spClass = "leftRightBU_3"; else if(map[w][h+1]=="6" && map[w][h]=="5" && map[w-1][h]=="6") spClass = "leftRightBU_5"; else if(map[w][h+1]=="3" && map[w][h]=="2" && map[w+1][h]=="3") spClass = "rightLeftTU_2"; else if(map[w][h+1]=="4" && map[w][h]=="3" && map[w+1][h]=="4") spClass = "rightLeftTU_3"; else if(map[w][h+1]=="6" && map[w][h]=="5" && map[w+1][h]=="6") spClass = "rightLeftTU_5"; else if(map[w][h-1]=="3" && map[w][h]=="2" && map[w+1][h]=="3") spClass = "leftRightTU_2"; else if(map[w][h-1]=="4" && map[w][h]=="3" && map[w+1][h]=="4") spClass = "leftRightTU_3"; else if(map[w][h-1]=="6" && map[w][h]=="5" && map[w+1][h]=="6") spClass = "leftRightTU_5"; else if(map[w][h-1]=="0" && map[w][h]=="1" && map[w][h+1]=="2") spClass = "leftRight_1"; else if(map[w][h-1]=="1" && map[w][h]=="2" && map[w][h+1]=="3") spClass = "leftRight_2"; else if(map[w][h-1]=="2" && map[w][h]=="3" && map[w][h+1]=="4") spClass = "leftRight_3"; else if(map[w][h]=="4") spClass = "ground"; else if(map[w][h-1]=="4" && map[w][h]=="5" && map[w][h+1]=="6") spClass = "leftRight_5"; else if(map[w][h]=="6") spClass = "grass"; else if((map[w][h+1]=="1" && map[w][h]=="1" && map[w+1][h]=="1") || (map[w][h-1]=="1" && map[w][h]=="1" && map[w+1][h]=="1") || (map[w-1][h]=="1" && map[w][h]=="1" && map[w][h+1]=="1") || (map[w-1][h]=="1" && map[w][h]=="1" && map[w][h-1]=="1")) spClass = "water"; else if(map[w][h+1]=="2" && map[w][h]=="2" && map[w+1][h]=="2") spClass = "leftRightT_2"; else if(map[w][h+1]=="3" && map[w][h]=="3" && map[w+1][h]=="3") spClass = "leftRightT_3"; else if(map[w][h+1]=="5" && map[w][h]=="5" && map[w+1][h]=="5") spClass = "leftRightT_5"; else if(map[w-1][h]=="0" && map[w][h]=="1" && map[w+1][h]=="2") spClass = "topDown_1"; else if(map[w-1][h]=="1" && map[w][h]=="2" && map[w+1][h]=="3") spClass = "topDown_2"; else if(map[w-1][h]=="2" && map[w][h]=="3" && map[w+1][h]=="4") spClass = "topDown_3"; else if(map[w-1][h]=="4" && map[w][h]=="5" && map[w+1][h]=="6") spClass = "topDown_5"; else if(map[w][h+1]=="0" && map[w][h]=="1" && map[w][h-1]=="2") spClass = "rightLeft_1"; else if(map[w][h+1]=="1" && map[w][h]=="2" && map[w][h-1]=="3") spClass = "rightLeft_2"; else if(map[w][h+1]=="2" && map[w][h]=="3" && map[w][h-1]=="4") spClass = "rightLeft_3"; else if(map[w][h+1]=="4" && map[w][h]=="5" && map[w][h-1]=="6") spClass = "rightLeft_5"; else if(map[w][h-1]=="2" && map[w][h]=="2" && map[w+1][h]=="2") spClass = "rightLeftT_2"; else if(map[w][h-1]=="3" && map[w][h]=="3" && map[w+1][h]=="3") spClass = "rightLeftT_3"; else if(map[w][h-1]=="5" && map[w][h]=="5" && map[w+1][h]=="5") spClass = "rightLeftT_5"; else if(map[w+1][h]=="0" && map[w][h]=="1" && map[w-1][h]=="2") spClass = "downTop_1"; else if(map[w+1][h]=="1" && map[w][h]=="2" && map[w-1][h]=="3") spClass = "downTop_2"; else if(map[w+1][h]=="2" && map[w][h]=="3" && map[w-1][h]=="4") spClass = "downTop_3"; else if(map[w+1][h]=="4" && map[w][h]=="5" && map[w-1][h]=="6") spClass = "downTop_5"; else if(map[w][h+1]=="2" && map[w][h]=="2" && map[w-1][h]=="2") spClass = "leftRightB_2"; else if(map[w][h+1]=="3" && map[w][h]=="3" && map[w-1][h]=="3") spClass = "leftRightB_3"; else if(map[w][h+1]=="5" && map[w][h]=="5" && map[w-1][h]=="5") spClass = "leftRightB_5"; else if(map[w][h-1]=="2" && map[w][h]=="2" && map[w-1][h]=="2") spClass = "rightLeftB_2"; else if(map[w][h-1]=="3" && map[w][h]=="3" && map[w-1][h]=="3") spClass = "rightLeftB_3"; else if(map[w][h-1]=="5" && map[w][h]=="5" && map[w-1][h]=="5") spClass = "rightLeftB_5"; cssMap[w][h] = spClass; } } return cssMap; }