From efc74f972ab1200a52841f17cfaa6499d9bf2359 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 13 Dec 2015 22:18:22 +0100 Subject: DONGDONGDONGDONGDONGDONG --- dong.mp3 | Bin 0 -> 6657 bytes dong.ogg | Bin 0 -> 7570 bytes index.html | 37 ++++++++++++++++++++++++++++--------- index.js | 25 +++++++++++++++---------- 4 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 dong.mp3 create mode 100644 dong.ogg diff --git a/dong.mp3 b/dong.mp3 new file mode 100644 index 0000000..b82b085 Binary files /dev/null and b/dong.mp3 differ diff --git a/dong.ogg b/dong.ogg new file mode 100644 index 0000000..d15d02b Binary files /dev/null and b/dong.ogg differ diff --git a/index.html b/index.html index 22bc9c2..852ff97 100644 --- a/index.html +++ b/index.html @@ -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(); +}