diff options
Diffstat (limited to 'index.html')
-rw-r--r-- | index.html | 37 |
1 files changed, 28 insertions, 9 deletions
@@ -12,7 +12,7 @@ var COLOURS=["#00F","#F00","#0CC"]; var socket=io(),me=[-1,""],userlist=[],rooms={},visibleroomuidiv=null; socket.on("disconnect",function(){ - location.href=location.href; + location.reload(); }); socket.on("message",function(msg){ alert("Message:\n\n"+msg); @@ -184,6 +184,8 @@ function Room(_roomid){ this.uidiv.appendChild(this.statusdiv); document.body.appendChild(this.uidiv); + + setTimeout(this.becomeVisible.bind(this),1); } Room.prototype.becomeVisible=function(){ if(visibleroomuidiv)visibleroomuidiv.classList.add("invisible"); @@ -204,7 +206,7 @@ Room.prototype.destroy=function(){ this.uidiv.parentElement.removeChild(this.uidiv); this.listdiv.parentElement.removeChild(this.listdiv); }; -Room.prototype.chat=function(by,msg){ +Room.prototype.chat=function(by,msg,isme){ var tr,td,div; tr=document.createElement("tr"); td=document.createElement("td"); @@ -215,6 +217,7 @@ Room.prototype.chat=function(by,msg){ tr.appendChild(td); this.uidiv.getElementsByClassName("chatlogtbody")[0].appendChild(tr); tr.scrollIntoView(); + if(!isme)sounddong(); }; Room.prototype.creategame=function(){ this.newgamebtn.classList.add("invisible"); @@ -228,14 +231,13 @@ Room.prototype.myturn=function(ot){ this.onturn=ot; this.statusdiv.innerHTML="Your turn!"; }; -Room.prototype.place=function(pos,pidx){ +Room.prototype.place=function(pos,pidx,isme){ //console.log("place: onturn "+this.onturn+" -> "+pidx); this.onturn=pidx; this.canplace=false; 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); if(!this.canplace){ this.onturn=(this.onturn+1)%this.userlist.length; @@ -243,6 +245,7 @@ Room.prototype.place=function(pos,pidx){ } drawboard(this.ctx,this.cellsz,this.bd,this.onturn,this.lastplacepos); }.bind(this)); + if(!isme)sounddong(); }; Room.prototype.gotwin=function(pidx){ queueapplymove(this.id,function(){ @@ -255,7 +258,10 @@ Room.prototype.gotwin=function(pidx){ }; function roominvite(roomid,by){ - if(!confirm("User '"+by[1]+"' sent you an invite to join their room. Accept?"))return; + if(!confirm("User '"+by[1]+"' sent you an invite to join their room. Accept?")){ + socket.emit("inviteaccept",roomid,true); + return; + } socket.emit("inviteaccept",roomid); } @@ -264,8 +270,8 @@ function roomdestroy(roomid){ delete rooms[roomid]; } -function roomchat(roomid,by,msg){ - rooms[roomid].chat(by,msg); +function roomchat(roomid,by,msg,isme){ + rooms[roomid].chat(by,msg,isme); } function roomcreategame(roomid){ @@ -276,8 +282,8 @@ function roomgameturn(roomid,ot){ rooms[roomid].myturn(ot); } -function roomgameplace(roomid,pos,pidx){ - rooms[roomid].place(pos,pidx); +function roomgameplace(roomid,pos,pidx,isme){ + rooms[roomid].place(pos,pidx,isme); } function roomgamewin(roomid,pidx){ @@ -455,6 +461,14 @@ function queueapplymove(id,ctx,cellsz,idx,c,lastplacepos){ else applymove(ctx,cellsz,idx,c,lastplacepos,id); } } + + +var sounddong__audioelem=null; +function sounddong(){ + if(sounddong__audioelem==null)sounddong__audioelem=document.getElementById("dongaudioelem"); + sounddong__audioelem.currentTime=0; + sounddong__audioelem.play(); +} </script> <style> body{ @@ -617,5 +631,10 @@ div#roomuisplash{ </div> <div id="roomlistcontainer"></div> </div> + +<audio id="dongaudioelem" preload="auto"> + <source src="dong.ogg"> + <source src="dong.mp3"> +</audio> </body> </html> |