Get card data from server and display it
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user