X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=web%2Fqwebchess%2Fjs.js;h=3474c3ac61d2fa7a15e8bc6eb2841600a70a6f14;hb=2ba4947e874b674fe54369932d4675119715a035;hp=db91e14d7dd7c01f6d59f0fd709e09d533653b90;hpb=538a32cb30f21a1a48653d7b639ab0c82db44d83;p=progcomp2013.git
diff --git a/web/qwebchess/js.js b/web/qwebchess/js.js
index db91e14..3474c3a 100644
--- a/web/qwebchess/js.js
+++ b/web/qwebchess/js.js
@@ -6,13 +6,13 @@
*/
pieceSelected = ""; // currently selected piece
-playerColour = "W"; // colour of this player
+playerColour = ""; // colour of this player
// Unicode representations of chess pieces
pieceChar = {"W" : { "p" : "\u2659", "h" : "\u2658", "b" : "\u2657", "r" : "\u2656", "q" : "\u2655", "k" : "\u2654", "?" : "?"},
"B" : { "p" : "\u265F", "h" : "\u265E", "b" : "\u265D", "r" : "\u265C", "q" : "\u265B", "k" : "\u265A", "?" : "?"}};
-emptyHTML = " "
+emptyHTML = ""
gameStarted = false;
canClick = true;
@@ -32,7 +32,7 @@ $(document).ready(function()
$("#status").html("white SELECT?");
$("#start").html("Quit Game");
pieceSelected = "";
- canClick = true;
+ canClick = false;
$.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "force_quit"}, success : function() {}});
$.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "start"}}).done(function(data) {$(this).update(data)});
@@ -44,6 +44,7 @@ $(document).ready(function()
$("#welcome").show();
$("#status").html("Game over");
$("#start").html("New Game");
+ canClick = false;
$.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "quit"}, success : function() {console.log("Quit game");}});
}
});
@@ -87,7 +88,10 @@ $(document).ready(function()
}
if (legal)
+ {
+ canClick = false;
$.ajax({url : "/cgi-bin/qchess.cgi", data : {x : id[0], y : id[1]}}).done(function(data) {$(this).update(data)});
+ }
});
$.fn.showMoves = function()
@@ -213,7 +217,7 @@ $(document).ready(function()
$(this).html(emptyHTML);
// Collapse into quantum state if on a black square
- if ((dest.getX() + dest.getY()) % 2 != 0 && (dest.html()[0] == '?' || dest.html()[dest.html().length-1] == '?'))
+ if ((dest.getX() + dest.getY()) % 2 != 0 && (dest.html()[0] == '?' || dest.html()[dest.html().length-1] != dest.html()[0]))
{
oldHTML = dest.html();
dest.html(oldHTML.replace(/.*<\/bold>/i, "?"));
@@ -225,6 +229,7 @@ $(document).ready(function()
{
console.log("AJAX Response:\n"+data);
var lines = data.split("\n");
+ var timeout = false;
for (var i = 0; i < lines.length; ++i)
{
var tokens = lines[i].split(" ");
@@ -237,7 +242,7 @@ $(document).ready(function()
if (s1.html()[4] != '0')
{
s2 = $("#board").find("#"+tokens[3]+tokens[4]);
- canClick = false;
+ timeout = true;
setTimeout((function(x)
{
return function()
@@ -279,12 +284,25 @@ $(document).ready(function()
}
else switch (lines[i])
{
+
case "SELECT?":
pieceSelected = "";
case "MOVE?":
case "":
case "New game.":
break;
+ case "START white":
+ if (playerColour == "")
+ {
+ playerColour = "W";
+ break;
+ }
+ case "START black":
+ if (playerColour == "")
+ {
+ playerColour = "B";
+ break;
+ }
default:
alert("Game ends: " + lines[i]);
gameStarted = false;
@@ -296,6 +314,8 @@ $(document).ready(function()
break;
}
}
+ if (timeout == false)
+ canClick = true;
}
//Reset the colour of a square
@@ -335,7 +355,7 @@ $(document).ready(function()
boardHTML += "";
for (var x = 0; x < 8; ++x)
{
- boardHTML += ""+emptyHTML+" | ";
+ boardHTML += ""+emptyHTML+" | ";
}
boardHTML += "
";
}