diff options
author | raylu <raylu@cmu.edu> | 2011-04-07 00:27:27 -0400 |
---|---|---|
committer | raylu <raylu@cmu.edu> | 2011-04-07 00:27:27 -0400 |
commit | f8c9eb5220afaf2f9a62f9a176a45913240f4081 (patch) | |
tree | 99775178acfcef6e86e39184be0ac96083042f1b /js | |
download | pathery-f8c9eb5220afaf2f9a62f9a176a45913240f4081.tar.xz |
Initial import from Dropbox
Diffstat (limited to 'js')
-rw-r--r-- | js/ajax.js | 195 | ||||
-rw-r--r-- | js/mapspecs.js | 688 |
2 files changed, 883 insertions, 0 deletions
diff --git a/js/ajax.js b/js/ajax.js new file mode 100644 index 0000000..4b1dd50 --- /dev/null +++ b/js/ajax.js @@ -0,0 +1,195 @@ +/* Simple AJAX Code-Kit (SACK) v1.6.1 */
+/* ©2005 Gregory Wild-Smith */
+/* www.twilightuniverse.com */
+/* Software licenced under a modified X11 licence,
+ see documentation or authors website for more details */
+
+function sack(file) {
+ this.xmlhttp = null;
+
+ this.resetData = function() {
+ this.method = "POST";
+ this.queryStringSeparator = "?";
+ this.argumentSeparator = "&";
+ this.URLString = "";
+ this.encodeURIString = true;
+ this.execute = false;
+ this.element = null;
+ this.elementObj = null;
+ this.requestFile = file;
+ this.vars = new Object();
+ this.responseStatus = new Array(2);
+ };
+
+ this.resetFunctions = function() {
+ this.onLoading = function() { };
+ this.onLoaded = function() { };
+ this.onInteractive = function() { };
+ this.onCompletion = function() { };
+ this.onError = function() { };
+ this.onFail = function() { };
+ };
+
+ this.reset = function() {
+ this.resetFunctions();
+ this.resetData();
+ };
+
+ this.createAJAX = function() {
+ try {
+ this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e1) {
+ try {
+ this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (e2) {
+ this.xmlhttp = null;
+ }
+ }
+
+ if (! this.xmlhttp) {
+ if (typeof XMLHttpRequest != "undefined") {
+ this.xmlhttp = new XMLHttpRequest();
+ } else {
+ this.failed = true;
+ }
+ }
+ };
+
+ this.setVar = function(name, value){
+ this.vars[name] = Array(value, false);
+ };
+
+ this.encVar = function(name, value, returnvars) {
+ if (true == returnvars) {
+ return Array(encodeURIComponent(name), encodeURIComponent(value));
+ } else {
+ this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
+ }
+ }
+
+ this.processURLString = function(string, encode) {
+ encoded = encodeURIComponent(this.argumentSeparator);
+ regexp = new RegExp(this.argumentSeparator + "|" + encoded);
+ varArray = string.split(regexp);
+ for (i = 0; i < varArray.length; i++){
+ urlVars = varArray[i].split("=");
+ if (true == encode){
+ this.encVar(urlVars[0], urlVars[1]);
+ } else {
+ this.setVar(urlVars[0], urlVars[1]);
+ }
+ }
+ }
+
+ this.createURLString = function(urlstring) {
+ if (this.encodeURIString && this.URLString.length) {
+ this.processURLString(this.URLString, true);
+ }
+
+ if (urlstring) {
+ if (this.URLString.length) {
+ this.URLString += this.argumentSeparator + urlstring;
+ } else {
+ this.URLString = urlstring;
+ }
+ }
+
+ // prevents caching of URLString
+ this.setVar("rndval", new Date().getTime());
+
+ urlstringtemp = new Array();
+ for (key in this.vars) {
+ if (false == this.vars[key][1] && true == this.encodeURIString) {
+ encoded = this.encVar(key, this.vars[key][0], true);
+ delete this.vars[key];
+ this.vars[encoded[0]] = Array(encoded[1], true);
+ key = encoded[0];
+ }
+
+ urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
+ }
+ if (urlstring){
+ this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
+ } else {
+ this.URLString += urlstringtemp.join(this.argumentSeparator);
+ }
+ }
+
+ this.runResponse = function() {
+ eval(this.response);
+ }
+
+ this.runAJAX = function(urlstring) {
+ if (this.failed) {
+ this.onFail();
+ } else {
+ this.createURLString(urlstring);
+ if (this.element) {
+ this.elementObj = document.getElementById(this.element);
+ }
+ if (this.xmlhttp) {
+ var self = this;
+ if (this.method == "GET") {
+ totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
+ this.xmlhttp.open(this.method, totalurlstring, true);
+ } else {
+ this.xmlhttp.open(this.method, this.requestFile, true);
+ try {
+ this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
+ } catch (e) { }
+ }
+
+ this.xmlhttp.onreadystatechange = function() {
+ switch (self.xmlhttp.readyState) {
+ case 1:
+ self.onLoading();
+ break;
+ case 2:
+ self.onLoaded();
+ break;
+ case 3:
+ self.onInteractive();
+ break;
+ case 4:
+ self.response = self.xmlhttp.responseText;
+ self.responseXML = self.xmlhttp.responseXML;
+ self.responseStatus[0] = self.xmlhttp.status;
+ self.responseStatus[1] = self.xmlhttp.statusText;
+
+ if (self.execute) {
+ self.runResponse();
+ }
+
+ if (self.elementObj) {
+ elemNodeName = self.elementObj.nodeName;
+ elemNodeName.toLowerCase();
+ if (elemNodeName == "input"
+ || elemNodeName == "select"
+ || elemNodeName == "option"
+ || elemNodeName == "textarea") {
+ self.elementObj.value = self.response;
+ } else {
+ self.elementObj.innerHTML = self.response;
+ }
+ }
+ if (self.responseStatus[0] == "200") {
+ self.onCompletion();
+ } else {
+ self.onError();
+ }
+
+ self.URLString = "";
+ break;
+ }
+ };
+
+ this.xmlhttp.send(this.URLString);
+ }
+ }
+ };
+
+ this.reset();
+ this.createAJAX();
+}
+
+var ajax = new sack(); //VGR26042006 ADDed declaration here
\ No newline at end of file diff --git a/js/mapspecs.js b/js/mapspecs.js new file mode 100644 index 0000000..fe58658 --- /dev/null +++ b/js/mapspecs.js @@ -0,0 +1,688 @@ +//
+// 1.0
+//
+//
+//
+
+window.onload = function(){
+ //document.getElementById('blocksdisplay').innerHTML = "<b>"+blocks+"</b>";
+ //doSend();
+ loadSol();
+}
+
+var solution = new Array();
+var blocks = new Array();
+var count = new Array();
+var mapdata = new Array();
+var mapjson = new Array();
+var htmlscores = '';
+
+function loadSol(sol) {
+ //alert("Temporary debug");
+ //document.getElementById('debug').innerHTML = "<br />Exe1...";
+ if (sol == null)
+ if (document.getElementById('mapsol') != undefined)
+ sol = document.getElementById('mapsol').innerHTML;
+
+ if (sol) {
+
+ tmp = sol.split(':');
+ position = tmp[1].split('.');
+ mapid = tmp[0];
+
+ clearwalls(mapid);
+
+ //document.getElementById('debug').innerHTML += "<br />"+mapid+','+position[1];
+ for(var i in position) {
+ //document.getElementById('debug').innerHTML += "<br />"+mapid+','+position[i];
+ if (document.getElementById(mapid+','+position[i]) != undefined) {
+ object = document.getElementById(mapid+','+position[i]);
+ grid_click(object);
+
+ }
+ //alert(soldata[i]);
+ }
+ }
+}
+
+function grid_click(obj) {
+
+ //Prepare data
+ tmp = obj.id.split(',');
+ mapid = tmp[0] - 0;
+ y = tmp[1];
+ x = tmp[2];
+
+ if (solution[mapid] == undefined) {
+ getmapdata(mapid);
+ }
+ //alert(obj.cv);
+
+ if (obj.cv) {
+ obj.cv = false;
+
+ //obj.style.backgroundColor = '#ffffff';
+ obj.setAttribute("class", "grid_td");
+ //IE 7
+ obj.style.backgroundColor = '';
+ blocks[mapid]++;
+ //alert(obj.id);
+ //Remove wall
+ solution[mapid] = solution[mapid].replace('.'+y+','+x+'.', '.');
+ //alert(y+','+x+'.');
+ } else {
+ if (blocks[mapid] < 1) {
+ //alert("Outa blocks!");
+ updateDsp(mapid, 'dspWalls', "OUT!");
+ //document.getElementById(mapid+',dspWalls').innerHTML = "OUT!";
+ return;
+ }
+ obj.cv = true;
+ //obj.style.backgroundColor = '#ff0000';
+ obj.setAttribute("class", "grid_td_walls");
+ //IE 7:
+ obj.style.backgroundColor = '#666666';
+ //Add Wall
+ solution[mapid] += y+','+x+'.';
+ blocks[mapid]--;
+ }
+ //document.getElementById('blocksdisplay').innerHTML = "<b>"+blocks[mapid]+"</b>";
+
+ updateDsp(mapid, 'dspWalls', blocks[mapid]+" walls");
+ //document.getElementById(mapid+',dspWalls').innerHTML = " "+blocks[mapid]+" walls";
+
+}
+
+function updateDsp(mapid, element, data) {
+ if (mapdata[mapid] == undefined)
+ return;
+ if (mapdata[mapid].example != true) {
+ if (document.getElementById(mapid+','+element) != undefined) {
+ handle = document.getElementById(mapid+','+element);
+ handle.innerHTML = data;
+ }
+ }
+}
+
+function getmapdata(mapid) {
+ //alert(typeof(JSON));
+ if (typeof(JSON) == 'undefined') {
+ //alert("We're using EVAL instead");
+ text = document.getElementById(mapid+',mapdata').innerHTML;
+ mapdata[mapid] = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')');
+ //mapdata[mapid] = eval(document.getElementById(mapid+',mapdata').innerHTML);
+ } else {
+ //alert("We're using JSON");
+ mapdata[mapid] = JSON.parse(document.getElementById(mapid+',mapdata').innerHTML);
+ }
+
+ blocks[mapid] = mapdata[mapid].walls;
+ solution[mapid] = '.';
+
+ updateDsp(mapid, 'dspWalls', blocks[mapid]+" walls");
+
+ //document.getElementById(mapid+',dspWalls').innerHTML = " "+blocks[mapid]+" walls";
+ //document.getElementById(mapid+',dspWalls').innerHTML = blocks[mapid];
+}
+
+function doSend(mapid) {
+ if (solution[mapid] == undefined) {
+ getmapdata(mapid);
+ }
+
+ reqstr = "";
+ reqstr += "&mapcode="+mapdata[mapid].code;
+ reqstr += "&mapid="+mapid;
+ //alert (mapdata[mapid].code);
+ reqstr += "&solution="+solution[mapid];
+
+ //alert(reqstr);
+ //document.getElementById('dispdo').innerHTML = "http://mazetd.4xg.net/do.php?r=getpath"+reqstr
+
+ //alert("request string:"+reqstr);
+ ajax.requestFile = "do.php?r=getpath"+reqstr; //prepare strdata
+ ajax.onCompletion = request_path_done; // Specify function to be executed on response.
+ ajax.runAJAX();// Do it!
+}
+
+function requestSol(solid) {
+ //alert("requesting solution id:" + solid);
+ ajax.requestFile = "do.php?r=getsol&solutionid="+solid; //prepare strdata
+ ajax.onCompletion = requestSolDone; // Specify function to be executed on response.
+ ajax.runAJAX();// Do it!
+}
+
+function requestSolDone() {
+ //alert("request complete");
+
+ if (typeof(JSON) == 'undefined') {
+ //alert("We're using EVAL instead AGAIN.");
+ text = ajax.response;
+ var JO = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')');
+ //mapdata[mapid] = eval(document.getElementById(mapid+',mapdata').innerHTML);
+ } else {
+ //alert("We're using JSON again");
+ var JO = JSON.parse(ajax.response);
+ }
+
+ clearwalls(JO.mapid);
+ loadSol(JO.mapid + ":" + JO.solution);
+}
+
+function clearwalls(mapid) {
+ if (solution[mapid] == undefined) return;
+ walls = solution[mapid].split('.');
+ for(var i in walls) {
+ //alert(walls[i]);
+ tmp = walls[i].split(',');
+ eid = mapid+','+tmp[0]+','+tmp[1];
+ //alert('eid:'+eid);
+ if (document.getElementById(eid) != undefined) {
+ obj = document.getElementById(eid);
+ obj.setAttribute("class", "grid_td");
+ obj.style.backgroundColor = '';
+ obj.cv = false;
+ //alert("exe");
+ }
+ }
+ solution[mapid] = undefined;
+ getmapdata(mapid);
+}
+
+function resetwalls(mapid) {
+ answer = confirm("Remove walls and start fresh?");
+ if (answer) {
+ clearwalls(mapid);
+ }
+}
+
+function request_path_done() {
+ //document.getElementById('mapdisplay').innerHTML = ajax.response;
+ //alert ("resp: "+ajax.response);
+ //if (ajax.response == undefined) return;
+
+ if (typeof(JSON) == 'undefined') {
+ //alert("We're using EVAL instead AGAIN.");
+ text = ajax.response;
+ var JO = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')');
+ //mapdata[mapid] = eval(document.getElementById(mapid+',mapdata').innerHTML);
+ } else {
+ //alert("We're using JSON again");
+ var JO = JSON.parse(ajax.response);
+ }
+
+ mapjson[JO.mapid] = JO;
+
+ //alert ("resp: "+ajax.response);
+ // if (typeof(JSON) == undefined) {
+ // var JO = eval(ajax.response);
+ // } else {
+ // var JO = JSON.parse(ajax.response);
+ // }
+ if (JO.scores) {
+ updateDsp(JO.mapid, 'dspScore', JO.scores);
+ }
+
+ for(var i in JO.error) {
+ alert('\n JO error ' + JO.error[i]);
+ }
+
+ //document.getElementById('disp').innerHTML = JO.map;
+
+ if (JO.blocked) {
+ alert("Path is blocked make sure there is a way for it to go!");
+ return;
+ }
+ //document.write(JO.map);
+ //alert ("moves: "+JO.moves);
+ //alert ("path: "+JO.start);
+ //document.getElementById('disppath').innerHTML = JO.path;
+ //document.getElementById('disptotalmoves').innerHTML = JO.moves;
+ var disptext = "Record: "+JO.best+" by "+JO.bestby;
+
+ updateDsp(JO.mapid, 'dspID', disptext);
+ //document.getElementById(JO.mapid+',dspID').innerHTML = JO.best;
+
+ animatePath(JO.path, JO.mapid, JO.start);
+
+ //Get score update.
+ ajax.requestFile = "do.php?r=getscores&mapid="+JO.mapid; //prepare strdata
+ ajax.onCompletion = request_scores_done; // Specify function to be executed on response.
+ ajax.runAJAX();// Do it!
+}
+
+function animatePath(path, mapid, start) {
+ tmp = start.split(',');
+ y = tmp[0];
+ x = tmp[1];
+
+ p = path;
+ //alert("Begin");
+ //t = p.length;
+ t = '';
+ //count[mapid] = 0;
+ document.getElementById(mapid+',btn').disabled = true;
+ doanimate(x, y, p, t, mapid);
+ //setTimeout("doanimate("+x+","+y+",'"+p+"',"+t+")",500);
+}
+
+function animatePathDone(mapid) {
+ document.getElementById(mapid+',btn').disabled = false;
+ //alert("animate done..." + htmlscores);
+ if (htmlscores) {
+ //alert("showing scores...");
+ updateDsp(mapid, 'dspScore', htmlscores);
+ htmlscores = '';
+ }
+}
+
+function request_scores_done() {
+
+ //alert("score request complete");
+ //Get scores.
+ if (typeof(JSON) == 'undefined') {
+ //alert("We're using EVAL instead AGAIN.");
+ text = ajax.response;
+ var JO = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')');
+ //mapdata[mapid] = eval(document.getElementById(mapid+',mapdata').innerHTML);
+ } else {
+ //alert("We're using JSON again");
+ var JO = JSON.parse(ajax.response);
+ }
+ //alert("scores saveing " + JO.scores);
+ htmlscores = JO.scores;
+}
+
+
+function checkSound(mapid) {
+ if (document.getElementById(mapid+',mute').checked) {
+ return false;
+ }
+ if (typeof(soundManager) != 'object') {
+ return false;
+ }
+ return true;
+}
+
+var snake = new Array();
+var snakeeffected = new Array();
+function doanimate(x, y, p, c, mapid) {
+
+ //x, y position
+ //p path string being trunicated.
+ //c current target code.
+ //t next target code.
+ t = p.substring(0, 1);
+
+ //Animate current square, and move to next one.
+ if (count[mapid] == undefined) {
+ count[mapid] = 0;
+ }
+ //alert("test");
+ if (snake[mapid] == undefined) {
+ snake[mapid] = new Array();
+ snake[mapid]['color'] = '#4444bb';
+ }
+
+ //Display movecount
+ updateDsp(mapid, 'dspCount', count[mapid]+ " moves");
+ //document.getElementById(mapid+',dspCount').innerHTML = count[mapid]+ " moves";
+
+ //Get a handle on the element.
+ eid = mapid+','+x+','+y;
+ //Verify.
+ if (document.getElementById(eid) == undefined) {
+ alert("Path exited field..?");
+ animatePathDone(mapid);
+ return;
+ }
+ handle = document.getElementById(eid);
+
+ //Maintain our original classname, no matter the cost!
+ origclass = handle.className;
+ if ( origclass == 'grid_td_path1' ||
+ origclass == 'grid_td_path2' ||
+ origclass == 'grid_td_path3' ||
+ origclass == 'grid_td_path4' ) {
+ // if (origclass == 'grid_td_animate' || origclass == 'grid_td_animate_pre' ) {
+ origclass = handle.classOrigName;
+ //setTimeout(handle.setAttribute('class', origclass), 850);
+ //alert('ex ' + origclass);
+ }
+ //handle.style.backgroundColor = snake[mapid]['color'];
+ handle.classOrigName = origclass;
+
+
+ //Animate.
+ switch(c) {
+ case '1': //1 - Up
+ case '2': //2 - Right
+ case '3': //3 - Down
+ case '4': //4 - Left
+ count[mapid]++;
+
+ 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.play('charm');
+ }
+ //alert("count-hit: "+count[mapid]);
+ //Flash
+ flashelement(mapid+',dspCount', 4);
+ break;
+ }
+ //if (checkSound(mapid)) {
+ //soundManager.play('bling');
+ //soundManager.play('sc');
+ //soundManager.setVolume('click', 50);
+ //soundManager.play('click');
+ //soundManager.play('charm');
+ //soundManager.play('ufoblip');
+ //}
+ handle.setAttribute('class', 'grid_td_path'+c);
+ handle.className = 'grid_td_path'+c;
+ handle.style.backgroundColor = snake[mapid]['color'];
+
+ string = "if (document.getElementById('"+eid+"').className == 'grid_td_path"+c+"') ";
+ string += "document.getElementById('"+eid+"').className = '"+origclass+"';";
+ //alert (string);
+ setTimeout(string, 855);
+ //And incase that didn't work...
+ //setTimeout("document.getElementById('"+eid+"').className = '"+origclass+"'", 7500);
+ //setTimeout("document.getElementById('"+eid+"').setAttribute('class', '"+origclass+"')", 855);
+
+ if (handle.pressed == true) {
+ setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '#dddddd';", 865);
+ } else {
+ //alert(eid);
+ setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '';", 865);
+ }
+
+ break;
+ //Teleports
+ case 't':
+ //case 'u':
+ case 'm':
+ case 'g':
+ case 'i':
+ case 'k':
+ //case 'n':
+ // if (t == "u" || t == "n") {
+ //alert("teleport");
+ //if (checkSound(mapid)) {
+ //soundManager.play('bling');
+ //soundManager.play('sc');
+ //soundManager.play('ufoblip');
+ //soundManager.play('002');
+ //soundManager.play('003');
+ //soundManager.setVolume('click', 50);
+ //soundManager.play('click');
+ //soundManager.play('charm');
+ //}
+ //flashelement(eid, 4);
+
+ // } else {
+ // break;
+ // }
+ //Targets
+ case 'q': //Teleport out;
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'e':
+
+ //break
+ case 'r':
+ //handle.setAttribute('class', 'grid_td_pressed');
+ //handle.classOrigName = 'grid_td_pressed';
+ snakeeffected.push("document.getElementById('"+eid+"').style.backgroundColor = '';");
+ snakeeffected.push("document.getElementById('"+eid+"').pressed = false;");
+ handle.style.backgroundColor = '#dddddd';
+ setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '#dddddd';", 865);
+ handle.pressed = true;
+
+ break;
+ }
+
+ //Sound effects
+ if (c == 'r') {
+ if (checkSound(mapid)) {
+ soundManager.play('bling');
+ //soundManager.play('blip');
+ //soundManager.play('charm');
+ }
+ }
+
+ //Done messing with current target
+ //Now take pre-action regarding the next tile.
+
+ //Speaking of the next tile - does it exist?
+ //End of the line?
+ if (t == '') {
+
+ //Did we beat or tie any records?
+ //Saw someone do this, thought it was clever.
+ //Switch for range result.
+ var disptext = ""
+ switch (true) {
+ case (count[mapid] > mapjson[mapid].best):
+ 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;
+
+ case (count[mapid] > mapjson[mapid].mybest):
+ disptext = "Improved score "+mapjson[mapid].mybest+ " to "+count[mapid];
+ break;
+
+ case (count[mapid] == mapjson[mapid].mybest):
+ disptext = "Tied personal best of "+count[mapid];
+ break;
+
+ }
+ //if anything worth mentioning happend let them know.
+ if (disptext != "") {
+ if (checkSound(mapid)) {
+ soundManager.play('charm');
+ soundManager.play('bling');
+ soundManager.play('sc');
+ }
+ updateDsp(mapid, 'dspID', disptext);
+ flashelement(mapid+',dspID', 8, "#FF3377");
+ }
+
+ //This is the end, lets reset stuff to defaults.
+ count[mapid] = 0;
+ snake[mapid]['color'] = '#4444bb';
+ //Bring the color back to our checkpoints/teleports.
+ for(var i in snakeeffected) {
+ //eval(snakeeffected[i]);
+ setTimeout((snakeeffected[i]), 2000);
+ }
+ //Clear
+ snakeeffected = new Array();
+ //We're done,
+ animatePathDone(mapid);
+ return;
+ }
+
+
+ //The next tile exists, how fast should we get there?
+ rs = 85;
+ //How fast should we be going?
+ selectbox = document.getElementById(mapid+',speed');
+ selected = selectbox.options[selectbox.selectedIndex].value;
+ switch (selected) {
+ case '1':
+ rs =310;
+ break;
+
+ case '2':
+ rs =85;
+ break;
+
+ case '3':
+ rs =45;
+ break;
+
+ case '4':
+ rs =23;
+ break;
+
+ }
+
+
+ //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
+ //Special codes within the path.
+ //Did we aquire a target?
+ //Checkpoint targets:
+ case 'a':
+ // rs = rs * 9;
+ snake[mapid]['color'] = '#F777FF';
+ break;
+ case 'b':
+ rs = rs + 500;
+ snake[mapid]['color'] = '#FFFF11';
+ //handle.style.backgroundColor = "#000000";
+ break;
+ case 'c':
+ rs = rs + 500;
+ snake[mapid]['color'] = '#FF4466';
+ break;
+ case 'd':
+ rs = rs + 500;
+ snake[mapid]['color'] = '#ff9911';
+ break;
+ case 'e':
+ rs = rs + 500;
+ snake[mapid]['color'] = '#00FFFF';
+ break;
+ //Finish target
+ case 'f':
+ rs = rs + 500;
+ snake[mapid]['color'] = '#4444bb';
+ break;
+
+ //Hey, we've ran into a teleport.
+ case 'u': //tp1
+ case 'n': //tp2
+ case 'h': //tp3
+ case 'j': //tp4
+ case 'l': //tp5
+ //Get teleport coords
+ tmp = p.split(t);
+ loc = tmp[1].split(',');
+ y = loc[0];
+ x = loc[1];
+
+ //Flash teleport-out
+ //Teleport Element ID
+ tpEid = mapid+','+x+','+y;
+ if (checkSound(mapid)) {
+ soundManager.play('ufoblip');
+ //soundManager.play('002');
+ //soundManager.play('003');
+ }
+ //alert(tpEid);
+ document.getElementById(eid).style.backgroundColor='#CCCCCC';
+ document.getElementById(tpEid).style.backgroundColor='#CCCCCC';
+ //flashelement(eid, 7);
+ flashelement(tpEid, 8, snake[mapid]['color']);
+
+
+ //The path once teleported - and an r to indicate to gray the teleport-out too.
+ p = 'q'+tmp[2];
+ //Slow down
+ rs = rs + 1500;
+ setTimeout("doanimate("+x+","+y+",'"+p+"','"+t+"',"+mapid+")",rs);
+ return;
+ break;
+ }
+ //Remove move from p
+ p = p.substring(1);
+ //rs = (10 * p.length) + 40;
+
+ setTimeout("doanimate("+x+","+y+",'"+p+"','"+t+"','"+mapid+"')",rs);
+}
+
+function flashelement(eid, times, color) {
+ //alert("exe"+eid);
+ if (document.getElementById(eid) == undefined) return;
+ if (!color) {
+ color = "#FFFF44";
+ }
+ //document.getElementById(eid).setAttribute('class', 'no_transition');
+ var currentclass = document.getElementById(eid).className;
+ if (document.getElementById(eid).classOrigName != undefined)
+ currentclass = document.getElementById(eid).classOrigName;
+ var currentColor = document.getElementById(eid).style.backgroundColor;
+ document.getElementById(eid).className='no_transition '+currentclass;
+ document.getElementById(eid).style.backgroundColor = '#000000';
+ for (var i=0; i<times; i++) {
+ //Flash bright
+ setTimeout("document.getElementById('"+eid+"').style.color = '#000000'", i*220);
+ setTimeout("document.getElementById('"+eid+"').style.backgroundColor = '"+color+"'", i*220);
+ // setTimeout("document.getElementById('"+mapid+",dspCount').style.fontWeight = 'bold'", i*200);
+ //Flash out
+ setTimeout("document.getElementById('"+eid+"').style.color = ''", (i*220) + 100);
+ setTimeout("document.getElementById('"+eid+"').style.backgroundColor = ''", (i*220) + 100);
+ // 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*220) + 200);
+ //document.getElementById(eid).className=currentclass;
+ //document.getElementById(eid).style.backgroundColor=currentColor;
+}
+
+
+
+function savePref(pref, value) {
+ setCookie('pref_'+pref, value,31);
+}
+
+//Cookie function from w3schools.com
+function setCookie(c_name,value,exdays)
+{
+ var exdate=new Date();
+ exdate.setDate(exdate.getDate() + exdays);
+ var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
+ document.cookie=c_name + "=" + c_value;
+}
+
+
+
+
+//== Outdated functions
+var de = false;
+function displaymap(obj) {
+ if (de == false) {
+ obj.setAttribute('class', 'mapdisplay_up');
+ }
+}
+function minmap(obj) {
+ de = true;
+ obj.setAttribute('class', 'mapdisplay');
+ setTimeout("de = false;", 1000);
+}
+//== End
+
|