From 864bce4ebdc625468969891b36784490448ceea3 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 8 May 2015 21:14:22 +0200 Subject: Bug fixing and win checking in gameserver --- gameserver/gameserver.html | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'gameserver/gameserver.html') diff --git a/gameserver/gameserver.html b/gameserver/gameserver.html index d8528ab..7fc27fc 100644 --- a/gameserver/gameserver.html +++ b/gameserver/gameserver.html @@ -74,19 +74,33 @@ function preinit(){ MOVES.push(arg[1]); addmovelistrow(arg[1]); nextmove(); - } else alert(arg[1]); - } else if(cmd=="your_turn"){ - canAlreadyTurn=true; - if(hasInited){ + } else { + alert(arg[1]); enableClicking(true,isFirstMove&&imPlayer==1); - isFirstMove=false; } + } else if(cmd=="other_turn"){ if(arg){ MOVES.push(arg); addmovelistrow(arg); nextmove(); } - } + } else if(cmd=="your_turn"){ + canAlreadyTurn=true; + if(hasInited){ + enableClicking(true,isFirstMove&&imPlayer==1); + isFirstMove=false; + } + } else if(cmd=="game_stop"){ + alert("Game has been stopped:\n"+arg); + enableClicking(false); + } else if(cmd=="game_win"){ + bgcell(neuidx).classList.add("win"); + if(arg==imPlayer){ + alert("You have won the game!"); + } else { + alert("You have lost the game! Better luck next time."); + } + } else alert("Unrecognised message "+msg); }); ws.addEventListener("open",function(){ ws.send("nick"); @@ -262,8 +276,8 @@ function addmovelistrow(mv,i/*optional*/){ if(moveidx==target)return; while(moveidxtarget)prevmove(true); - setselectedmovelistline(i+1); - };})(i+1)); + setselectedmovelistline(target); + };})(i-1)); movelisttbody.appendChild(tr); } @@ -339,7 +353,7 @@ function nextmove(notimeout){ fgcells[neuidx]=null; neuidx=newidx; - if(moveidx==MOVES.length-1)bgcell(neuidx).classList.add("win"); + //if(moveidx==MOVES.length-1)bgcell(neuidx).classList.add("win"); } newidx=indexafterslide(MOVES[moveidx][1],MOVES[moveidx][2]); @@ -371,7 +385,9 @@ function prevmove(notimeout){ if(moveidx==0||!canclick)return false; moveidx--; - if(MOVES[moveidx][0]!=-1&&moveidx==MOVES.length-1)winGlowIdxToRemove=neuidx; + //if(MOVES[moveidx][0]!=-1&&moveidx==MOVES.length-1)winGlowIdxToRemove=neuidx; + for(var i=0;i -- cgit v1.2.3-70-g09d2