I am having difficulty looping labels across an array of cards created with ZIM's flipper and tile functions. In the code below, the front and back labels are only being added to the first card instead all of the cards being created. Also, how can I tell when flipped cards are matching? I am trying to create a version of the example matching game. Thanks for the help!
let rows = 3;
let cols = 4;
let cards = [
{ front: "?", back: "1" },
{ front: "?", back: "2" },
{ front: "?", back: "3" },
{ front: "?", back: "4" },
{ front: "?", back: "5" },
{ front: "?", back: "6" },
{ front: "?", back: "1" },
{ front: "?", back: "2" },
{ front: "?", back: "3" },
{ front: "?", back: "4" },
{ front: "?", back: "5" },
{ front: "?", back: "6" }
];
let deck = [];
loop(cards, (card, i) => {
let frontSide = new Rectangle({
width: 200, height: 200, corner: 20,
color: purple, borderColor: black
});
let backSide = new Rectangle({
width: 200, height: 200, corner: 20,
color: orange, borderColor: black
});
let frontLabel = new Label(card.front, 40).center(frontSide);
let backLabel = new Label(card.back, 40).center(backSide);
let flipper = new Flipper({
front: frontSide,
back: backSide,
reverse: true,
interactive: true
}).sca(0.7);
deck.push(flipper);
});
new Tile({
obj: deck,
cols: cols,
rows: rows,
spacingH: 20,
spacingV: 20
}).center();
S.update();
}