首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用数组将纸牌图像添加到纸牌游戏中,而不是文本

使用数组将纸牌图像添加到纸牌游戏中,而不是文本
EN

Stack Overflow用户
提问于 2017-09-21 14:38:00
回答 1查看 196关注 0票数 0

我的程序一直崩溃这是一个21点/21游戏(我不确定区别),程序询问玩家他们想要做什么,然后一旦他们选择了stick it crashes,我检查了控制台,没有出现错误,我已经用repl测试了javascript,它工作得很好,只是当我试图将它合并到一个html页面中时。

同样,当它工作时,它将只显示房子牌或第二个玩家的牌,而不是所有的玩家的牌。

最后,一旦这是工作,我想通过添加用户的卡片图像来改进它,但我不知道如何开始。

代码语言:javascript
复制
<html>
<head>
<h1 align="center">21 Game</h1>
</head>
<body bgcolor="#458B00">

<div align='center'>
    <h3>House Cards</h3>
    <h5 id='housecurrenthand'></h5>
    <h5 id='househand'> </h5>

    <h3>Players Cards</h3>
    <h5 id='playershand1'> </h5>
    <h5 id='playershand2'> </h5>
    <h5 id='playershand3'> </h5>
    <h5 id='playershand4'> </h5>
    <h5 id='playershand5'> </h5>
    <h5 id='playershand6'> </h5>
    <h5 id='playershand7'> </h5>
    <h5 id='playershand8'> </h5>
    <h5 id='playershand9'> </h5>
    <h5 id='playershand10'> </h5>

    <h4 id='winner'> </h4>

    <button onclick="play()" float='bottom'>Play</button>

</div>
<script language='JavaScript'> 

function play() {
  playersQ = prompt('How many people are playing?');
  playershands = [];
  i = 0;
  count = 0;
  var player_cards = 0;

  function player() {
    var player_cards = Math.floor(Math.random() * 21) + 1;
    while (player_cards < 21) {
      Hit = prompt('Players cards are ' + player_cards + ' Would you like stick or twist?(S/T)')
      if (Hit == 'T') {
        player_cards = player_cards + Math.floor(Math.random() * 11) + 1;
      } else if (Hit == 'S') {
        break;
      } else if (player_cards > 21) {
        alert('Player is bust');
        break;
      }
    }
    return player_cards;
  }

  function house() {
    var house_cards = Math.floor(Math.random() * 21) + 1;
    while (house_cards < 18 && house_cards < 22) {
      house_cards = house_cards + Math.floor(Math.random() * 11);
    }
    return house_cards;
  }

  while (i < playersQ) {
    playershands.push(player());
    i = i + 1;
  }

var house_hand = house();



  while (count < playersQ) {
    count2 = count + 1
    document.getElementById('playershand' +i ).innerHTML = ('Player ' + count2 + ' has ' + playershands[count]);
  }

document.getElementById('househand').innerHTML = ('House has ' + house_hand);

count = 0 ;

while (count < playersQ){
    if (playershands[count] > house_hand && playershands[count] < 22) {
      document.getElementById('winner').innerHTML = ('Player wins');
      count = count + 1;
    } else if (house_hand > playershands[count] && house_hand < 22) {
      document.getElementById('winner').innerHTML = ('House wins');
      break;
    } else if (house_hand == playershands[count]) {
      document.getElementById('winner').innerHTML = ('draw');
      break;
    }
  }
}

</script>
</body>
</html>
EN

回答 1

Stack Overflow用户

发布于 2017-09-21 14:44:29

要抽出一张牌,您可以:

在一张卡片“canvas

”中画出它们“of

  • ”A♥等于“1A.png”
  • 可以使用SVG

生成卡片

祝你有个愉快的开发!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46337052

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档