diff --git a/js/main.js b/js/main.js index 9e306b1..10d0135 100644 --- a/js/main.js +++ b/js/main.js @@ -19,7 +19,16 @@ socket.on('getmap', function (conent) { cssMap = conent["cssMap"]; $("#main").append('
'); utilMap = conent["utilMap"]; - //console.log(map); + var chestCoords = [0,0]; + for (var w = 0; w < utilMap.length; w++) { //get chest coords + for (var h = 0; h < utilMap[w].length; h++) { + if(utilMap[w][h]=="treasure-closed") { + chestCoords = [w,h]; + } + } + } + console.log(chestCoords); + //console.log(cssMap); domMap = $("#map"); domMap.empty(); @@ -63,6 +72,11 @@ socket.on('removeUtil', function (obj) { $("."+obj["mapY"]+'-'+obj["mapX"]+'.'+obj["name"]).remove(); }); +socket.on('replaceUtil', function (obj) { + console.log(obj); + $("."+obj["mapY"]+'-'+obj["mapX"]+'.'+obj["name"]).removeClass(obj["name"]).addClass(obj["newName"]); +}); + function addNewPlayer(player, id) { if($("#"+id).length==0) { var modeClass = "default_ship"; @@ -215,7 +229,7 @@ $(document).ready(function() { event.preventDefault(); } var key = event.which; - console.log(key); + //console.log(key); if(key==37||key==38||key==39||key==40) event.preventDefault(); if(!keys[key]) { diff --git a/s_map.js b/s_map.js index 4e0ac91..a5e98a6 100644 --- a/s_map.js +++ b/s_map.js @@ -138,9 +138,14 @@ module.exports = { } var treasureSet = false; - while (!treasureSet) { - for (var w = 0; w < width; w++) { //fill forest + var foundLand = true; + while (!treasureSet && foundLand) { + foundLand = false; + for (var w = 0; w < width; w++) { //add chest for (var h = 0; h < height; h++) { + if(map[w][h] == "6") { + foundLand = true; + } if (map[w][h] == "6" && Math.random() < 0.00001 && !treasureSet) { treasureSet = true; utilMap[w][h] = "treasure-closed"; @@ -150,7 +155,6 @@ module.exports = { } } - var g = [6, 5, 4, 3, 2]; for (var k = 0; k < g.length; k++) { var i = g[k] + ""; diff --git a/server.js b/server.js index 46d48c3..a12a118 100644 --- a/server.js +++ b/server.js @@ -95,7 +95,14 @@ io.on('connection', function(socket){ playerActionTimer = setTimeout(function() { utilMap[obj["mapY"]][obj["mapX"]] = ""; io.sockets.emit("removeUtil", obj); - console.log("REMOVEEEEE", obj); + socket.emit("stopAnimation", 2000); + }, 2000); //2 Secs + socket.emit("animation", 2000); + } else if(obj["name"] == "treasure-closed") { + playerActionTimer = setTimeout(function() { + utilMap[obj["mapY"]][obj["mapX"]] = "treasure-open"; + obj["newName"] = "treasure-open"; + io.sockets.emit("replaceUtil", obj); socket.emit("stopAnimation", 2000); }, 2000); //2 Secs socket.emit("animation", 2000);