From 00d868f963afb794d99954a8c008b87602c8a4fd Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Mon, 14 Jun 2021 12:06:49 +0200 Subject: [PATCH] Destroy text and borders --- Webservice/server.js | 9 +++++++++ public/js/Card.js | 10 ++++------ public/js/game.js | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Webservice/server.js b/Webservice/server.js index 0898cfb..e4ce7e3 100644 --- a/Webservice/server.js +++ b/Webservice/server.js @@ -63,6 +63,15 @@ io.on('connection', socket => { gameState['players'].splice(index, 1); gameState['positions'].splice(index, 1); } + + socket.leave(socket.room); + + if (gameState['players'].length === 0) { + gameState['players'] = []; + gameState['positions'] = []; + gameState['whosNext'] = 0; + gameState['started'] = false; + } } generate_log_message(socket.room, socket.username, "LEFT", ""); diff --git a/public/js/Card.js b/public/js/Card.js index 1e21d0d..29275c9 100644 --- a/public/js/Card.js +++ b/public/js/Card.js @@ -50,25 +50,25 @@ function Card(game_board_size, s, a1, a2, a3, a4, d, your_turn) { // Answers this.buttons.push(new Button(0xffffff, 0xcccccc, 0x4169E1, this.card_width - 40, 150, this.card_x + 20, this.card_y + this.card_height - 120 - 170 * 4, this.a1.text, this.a1.status, true, function () { - if (this.your_turn) { + if (_this.your_turn) { select_answer(0, _this.a1.text); } })); this.buttons.push(new Button(0xffffff, 0xcccccc, 0x4169E1, this.card_width - 40, 150, this.card_x + 20, this.card_y + this.card_height - 120 - 170 * 3, this.a2.text, this.a2.status, true, function () { - if (this.your_turn) { + if (_this.your_turn) { select_answer(1, _this.a2.text); } })); this.buttons.push(new Button(0xffffff, 0xcccccc, 0x4169E1, this.card_width - 40, 150, this.card_x + 20, this.card_y + this.card_height - 120 - 170 * 2, this.a3.text, this.a3.status, true, function () { - if (this.your_turn) { + if (_this.your_turn) { select_answer(2, _this.a3.text); } })); this.buttons.push(new Button(0xffffff, 0xcccccc, 0x4169E1, this.card_width - 40, 150, this.card_x + 20, this.card_y + this.card_height - 120 - 170 * 1, this.a4.text, this.a4.status, true, function () { - if (this.your_turn) { + if (_this.your_turn) { select_answer(3, _this.a4.text); } })); @@ -88,8 +88,6 @@ function Card(game_board_size, s, a1, a2, a3, a4, d, your_turn) { answer = null; diced = false; rolled_number = null; - rolled_number_text.destroy(); - border_card_stack.clear(); socket.emit('card finished', d); } else { alert("Bitte wähle eine Antwortmöglichkeit aus"); diff --git a/public/js/game.js b/public/js/game.js index 7ff968d..eaf00d9 100644 --- a/public/js/game.js +++ b/public/js/game.js @@ -170,6 +170,8 @@ function start_game() { socket.on('card destroyed', function () { card.destroyCard(); + rolled_number_text.destroy(); + border_card_stack.clear(); }); resize();