我正在用 Javascript 创建一个二十一点纸牌游戏。到目前为止,我很欣赏你的评论。我正在寻找关于为什么我似乎只能在 cardDealer 函数中调用 cardFace 函数一次的反馈。目前 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>