Javascript でブラックジャック カード ゲームを作成しています。これまでのコメントに感謝します。cardDealer 関数内で cardFace 関数を 1 回しか呼び出せないように見える理由について、フィードバックを探しています。現在、cardFace(0) は値を提供しますが、cardFace(1) またはその他の数値は、cardDealer 関数内で呼び出されている唯一の cardFace(x) でない限り提供されません。どんなアイデアでも大歓迎です。ありがとう
以下のコードは完全ではありませんが、十分な情報を識別するには十分だと思います。ありがとう
function card(name, suit, face, value)
{
this.name = name;
this.suit = suit;
this.face = face;
this.value = value;
}
aceOfHearts = new card("aceofhearts","hearts", "ace", 11);
kingOfHearts = new card("kingofhearts","hearts", "king", 10);
queenOfHearts = new card("queenofhearts","hearts", "queen", 10);
jackOfHearts = new card("jackofhearts","hearts", "jack", 10);
tenOfHearts = new card("tenofhearts","hearts", "ten", 10);
nineOfHearts = new card("nineofhearts","hearts", "nine", 9);
eightOfHearts = new card("eightofhearts","hearts", "eight", 8);
sevenOfHearts = new card("sevenofhearts","hearts", "seven", 7);
sixOfHearts = new card("sixofhearts","hearts", "six", 6);
var deck;
deck = [];
deck.push(aceOfHearts);
deck.push(aceOfDiamonds);
deck.push(aceOfClubs);
deck.push(aceOfSpades);
deck.push(kingOfClubs);
deck.push(kingOfDiamonds);
deck.push(kingOfHearts);
deck.push(kingOfSpades);
deck.push(queenOfClubs);
deck.push(queenOfDiamonds);
deck.push(queenOfHearts);
deck.push(queenOfSpades);
deck.push(jackOfClubs);
deck.push(jackOfDiamonds);
deck.push(jackOfHearts);
deck.push(jackOfSpades);
deck.push(tenOfClubs);
deck.push(tenOfDiamonds);
deck.push(tenOfHearts);
deck.push(tenOfSpades);
var cardDealer = function()
{
fisherYates(deck);
document.getElementById("yourFirstCard").textContent = "Your First Card is " + cardFace(0) ;
document.getElementById("yourSecondCard").textContent = "Your Second Card is " + cardFace(1) ;
};
var cardFace = function(x)
{
cardFace = deck[x].face;
return cardFace;
};
var cardSuit = function(x)
{
cardSuit = deck[x].suit;
return cardSuit;
};
<body>
<div>Black Jack 1.1</div>
<br/>
<button type="button" onClick="cardDealer()">Deal</button>
<div id="yourFirstCard"></div>
<div id="yourSecondCard"></div>
<div id="yourThirdCard"></div>
<div id="yourFourthCard"></div>
<div id="yourFifthCard"></div>
<div id="playerTotal"></div></div>
<div id="playerSit"></div>
<div id="playerMessage"></div>
<div id="sitter"><button type="button" onClick="sit()">Sit</button></div>
<div id="hitter"><button type="button" onClick="hitMe()">Hit</button></div>
<br/>
<br/>
<div id="dealersFirstCard"></div></div>
<div id="dealersSecondCard"></div></div>
<div id="dealersThirdCard"></div></div>
<div id="dealersFourthCard"></div></div>
<div id="dealersFifthCard"></div></div>
<div id="dealerTotal"></div></div>
<div id="dealerSit"></div></div>
<div id="dealerMessage"></div></div>
</body>