我是一个 JavaScript 菜鸟,想知道是否有更好的方法来询问我的脚本生成的卡是否已在使用中。
现在,我正在使用一堆Or运算符,但是,必须有一种不那么冗余的方法来做到这一点。如果你们中的任何一个人能回答我的问题,从长远来看,这将真正帮助我。谢谢
var cards = ['Ace of heart','Ace of club','Ace of diamond','Ace of spade',
'Two of heart','Two of club','Two of diamond','Two of spade',
'Three of heart','Three of club','Three of diamond','Three of spade',
'Four of heart','Four of club','Four of diamond','Four of spade',
'Five of heart','Five of club','Five of diamond','Five of spade'];
// Distributed Cards //
var pre_flop = [1];
var flop = [2];
var turn = [0];
var river = [0];
// Cards value //
var your_card;
var indexed_cards = [6];
var total_card = 0;
var deck_size = cards.length;
function generate_card(){
// Assign value to first card //
if(total_card === 0){
your_card = Math.floor(Math.random() * deck_size);
indexed_cards [total_card] = your_card;
total_card++;
}else{
your_card = Math.floor(Math.random() * deck_size);
// Makes sure the cards are different //
while(1){
if(your_card === indexed_cards [0] || your_card === indexed_cards [1] || your_card === indexed_cards [2] || your_card === indexed_cards [3] || your_card === indexed_cards [4] || your_card === indexed_cards [5] || your_card === indexed_cards [6]){
your_card = Math.floor(Math.random() * deck_size);
}else {
indexed_cards [total_card] = your_card;
break;
}
}
total_card++;
}
}