Remove Cups properly

This commit is contained in:
Lukas Doerr 2021-06-18 16:06:24 +02:00 committed by Max Gold
parent 9e7279ebd4
commit ef2a5d55db
5 changed files with 40 additions and 29 deletions

View File

@ -51,7 +51,6 @@ Board.prototype.enableAll = function() {
* @param cupId * @param cupId
*/ */
Board.prototype.mark = function(cupId) { Board.prototype.mark = function(cupId) {
alert(' mark bsjs');
var cup = this.cups[cupId]; var cup = this.cups[cupId];
if (!cup) { if (!cup) {
@ -84,6 +83,7 @@ Board.prototype.mark = function(cupId) {
* @returns {boolean} * @returns {boolean}
*/ */
Board.prototype.checkTurn = function(playerId) { Board.prototype.checkTurn = function(playerId) {
('checkTurn');
return this.players[this.currentTurn].id == playerId; return this.players[this.currentTurn].id == playerId;
}; };

View File

@ -2,6 +2,9 @@
* *
* @constructor * @constructor
*/ */
var root = document.documentElement;
var ball = document.getElementById("ball");
var Board = function(scoreBoard) { var Board = function(scoreBoard) {
this.cups = []; this.cups = [];
this.dom = document.getElementById('cont'); this.dom = document.getElementById('cont');
@ -37,7 +40,6 @@ Board.prototype.init = function() {
Board.prototype.disableAll = function() { Board.prototype.disableAll = function() {
alert('disableAll');
this.cups.forEach(function(cup) { this.cups.forEach(function(cup) {
//cup.classList.add('notActive'); //cup.classList.add('notActive');
}); });
@ -52,7 +54,6 @@ Board.prototype.enableAll = function() {
}; };
Board.prototype.enableTurn = function() { Board.prototype.enableTurn = function() {
alert('enableTurn');
this.cups.forEach(function(cup) { this.cups.forEach(function(cup) {
if (cup.getAttribute('marked') === 'false') { if (cup.getAttribute('marked') === 'false') {
//cup.classList.remove('notActive'); //cup.classList.remove('notActive');
@ -83,78 +84,87 @@ Board.prototype.lowlightcups = function() {
Board.prototype.getCup = function(code) { Board.prototype.getCup = function(code) {
alert(code); ball.classList.add("Shoot");
switch (code) switch (code)
{ {
case 'e': case 'e':
case 'E': case 'E':
//root.style.setProperty('--top325', "-350"+ "px"); root.style.setProperty('--top325', "-350"+ "px");
ball.style.top = "-350px" ball.style.top = "-350px";
ball.style.left = "-155px"; ball.style.left = "-155px";
return "cup1"; return "cup1";
break; break;
case 'r': case 'r':
case 'R': case 'R':
//root.style.setProperty('--top325', "-350"+ "px"); root.style.setProperty('--top325', "-350"+ "px");
ball.style.top = "-350px" ball.style.top = "-350px";
ball.style.left = "-50px"; ball.style.left = "-50px";
return "cup2";
//removeCup("2"); //removeCup("2");
break; break;
case 't': case 't':
case 'T': case 'T':
//root.style.setProperty('--top325', "-350"+ "px"); root.style.setProperty('--top325', "-350"+ "px");
ball.style.top = "-350px" ball.style.top = "-350px";
ball.style.left = "55px"; ball.style.left = "55px";
return "cup3";
//removeCup("3"); //removeCup("3");
break; break;
case 'z': case 'z':
case 'Z': case 'Z':
//root.style.setProperty('--top325', "-350"+ "px"); root.style.setProperty('--top325', "-350"+ "px");
ball.style.top = "-350px" ball.style.top = "-350px";
ball.style.left = "160px"; ball.style.left = "160px";
return "cup4";
//removeCup("4"); //removeCup("4");
break; break;
case 'd': case 'd':
case 'D': case 'D':
//root.style.setProperty('--top325', "-290"+ "px"); root.style.setProperty('--top325', "-290"+ "px");
ball.style.top = "-290px" ball.style.top = "-290px";
ball.style.left = "-100px"; ball.style.left = "-100px";
return "cup5";
//removeCup("5"); //removeCup("5");
break; break;
case 'f': case 'f':
case 'F': case 'F':
//root.style.setProperty('--top325', "-290"+ "px"); root.style.setProperty('--top325', "-290"+ "px");
ball.style.top = "-290px" ball.style.top = "-290px";
ball.style.left = "0px"; ball.style.left = "0px";
return "cup6";
//removeCup("6"); //removeCup("6");
break; break;
case 'g': case 'g':
case 'G': case 'G':
//root.style.setProperty('--top325', "-290"+ "px"); root.style.setProperty('--top325', "-290"+ "px");
ball.style.top = "-290px" ball.style.top = "-290px";
ball.style.left = "110px"; ball.style.left = "110px";
//removeCup("7"); //removeCup("7");
return "cup7";
break; break;
case 'c': case 'c':
case 'C': case 'C':
//root.style.setProperty('--top325', "-220"+ "px"); root.style.setProperty('--top325', "-220"+ "px");
ball.style.top = "-220px" ball.style.top = "-220px"
ball.style.left = "-50px"; ball.style.left = "-50px";
//removeCup("8"); //removeCup("8");
return "cup8";
break; break;
case 'v': case 'v':
case 'V': case 'V':
//root.style.setProperty('--top325', "-220"+ "px"); root.style.setProperty('--top325', "-220"+ "px");
ball.style.top = "-220px" ball.style.top = "-220px"
ball.style.left = "55px"; ball.style.left = "55px";
//removeCup("9"); //removeCup("9");
return "cup9";
break; break;
case 'b': case 'b':
case 'B': case 'B':
//root.style.setProperty('--top325', "-160"+ "px"); root.style.setProperty('--top325', "-160"+ "px");
ball.style.top = "-160px" ball.style.top = "-160px"
ball.style.left = "0px"; ball.style.left = "0px";
//removeCup("10"); //removeCup("10");
return "cup10";
break; break;
default: default:
break; break;
@ -166,12 +176,9 @@ Board.prototype.getCup = function(code) {
* @param event * @param event
*/ */
Board.prototype.mark = function(event) { Board.prototype.mark = function(event) {
alert(this.ready);
if (this.ready) { if (this.ready) {
var target = document.getElementById(this.getCup(event.key)); var target = document.getElementById(this.getCup(event.key));
alert(target);
if (target.getAttribute('data-intent') === 'gamecup' && target.getAttribute('active') === 'true') { if (target.getAttribute('data-intent') === 'gamecup' && target.getAttribute('active') === 'true') {
this.onMark(this.cups.indexOf(target)); this.onMark(this.cups.indexOf(target));
this.disableAll(); this.disableAll();
@ -188,9 +195,13 @@ Board.prototype.doMark = function(cupId, label) {
var cup = this.cups[cupId]; var cup = this.cups[cupId];
cup.textContent = label; cup.textContent = label;
//cup.classList.add('notActive'); //cup.classList.add('notActive');
// removeCup // removeCup
setTimeout(this.cups[cupId].classList.add("fadeAway") ,1000);
cup.setAttribute('marked', 'true'); cup.setAttribute('marked', 'true');
setTimeout(function() {
ball.style.top = "0px";
ball.style.left = "0px";
}, 1000);
}; };
/** /**
@ -206,6 +217,7 @@ Board.prototype.doWinner = function(pos) {
* *
*/ */
Board.prototype.doDraw = function() { Board.prototype.doDraw = function() {
alert('doDraw');
this.lowlightcups(); this.lowlightcups();
}; };

View File

@ -54,7 +54,6 @@ function makeMessage(action, data){
* @param cupId * @param cupId
*/ */
board.onMark = function(cupId){ board.onMark = function(cupId){
alert('onMark');
socket.send(makeMessage(events.outgoing.MARK, {playerId: hero.id, cupId: cupId})); socket.send(makeMessage(events.outgoing.MARK, {playerId: hero.id, cupId: cupId}));
}; };
@ -88,7 +87,7 @@ socket.onmessage = function(event){
switch (msg.action) { switch (msg.action) {
case events.incoming.ERROR: case events.incoming.ERROR:
alert('Error: ' + msg.data); alert('Errorrr: ' + msg.data);
break; break;
case events.incoming.JOIN_GAME: case events.incoming.JOIN_GAME:
board.addPlayer(msg.data); board.addPlayer(msg.data);
@ -109,7 +108,6 @@ socket.onmessage = function(event){
break; break;
case events.incoming.MARK: case events.incoming.MARK:
alert('incoming.mARK');
board.doMark(msg.data.cupId, msg.data.player.label); board.doMark(msg.data.cupId, msg.data.player.label);
break; break;

View File

@ -78,6 +78,7 @@ wss.on('connection', function connection(ws) {
}); });
ws.on('message', function incoming(msg) { ws.on('message', function incoming(msg) {
try { try {
var msg = JSON.parse(msg); var msg = JSON.parse(msg);
} catch (error) { } catch (error) {

View File

@ -1,5 +1,5 @@
doctype html doctype html
html(lang='en') html(lang='en')#cont
head head
meta(charset='UTF-8') meta(charset='UTF-8')
meta( http-equiv='X-UA-Compatible', content='IE=edge' ) meta( http-equiv='X-UA-Compatible', content='IE=edge' )