テーブルには 8 枚のカードがあり、4 面が表示され、4 面が非表示になっています。カードをクリックしてめくります。ピップ マッチまたはスーツ マッチがある場合は、関連するカードの周りに火花を表示します。
問題は、論理的に何か間違ったことをしている、または .concat() が機能していないことです。火花が出る場合と出ない場合があるからです。
ゲーム全体を適切なオブジェクトにリファクタリングできるかもしれませんが、それは私の現在のレベルを超えています (私は 1 か月間 JS を学んでいます)。使用するフレームワークはRightJSです。わかりやすくするため、および少しのコンテキストのために、関数全体を投稿しました。
function pick(card) {
var matches = [],
pip = [],
suit = [];
//Check for matches
['card1', 'card2', 'card3', 'card4'].each(function (el) {
if (hand[el].charAt(0) == 'j') {
matches.push(card);
matches.push(el);
} //Joker
else if (hand[card].charAt(1) == hand[el].charAt(1) || hand[card].charAt(0) == 'j') {
matches.push(card);
pip.push(el);
} //Pip match
else if (hand[card].charAt(0) == hand[el].charAt(0) || hand[card].charAt(0) == 'j') {
matches.push(card);
suit.push(el);
} //Suit match
});
if (pip.length > suit.length) {
matches.concat(pip);
} else {
matches.concat(suit);
}
//Hide old bling
$$('.bling').each(function (el) {
el.hide();
});
//Show bling
if (matches.length > 0) {
matches.each(function (el) {
$(el).firstChild.show();
});
}
//Show the card from hand
$(card).setClass(hand[card]);
turned++;
// New turn if all have been clicked
if (turned == 4) {
turned = 0;
newturn();
}
}