From a367a183e75956b2ff3ef7630c7b4fabef29cd36 Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Tue, 8 Jun 2021 16:16:55 +0200 Subject: [PATCH 1/2] Fixed dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 3bb794c..6691e24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ RUN npm install COPY Webservice Webservice COPY public public +COPY data data EXPOSE 5000 -- 2.45.2 From f469259d36f1dccd20537dfc765dd76050be408a Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Tue, 8 Jun 2021 17:33:59 +0200 Subject: [PATCH 2/2] Get card data from server and display it --- Webservice/server.js | 2 +- data/cards.json | 30 +++++++++++++++--------------- public/js/Button.js | 3 ++- public/js/Card.js | 30 ++++++++++++++++-------------- public/js/game.js | 15 ++++++++------- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/Webservice/server.js b/Webservice/server.js index 6eb9bd0..e93be02 100644 --- a/Webservice/server.js +++ b/Webservice/server.js @@ -98,7 +98,7 @@ function generate_log_message(room, user, type, message) { function getRandomCard(difficulty) { let filtered_cards = cards.filter(card => { - return card.diffuculty === difficulty; + return card.difficulty === difficulty; }); return shuffleAnswers(filtered_cards[Math.floor(Math.random() * filtered_cards.length)]); diff --git a/data/cards.json b/data/cards.json index 56094a4..726d93b 100644 --- a/data/cards.json +++ b/data/cards.json @@ -1,69 +1,69 @@ [ { "id": 1, - "diffuculty": 1, + "difficulty": 1, "question": "Was?", "answers": [ { - "answer_a": "A", + "text": "A", "status": false }, { - "answer_b": "B", + "text": "B", "status": true }, { - "answer_c": "C", + "text": "C", "status": false }, { - "answer_d": "D", + "text": "D", "status": false } ] }, { "id": 2, - "diffuculty": 2, + "difficulty": 2, "question": "Wie?", "answers": [ { - "answer_a": "A", + "text": "A", "status": false }, { - "answer_b": "B", + "text": "B", "status": true }, { - "answer_c": "C", + "text": "C", "status": false }, { - "answer_d": "D", + "text": "D", "status": false } ] }, { "id": 3, - "diffuculty": 3, + "difficulty": 3, "question": "Wo?", "answers": [ { - "answer_a": "A", + "text": "A", "status": false }, { - "answer_b": "B", + "text": "B", "status": true }, { - "answer_c": "C", + "text": "C", "status": false }, { - "answer_d": "D", + "text": "D", "status": false } ] diff --git a/public/js/Button.js b/public/js/Button.js index 476c43e..163e4bd 100644 --- a/public/js/Button.js +++ b/public/js/Button.js @@ -1,4 +1,4 @@ -function Button(default_color, hover_color, select_color, width, height, x, y, text, button_is_answer, click) { +function Button(default_color, hover_color, select_color, width, height, x, y, text, status, button_is_answer, click) { this.graphics = new PIXI.Graphics(); this.default_color = default_color; this.hover_color = hover_color; @@ -7,6 +7,7 @@ function Button(default_color, hover_color, select_color, width, height, x, y, t this.x = x; this.y = y; this.text = text; + this.status = status; this.button_is_answer = button_is_answer; this.click = click; this.selected = false; diff --git a/public/js/Card.js b/public/js/Card.js index 6ec78b5..14266b0 100644 --- a/public/js/Card.js +++ b/public/js/Card.js @@ -1,11 +1,14 @@ -function Card(game_board_size, s, a1, a2, a3, a4, right_answer, d) { +function Card(game_board_size, s, a1, a2, a3, a4, d) { this.card = new PIXI.Graphics(); this.s = s; this.a1 = a1; this.a2 = a2; this.a3 = a3; this.a4 = a4; - this.right_answer = right_answer; + if (a1.status) this.right_answer = this.a1.text; + if (a2.status) this.right_answer = this.a2.text; + if (a3.status) this.right_answer = this.a3.text; + if (a4.status) this.right_answer = this.a4.text; this.d = d; this.card_x = game_board_size * 0.25 + 2.5; this.card_y = game_board_size / 2 - game_board_size * 0.72 / 2 + 2.5; @@ -45,27 +48,27 @@ function Card(game_board_size, s, a1, a2, a3, a4, right_answer, d) { this.card.addChild(basicText); // Answers - this.buttons.push(new Button(0xffffff, 0xcccccc, 0xff00ff, this.card_width - 40, 150, this.card_x + 20, this.card_y + this.card_height - 120 - 170 * 4, this.a1, true, function () { - select_answer(0); + this.buttons.push(new Button(0xffffff, 0xcccccc, 0xff00ff, 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 () { + select_answer(0, _this.a1.text); })); - this.buttons.push(new Button(0xffffff, 0xcccccc, 0xff00ff, this.card_width - 40, 150, this.card_x + 20, this.card_y + this.card_height - 120 - 170 * 3, this.a2, true, function () { - select_answer(1); + this.buttons.push(new Button(0xffffff, 0xcccccc, 0xff00ff, 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 () { + select_answer(1, _this.a2.text); })); - this.buttons.push(new Button(0xffffff, 0xcccccc, 0xff00ff, this.card_width - 40, 150, this.card_x + 20, this.card_y + this.card_height - 120 - 170 * 2, this.a3, true, function () { - select_answer(2); + this.buttons.push(new Button(0xffffff, 0xcccccc, 0xff00ff, 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 () { + select_answer(2, _this.a3.text); })); - this.buttons.push(new Button(0xffffff, 0xcccccc, 0xff00ff, this.card_width - 40, 150, this.card_x + 20, this.card_y + this.card_height - 120 - 170 * 1, this.a4, true, function () { - select_answer(3); + this.buttons.push(new Button(0xffffff, 0xcccccc, 0xff00ff, 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 () { + select_answer(3, _this.a4.text); })); this.buttons.forEach(button => this.card.addChild(button.getButton())); // OK-Button - this.card.addChild(new Button(0xffffff, 0xcccccc, 0xffffff, this.card_width - 40, 100, this.card_x + 20, this.card_y + this.card_height - 120, "OK", false, function () { + this.card.addChild(new Button(0xffffff, 0xcccccc, 0xffffff, this.card_width - 40, 100, this.card_x + 20, this.card_y + this.card_height - 120, "OK", null, false, function () { if (_this.right_answer === answer) { console.log("Richtig") } else { @@ -79,10 +82,9 @@ function Card(game_board_size, s, a1, a2, a3, a4, right_answer, d) { } - function select_answer(id) { - console.log(id) + function select_answer(id, text) { _this.buttons.forEach(button => button.unSelectButton()); _this.buttons[id].selectButton(); - answer = id; + answer = text; } } \ No newline at end of file diff --git a/public/js/game.js b/public/js/game.js index d80862e..42be662 100644 --- a/public/js/game.js +++ b/public/js/game.js @@ -71,8 +71,7 @@ function start_game() { let cards_1 = generate_card_stack(PIXI.Sprite.from('/img/card_stack.png'), 3, 3, function () { if (!show_card) { console.log("1"); - new Card(game_board_size, "Ein Bäcker möchte eine neue Filiale eröffnen. Wie sollte er das Budget einteilen?", "a1", "a2", "a3", "a4", 1, 1).showCard(); - show_card = true; + socket.emit('get card', 1); } }); app.stage.addChild(cards_1); @@ -80,8 +79,7 @@ function start_game() { let cards_2 = generate_card_stack(PIXI.Sprite.from('/img/card_stack.png'), 5, 3, function () { if (!show_card) { console.log("2"); - new Card(game_board_size, "Ein Bäcker möchte eine neue Filiale eröffnen. Wie sollte er das Budget einteilen?", "a1", "a2", "a3", "a4", 1, 1).showCard(); - show_card = true; + socket.emit('get card', 2); } }); app.stage.addChild(cards_2); @@ -89,8 +87,7 @@ function start_game() { let cards_3 = generate_card_stack(PIXI.Sprite.from('/img/card_stack.png'), 7, 3, function () { if (!show_card) { console.log("3"); - new Card(game_board_size, "Ein Bäcker möchte eine neue Filiale eröffnen. Wie sollte er das Budget einteilen?", "a1", "a2", "a3", "a4", 1, 1).showCard(); - show_card = true; + socket.emit('get card', 3); } }); app.stage.addChild(cards_3); @@ -100,7 +97,11 @@ function start_game() { }); socket.on('card', function (data) { - console.log(data); + let q = data.question + let a = data.answers + let d = data.difficulty + new Card(game_board_size, q, a[0], a[1], a[2], a[3], d).showCard(); + show_card = true; }); resize(); -- 2.45.2