From ff90de96005fd50de6ef0c25837eb2ff406c580b Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 13 Dec 2015 21:05:09 +0100 Subject: Last move highlight --- index.html | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index 754b96c..22bc9c2 100644 --- a/index.html +++ b/index.html @@ -97,6 +97,7 @@ function Room(_roomid){ this.cellsz=40; this.canplace=false; + this.lastplacepos=-1; this.listdiv=document.createElement("div"); this.listdiv.classList.add("room"); @@ -113,7 +114,7 @@ function Room(_roomid){ this.uidiv.classList.add("invisible"); e=document.createElement("div"); - e.setAttribute("style","float:right;margin:5px;margin-left:10px;cursor:pointer"); + e.classList.add("uiclosebtn"); e.innerHTML="x"; e.addEventListener("click",function(){ this.uidiv.classList.add("invisible"); @@ -166,7 +167,7 @@ function Room(_roomid){ if(x<0||y<0||x>=W||y>=H)return; socket.emit("roomgameplace",this.id,idx); }.bind(this)); - //drawboard(this.ctx,this.cellsz,this.bd,0); + //drawboard(this.ctx,this.cellsz,this.bd,0,this.lastplacepos); this.gamediv.appendChild(this.cvs); this.uidiv.appendChild(this.gamediv); @@ -219,7 +220,7 @@ Room.prototype.creategame=function(){ this.newgamebtn.classList.add("invisible"); this.gamediv.classList.remove("invisible"); this.bd=emptyboard(); - drawboard(this.ctx,this.cellsz,this.bd,0); + drawboard(this.ctx,this.cellsz,this.bd,0,this.lastplacepos); this.statusdiv.innerHTML="Waiting for player 1..."; }; Room.prototype.myturn=function(ot){ @@ -231,7 +232,8 @@ Room.prototype.place=function(pos,pidx){ //console.log("place: onturn "+this.onturn+" -> "+pidx); this.onturn=pidx; this.canplace=false; - queueapplymove(this.id,this.ctx,this.cellsz,pos,pidx); + this.lastplacepos=pos; + queueapplymove(this.id,this.ctx,this.cellsz,pos,pidx,this.lastplacepos); queueapplymove(this.id,function(){ //WINCHECK? //console.log("place qam_func: onturn "+this.onturn+" -> "+(this.onturn+1)%this.userlist.length); @@ -239,14 +241,14 @@ Room.prototype.place=function(pos,pidx){ this.onturn=(this.onturn+1)%this.userlist.length; this.statusdiv.innerHTML="Waiting for player "+(this.onturn+1)+"..."; } - drawboard(this.ctx,this.cellsz,this.bd,this.onturn); + drawboard(this.ctx,this.cellsz,this.bd,this.onturn,this.lastplacepos); }.bind(this)); }; Room.prototype.gotwin=function(pidx){ queueapplymove(this.id,function(){ this.onturn=pidx; this.canplace=false; - drawboard(this.ctx,this.cellsz,this.bd,this.onturn); + drawboard(this.ctx,this.cellsz,this.bd,this.onturn,this.lastplacepos); this.statusdiv.innerHTML="Player "+(this.onturn+1)+" won!"; this.newgamebtn.classList.remove("invisible"); }.bind(this)); @@ -306,7 +308,7 @@ function dodestroyroom(roomid){ socket.emit("roomdestroy",roomid); } -function drawboard(ctx,cellsz,bd,clr){ +function drawboard(ctx,cellsz,bd,clr,lastplacepos){ var x,y,i,angle,radius; ctx.clearRect(0,0,W*cellsz+1,H*cellsz+1); ctx.strokeStyle=COLOURS[+clr]; @@ -321,6 +323,12 @@ function drawboard(ctx,cellsz,bd,clr){ } } ctx.stroke(); + if(lastplacepos!=-1){ + x=lastplacepos%W; + y=~~(lastplacepos/W); + ctx.fillStyle="rgba(0,0,0,0.2)"; + ctx.fillRect(x*cellsz,y*cellsz,cellsz,cellsz); + } for(y=0;y @@ -544,6 +552,13 @@ div.roomui{ border-radius:5px; } +div.uiclosebtn{ + float:right; + margin:5px; + margin-left:10px; + cursor:pointer; +} + div.chatdiv{ float:right; width:300px; -- cgit v1.2.3