diff options
Diffstat (limited to 'js/mapspecs.js')
-rw-r--r-- | js/mapspecs.js | 310 |
1 files changed, 164 insertions, 146 deletions
diff --git a/js/mapspecs.js b/js/mapspecs.js index ee9759d..b9d0aa4 100644 --- a/js/mapspecs.js +++ b/js/mapspecs.js @@ -1,12 +1,12 @@ var ready_done = false,
- ready = function() {
- if (ready_done)
- return;
- ready_done = true;
- loadSol();
- if (isChallenge)
- challengeLoad();
- }
+ready = function() {
+ if (ready_done)
+ return;
+ ready_done = true;
+ loadSol();
+ if (isChallenge)
+ challengeLoad();
+}
if (document.readyState === 'complete')
ready();
@@ -97,9 +97,9 @@ function grid_click(obj) { //Is this placing a wall, or removing one?
var tmp = obj.id;
childdiv = document.getElementById('child_'+tmp);
- if (obj.cv) {
+ if (obj.cv) {
//Removing a wall
- obj.cv = false;
+ obj.cv = false;
//Reset childdiv to it's default.
childdiv.removeAttribute("class");
@@ -112,16 +112,16 @@ function grid_click(obj) { obj.removeAttribute("class");
obj.setAttribute("class", "grid_td");
- blocks[mapid]++;
+ blocks[mapid]++;
//Remove wall
solution[mapid] = solution[mapid].replace('.'+y+','+x+'.', '.');
- } else {
+ } else {
//Placing a wall
- if (blocks[mapid] < 1) {
+ if (blocks[mapid] < 1) {
updateDsp(mapid, 'dspWalls', "OUT!");
- return;
- }
- obj.cv = true;
+ return;
+ }
+ obj.cv = true;
childdiv.removeAttribute("class");
childdiv.setAttribute("class", "grid_td_walls");
@@ -135,14 +135,14 @@ function grid_click(obj) { //Add Wall
solution[mapid] += y+','+x+'.';
- blocks[mapid]--;
- }
- //document.getElementById('blocksdisplay').innerHTML = "<b>"+blocks[mapid]+"</b>";
- if (isChallenge == true) {
+ blocks[mapid]--;
+ }
+ //document.getElementById('blocksdisplay').innerHTML = "<b>"+blocks[mapid]+"</b>";
+ if (isChallenge == true) {
challengeWall(mapid);
}
updateDsp(mapid, 'dspWalls', blocks[mapid]+" walls");
- //document.getElementById(mapid+',dspWalls').innerHTML = " "+blocks[mapid]+" walls";
+//document.getElementById(mapid+',dspWalls').innerHTML = " "+blocks[mapid]+" walls";
}
@@ -154,7 +154,7 @@ function updateDsp(mapid, element, data) { handle = document.getElementById(mapid+','+element);
handle.innerHTML = data;
}
- //}
+//}
}
function getmapdata(mapid) {
@@ -321,7 +321,7 @@ function animatePathDone(mapid) { if (isChallenge == true) {
challengeGo(mapid);
}
- //Mark off challenges
+ //Mark off challenges
//TODO: This hack is stupidd :(
if(isChallenge && isTutorial == false)
{
@@ -371,7 +371,7 @@ function doanimate(x, y, p, c, mapid, pathNumber) { var colorScores = '<span class="green">' + mapdata[mapid].moveCount[0] + '</span> + ';
colorScores += '<span class="red">' + mapdata[mapid].moveCount[1] + '</span> = ' + count[mapid] + " moves";
updateDsp(mapid, 'dspCount', colorScores);
- //updateDsp(mapid, 'dspCount', '<span class="green">' + mapdata[mapid].moveCount[0] + ' + ' + mapdata[mapid].moveCount[1] + ' = ' + count[mapid] + " moves");
+ //updateDsp(mapid, 'dspCount', '<span class="green">' + mapdata[mapid].moveCount[0] + ' + ' + mapdata[mapid].moveCount[1] + ' = ' + count[mapid] + " moves");
} else {
updateDsp(mapid, 'dspCount', count[mapid]+ " moves");
}
@@ -390,12 +390,12 @@ function doanimate(x, y, p, c, mapid, pathNumber) { //Maintain our original classname, no matter the cost!
origclass = handle.className;
if ( origclass == 'grid_td_path'+pathNumber+'-1' ||
- origclass == 'grid_td_path'+pathNumber+'-2' ||
- origclass == 'grid_td_path'+pathNumber+'-3' ||
- origclass == 'grid_td_path'+pathNumber+'-4' ) {
- // if (origclass == 'grid_td_animate' || origclass == 'grid_td_animate_pre' ) {
+ origclass == 'grid_td_path'+pathNumber+'-2' ||
+ origclass == 'grid_td_path'+pathNumber+'-3' ||
+ origclass == 'grid_td_path'+pathNumber+'-4' ) {
+ // if (origclass == 'grid_td_animate' || origclass == 'grid_td_animate_pre' ) {
origclass = handle.classOrigName;
- //setTimeout(handle.setAttribute('class', origclass), 850);
+ //setTimeout(handle.setAttribute('class', origclass), 850);
}
//handle.style.backgroundColor = mapdata[mapid].pathColor[pathNumber];
handle.classOrigName = origclass;
@@ -421,58 +421,58 @@ function doanimate(x, y, p, c, mapid, pathNumber) { count[mapid]++;
mapdata[mapid].moveCount[pathNumber]++;
- //Notify users on score levels;
- switch(count[mapid]) {
- //case mapjson[mapid].best:
+ //Notify users on score levels;
+ switch(count[mapid]) {
+ //case mapjson[mapid].best:
//flashelement(mapid+',dspCount', 4, "#FF0000");
- //break;
- case 500:
- case 400:
- //case 350:
- case 300:
- //case 250:
- case 200:
- //case 150:
- case 100:
- //case 50:
- if (checkSound(mapid)) {
- soundManager.setVolume('charm', 40);
- soundManager.setPan('charm', 75)
- soundManager.play('charm');
+ //break;
+ case 500:
+ case 400:
+ //case 350:
+ case 300:
+ //case 250:
+ case 200:
+ //case 150:
+ case 100:
+ //case 50:
+ if (checkSound(mapid)) {
+ soundManager.setVolume('charm', 40);
+ soundManager.setPan('charm', 75)
+ soundManager.play('charm');
+ }
+ //Flash
+ flashelement(mapid+',dspCount', 4);
+ break;
}
- //Flash
- flashelement(mapid+',dspCount', 4);
- break;
- }
- childdiv = document.getElementById('child_'+handle.id);
- if (childdiv.className.indexOf('grid_td_walls') < 0) {
- childdiv.setAttribute('class', 'grid_td_path'+pathNumber+'-'+c);
+ childdiv = document.getElementById('child_'+handle.id);
+ if (childdiv.className.indexOf('grid_td_walls') < 0) {
+ childdiv.setAttribute('class', 'grid_td_path'+pathNumber+'-'+c);
- handle.style.backgroundColor = mapdata[mapid].pathColor[pathNumber];
+ handle.style.backgroundColor = mapdata[mapid].pathColor[pathNumber];
- var string = "if (document.getElementById('"+'child_'+eid+"').className == 'grid_td_path"+pathNumber+'-'+c+"')";
- string += "document.getElementById('"+'child_'+eid+"').removeAttribute('class');";
- setTimeout(string, 855);
+ var string = "if (document.getElementById('"+'child_'+eid+"').className == 'grid_td_path"+pathNumber+'-'+c+"')";
+ string += "document.getElementById('"+'child_'+eid+"').removeAttribute('class');";
+ setTimeout(string, 855);
- //Maintain disabled appearnce of checkpoints
- if (handle.pressed == true) {
- setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '#dddddd';", 865);
- } else {
- setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '';", 865);
+ //Maintain disabled appearnce of checkpoints
+ if (handle.pressed == true) {
+ setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '#dddddd';", 865);
+ } else {
+ setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '';", 865);
+ }
}
- }
- break;
+ break;
//Teleports
case 't': case 'm': case 'g': case 'i': case 'k':
//Outs
case 'u': case 'n': case 'h': case 'j': case 'l':
case 'r':
- // if (handle.pressed == true)
- // break;
- //case 'a': case 'b': case 'c': case 'd': case 'e':
+ // if (handle.pressed == true)
+ // break;
+ //case 'a': case 'b': case 'c': case 'd': case 'e':
//handle.setAttribute('class', 'grid_td_pressed');
//handle.classOrigName = 'grid_td_pressed';
@@ -496,20 +496,20 @@ function doanimate(x, y, p, c, mapid, pathNumber) { setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '#dddddd';", 865);
handle.pressed = true;
} else {
- //mapdata[mapid].usedTiles.push(eid);
- //break;
+ //mapdata[mapid].usedTiles.push(eid);
+ //break;
}
}
if (contains(mapdata[mapid].usedTiles, eid) == false)
mapdata[mapid].usedTiles.push(eid);
- //mapdata[mapid].restoreTiles.push("document.getElementById('"+eid+"').style.backgroundColor = '';");
- //mapdata[mapid].restoreTiles.push("document.getElementById('"+eid+"').pressed = false;");
+ //mapdata[mapid].restoreTiles.push("document.getElementById('"+eid+"').style.backgroundColor = '';");
+ //mapdata[mapid].restoreTiles.push("document.getElementById('"+eid+"').pressed = false;");
- //alert(mapdata[mapid].pathColor[pathNumber]);
+ //alert(mapdata[mapid].pathColor[pathNumber]);
- //break;
+ //break;
}
//Sound effects
@@ -546,28 +546,28 @@ function doanimate(x, y, p, c, mapid, pathNumber) { var improvedScore = (count[mapid] > mapjson[mapid].mybest && mapjson[mapid].mybest != "0");
switch (true) {
case (count[mapid] > mapjson[mapid].best):
- disptext = "Beat "+mapjson[mapid].bestby+"'s record of "+mapjson[mapid].best+" with "+count[mapid]+"!";
- break;
+ disptext = "Beat "+mapjson[mapid].bestby+"'s record of "+mapjson[mapid].best+" with "+count[mapid]+"!";
+ break;
case (count[mapid] == mapjson[mapid].best):
- disptext = "Tied "+mapjson[mapid].bestby+"'s record of "+mapjson[mapid].best;
- break;
+ disptext = "Tied "+mapjson[mapid].bestby+"'s record of "+mapjson[mapid].best;
+ break;
case (mapjson[mapid].mybest == "0"):
- disptext = "You scored "+count[mapid]+"!";
- break;
+ disptext = "You scored "+count[mapid]+"!";
+ break;
case (count[mapid] > mapjson[mapid].mybest):
- disptext = "Improved score "+mapjson[mapid].mybest+ " to "+count[mapid];
- break;
+ disptext = "Improved score "+mapjson[mapid].mybest+ " to "+count[mapid];
+ break;
case (count[mapid] == mapjson[mapid].mybest):
- disptext = "Tied personal best of "+count[mapid];
- break;
+ disptext = "Tied personal best of "+count[mapid];
+ break;
case (count[mapid] < mapjson[mapid].mybest):
- disptext = "You got "+count[mapid]+". Your best is "+mapjson[mapid].mybest;
- break;
+ disptext = "You got "+count[mapid]+". Your best is "+mapjson[mapid].mybest;
+ break;
}
//if anything worth mentioning happend let them know.
if (disptext != "") {
@@ -610,21 +610,21 @@ function doanimate(x, y, p, c, mapid, pathNumber) { selected = selectbox.options[selectbox.selectedIndex].value;
switch (selected) {
case '1':
- rs =120;
- rs =0;
- break;
+ rs =120;
+ rs =0;
+ break;
case '2':
- rs =84;
- break;
+ rs =84;
+ break;
case '3':
- rs =44;
- break;
+ rs =44;
+ break;
case '4':
- rs =22;
- break;
+ rs =22;
+ break;
}
@@ -632,10 +632,18 @@ function doanimate(x, y, p, c, mapid, pathNumber) { //The next path code.
switch(t) {
//Are we just moving someplace?
- case '1': x--; break; //1 - Up
- case '2': y++; break; //2 - Right
- case '3': x++; break; //3 - Down
- case '4': y--; break; //4 - Left
+ case '1':
+ x--;
+ break; //1 - Up
+ case '2':
+ y++;
+ break; //2 - Right
+ case '3':
+ x++;
+ break; //3 - Down
+ case '4':
+ y--;
+ break; //4 - Left
//Special codes within the path.
//Did we aquire a target?
//Checkpoint targets:
@@ -644,7 +652,7 @@ function doanimate(x, y, p, c, mapid, pathNumber) { case 'd': case 'e': case 'f':
rs = rs + 410;
mapdata[mapid].pathColor[pathNumber] = targetColor(t);
- break;
+ break;
//Hey, we've ran into a teleport.
case 'u': //tp1
@@ -677,20 +685,20 @@ function doanimate(x, y, p, c, mapid, pathNumber) { p = 'q'+tmp[2];
//Slow down
rs = rs + 1200;
- break;
+ break;
}
//Remove move from p
p = p.substring(1);
//rs = (10 * p.length) + 40;
// if (mapdata[mapid].moveCount[1] < mapdata[mapid].moveCount[pathNumber] - 2
- // || mapdata[mapid].moveCount[0] < mapdata[mapid].moveCount[pathNumber] - 2)
- // rs = rs + 100;
+ // || mapdata[mapid].moveCount[0] < mapdata[mapid].moveCount[pathNumber] - 2)
+ // rs = rs + 100;
if (count[mapid] % 2 == 1 && rs == 0)
doanimate(x,y,p,t,mapid,pathNumber);
else
setTimeout("doanimate("+x+","+y+",'"+p+"','"+t+"','"+mapid+"','"+pathNumber+"')",rs);
- //setTimeout("doanimate("+x+","+y+",'"+p+"','"+t+"','"+mapid+"','"+pathNumber+"')",1);
+//setTimeout("doanimate("+x+","+y+",'"+p+"','"+t+"','"+mapid+"','"+pathNumber+"')",1);
}
@@ -698,22 +706,22 @@ function doanimate(x, y, p, c, mapid, pathNumber) { function targetColor(target) {
var r = '#ccc';
switch(target) {
- case 'a':
+ case 'a':
r = '#F777FF';
- break;
- case 'b':
+ break;
+ case 'b':
r = '#FFFF11';
- break;
- case 'c':
+ break;
+ case 'c':
r = '#FF4466';
- break;
- case 'd':
+ break;
+ case 'd':
r = '#ff9911';
- break;
- case 'e':
+ break;
+ case 'e':
r = '#00FFFF';
- break;
- case 'f':
+ break;
+ case 'f':
r = '#ccc';
}
return r;
@@ -745,24 +753,24 @@ function flashelement(eid, times, color, speed) { //Flash out
setTimeout("document.getElementById('"+eid+"').style.color = ''", (i*speed) + speedon);
setTimeout("document.getElementById('"+eid+"').style.backgroundColor = ''", (i*speed) + speedon);
- // setTimeout("document.getElementById('"+mapid+",dspCount').style.fontWeight = ''", i*200);
+ // setTimeout("document.getElementById('"+mapid+",dspCount').style.fontWeight = ''", i*200);
}
//setTimeout("document.getElementById('"+eid+"').className = '"+currentclass+"'", (i*220) + 200);
setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '"+currentColor+"'", (i*speed) + 200);
- //document.getElementById(eid).className=currentclass;
- //document.getElementById(eid).style.backgroundColor=currentColor;
+//document.getElementById(eid).className=currentclass;
+//document.getElementById(eid).style.backgroundColor=currentColor;
}
function contains(a, obj) {
- var i = a.length;
- while (i--) {
- if (a[i] === obj) {
- return true;
- }
- }
- return false;
+ var i = a.length;
+ while (i--) {
+ if (a[i] === obj) {
+ return true;
+ }
+ }
+ return false;
}
@@ -782,18 +790,28 @@ function dullColor(colorAsHex, value) { //Color modifications
// Thanks javascripter.net
-function rgbToHex(R,G,B) {return toHex(R)+toHex(G)+toHex(B)}
+function rgbToHex(R,G,B) {
+ return toHex(R)+toHex(G)+toHex(B)
+ }
function toHex(n) {
- n = parseInt(n,10);
- if (isNaN(n)) return "00";
- n = Math.max(0,Math.min(n,255));
- return "0123456789ABCDEF".charAt((n-n%16)/16)
- + "0123456789ABCDEF".charAt(n%16);
+ n = parseInt(n,10);
+ if (isNaN(n)) return "00";
+ n = Math.max(0,Math.min(n,255));
+ return "0123456789ABCDEF".charAt((n-n%16)/16)
+ + "0123456789ABCDEF".charAt(n%16);
}
-function hexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
-function hexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
-function hexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
-function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}
+function hexToR(h) {
+ return parseInt((cutHex(h)).substring(0,2),16)
+ }
+function hexToG(h) {
+ return parseInt((cutHex(h)).substring(2,4),16)
+ }
+function hexToB(h) {
+ return parseInt((cutHex(h)).substring(4,6),16)
+ }
+function cutHex(h) {
+ return (h.charAt(0)=="#") ? h.substring(1,7):h
+ }
//Thanks stackExchange
function rgbStringToHex(rgbString) {
@@ -828,16 +846,16 @@ function setCookie(c_name,value,exdays) }
function getCookie(c_name)
{
-var i,x,y,ARRcookies=document.cookie.split(";");
-for (i=0;i<ARRcookies.length;i++)
-{
- x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
- y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
- x=x.replace(/^\s+|\s+$/g,"");
- if (x==c_name)
- {
- return unescape(y);
- }
- }
- return "";
+ var i,x,y,ARRcookies=document.cookie.split(";");
+ for (i=0;i<ARRcookies.length;i++)
+ {
+ x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
+ y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
+ x=x.replace(/^\s+|\s+$/g,"");
+ if (x==c_name)
+ {
+ return unescape(y);
+ }
+ }
+ return "";
}
|