summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-12-13 19:14:03 +0100
committertomsmeding <hallo@tomsmeding.nl>2015-12-13 19:14:03 +0100
commit0c1d78e22988de5dbcde304c10b91b9ad1319f28 (patch)
tree7ddc9ab94b1c34655ba820f670f117e014f284cf
parent9d2137af1be2ab47f18aa33e8e9c6a41da421c79 (diff)
Correct turn display, wincheck, larger chat
-rw-r--r--index.html38
-rwxr-xr-xindex.js6
2 files changed, 35 insertions, 9 deletions
diff --git a/index.html b/index.html
index 6fbc6fc..dcda3eb 100644
--- a/index.html
+++ b/index.html
@@ -27,6 +27,7 @@ socket.on("roomchat",roomchat);
socket.on("roomcreategame",roomcreategame)
socket.on("roomgameturn",roomgameturn);
socket.on("roomgameplace",roomgameplace);
+socket.on("roomgamewin",roomgamewin);
if(location.hostname=="localhost"&&Math.random()<.25)localStorage.setItem("nickname","aaa");
@@ -115,7 +116,7 @@ function Room(_roomid){
this.uidiv.classList.add("invisible");
e=document.createElement("div");
- e.setAttribute("style","float:right;margin:5px;cursor:pointer");
+ e.setAttribute("style","float:right;margin:5px;margin-left:10px;cursor:pointer");
e.innerHTML="x";
e.addEventListener("click",function(){
this.uidiv.classList.add("invisible");
@@ -155,6 +156,7 @@ function Room(_roomid){
this.cvs.width=this.cellsz*W+1;
this.cvs.height=this.cellsz*H+1;
this.cvs.addEventListener("click",function(ev){
+ if(!this.canplace)return;
if(ev.target!=this.cvs)return;
var bbox=ev.target.getBoundingClientRect();
var x=~~((ev.clientX-bbox.left)/this.cellsz),
@@ -210,6 +212,7 @@ Room.prototype.creategame=function(){
this.gamediv.classList.remove("invisible");
this.bd=emptyboard();
drawboard(this.ctx,this.cellsz,this.bd,0);
+ this.statusdiv.innerHTML="Waiting for player 1...";
};
Room.prototype.myturn=function(ot){
this.canplace=true;
@@ -217,16 +220,29 @@ Room.prototype.myturn=function(ot){
this.statusdiv.innerHTML="Your turn!";
};
Room.prototype.place=function(pos,pidx){
- console.log("place: onturn "+this.onturn+" -> "+pidx);
+ //console.log("place: onturn "+this.onturn+" -> "+pidx);
this.onturn=pidx;
+ this.canplace=false;
queueapplymove(this.id,this.ctx,this.cellsz,pos,pidx);
queueapplymove(this.id,function(){
//WINCHECK?
- console.log("place qam_func: onturn "+this.onturn+" -> "+(this.onturn+1)%this.userlist.length);
- this.onturn=(this.onturn+1)%this.userlist.length;
+ //console.log("place qam_func: onturn "+this.onturn+" -> "+(this.onturn+1)%this.userlist.length);
+ if(!this.canplace){
+ 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);
}.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);
+ this.statusdiv.innerHTML="Player "+(this.onturn+1)+" won!";
+ this.newgamebtn.classList.remove("invisible");
+ }.bind(this));
+};
function roominvite(roomid,by){
if(!confirm("User '"+by[1]+"' sent you an invite to join their room. Accept?"))return;
@@ -254,6 +270,10 @@ function roomgameplace(roomid,pos,pidx){
rooms[roomid].place(pos,pidx);
}
+function roomgamewin(roomid,pidx){
+ rooms[roomid].gotwin(pidx);
+}
+
function changenick(){
var newnick=prompt("New nickname?");
@@ -518,22 +538,22 @@ div.roomui{
div.chatdiv{
float:right;
- width:200px;
- height:200px;
+ width:300px;
+ height:600px;
}
table.chatlogtable{
display:block;
width:100%;
- height:160px;
+ height:560px;
border:1px black solid;
overflow-y:scroll;
}
div.chatitem{
- width:200px;
+ width:300px;
word-wrap:break-word;
}
input.chatinput{
- width:200px;
+ width:300px;
}
div.gamestatusdiv{
diff --git a/index.js b/index.js
index a87d6f0..f4f55b2 100755
--- a/index.js
+++ b/index.js
@@ -251,6 +251,12 @@ io.on("connection",function(conn){
return;
}
io.to(roomid).emit("roomgameplace",roomid,pos,playeridx);
+ var win=rooms[roomid].game.checkwin();
+ if(win!=-1){
+ io.to(roomid).emit("roomgamewin",roomid,playeridx);
+ rooms[roomid].game=null;
+ return;
+ }
connlist[findid(rooms[roomid].ids[rooms[roomid].game.onturn])].conn.emit("roomgameturn",roomid,rooms[roomid].game.onturn);
});
});