第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

我怎樣才能讓我的牌組發(fā)出正確的花色?

我怎樣才能讓我的牌組發(fā)出正確的花色?

慕慕森 2023-07-20 17:24:07
我試圖讓當(dāng)你點(diǎn)擊一個(gè)按鈕時(shí),它會(huì)顯示一副紙牌。我為每種花色都有一個(gè)按鈕,所以當(dāng)你點(diǎn)擊它時(shí),它就會(huì)處理該花色。我已經(jīng)用它來處理紅心,但當(dāng)我嘗試處理鉆石時(shí),它仍然顯示紅心。我究竟做錯(cuò)了什么?我該如何展示我的鉆石?var heart = true;var diamond = true;var suit = "";function card(name,suit,value) {    this.name = name;    this.suit = suit;    this.value = value;}var deck = [    new card('Ace', 'Hearts',11),    new card('Two', 'Hearts',2),    new card('Three', 'Hearts',3),    new card('Four', 'Hearts',4),    new card('Five', 'Hearts',5),    new card('Six', 'Hearts',6),    new card('Seven', 'Hearts',7),    new card('Eight', 'Hearts',8),    new card('Nine', 'Hearts',9),    new card('Ten', 'Hearts',10),    new card('Jack', 'Hearts',10),    new card('Queen', 'Hearts',10),    new card('King', 'Hearts',10),    new card('Ace', 'Diamonds',11),    new card('Two', 'Diamonds',2),    new card('Three', 'Diamonds',3),    new card('Four', 'Diamonds',4),    new card('Five', 'Diamonds',5),    new card('Six', 'Diamonds',6),    new card('Seven', 'Diamonds',7),    new card('Eight', 'Diamonds',8),    new card('Nine', 'Diamonds',9),    new card('Ten', 'Diamonds',10),    new card('Jack', 'Diamonds',10),    new card('Queen', 'Diamonds',10),    new card('King', 'Diamonds',10),    new card('Ace', 'Clubs',11),    new card('Two', 'Clubs',2),    new card('Three', 'Clubs',3),    new card('Four', 'Clubs',4),    new card('Five', 'Clubs',5),    new card('Six', 'Clubs',6),    new card('Seven', 'Clubs',7),    new card('Eight', 'Clubs',8),    new card('Nine', 'Clubs',9),    new card('Ten', 'Clubs',10),    new card('Jack', 'Clubs',10),    new card('Queen', 'Clubs',10),];
查看完整描述

1 回答

?
桃花長(zhǎng)相依

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊

如果您不想為了更優(yōu)雅的解決方案而重寫所有內(nèi)容,您可以在處理鉆石時(shí)將牌組的索引添加 12。但是,如果您最終洗牌,則此方法不會(huì)起作用。


function dealDiamonds(d) {

    if (d < 13) {

        displayDiamonds = deck[d + 12];

        //...

    } else {

        //...

    }

}

一個(gè)更優(yōu)雅的解決方案是擁有一個(gè)函數(shù)來獲取某套特定的牌,而不依賴于牌組的特定順序。


function dealDiamonds(d) {

    if (d < 13) {

        displayDiamonds = getCardOfSuit('Diamonds', d);

        //...

    } else {

        //...

    }

}


function getCardOfSuit(suit, index) {

    //filter the deck to only the deck of a certain suit

    let suitDeck = deck.filter((card) => card.suit == suit);


    //returns the card (0 - 12) based on the second parameter

    return suitDeck[index];

}


查看完整回答
反對(duì) 回復(fù) 2023-07-20
  • 1 回答
  • 0 關(guān)注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)