Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 模拟垃圾游戏的程序(需要帮助在此代码上添加银行)_Javascript - Fatal编程技术网

Javascript 模拟垃圾游戏的程序(需要帮助在此代码上添加银行)

Javascript 模拟垃圾游戏的程序(需要帮助在此代码上添加银行),javascript,Javascript,//掷骰子游戏是由X和Y两个玩家玩的骰子游戏。 第一个X掷这对骰子。 如果骰子的总数是7或11,那么X赢了游戏。 如果总和是2、3或12,Y赢。 否则,总和被指定为点,由另一次掷骰进行匹配。 因此,如果第一次掷骰子时两人都没有赢,那么骰子将被反复掷到最后 要么得分,要么得7分。 如果先出7,Y赢。 否则,当分数上升时,X获胜。 //下面写的代码是我写的代码,它有垃圾游戏功能的代码,但我在创建一个银行和下注金额,能够下注的钱,并停止时,钱的数额是结束下注的部分被绊住了。 //用于测试游戏状态的变量

//掷骰子游戏是由X和Y两个玩家玩的骰子游戏。 第一个X掷这对骰子。 如果骰子的总数是7或11,那么X赢了游戏。 如果总和是2、3或12,Y赢。 否则,总和被指定为点,由另一次掷骰进行匹配。 因此,如果第一次掷骰子时两人都没有赢,那么骰子将被反复掷到最后 要么得分,要么得7分。 如果先出7,Y赢。 否则,当分数上升时,X获胜。 //下面写的代码是我写的代码,它有垃圾游戏功能的代码,但我在创建一个银行和下注金额,能够下注的钱,并停止时,钱的数额是结束下注的部分被绊住了。 //用于测试游戏状态的变量 var赢=0,输=1,继续滚动=2

             // other variables used in program`enter code here`
             var firstRoll = true,            // true if first roll
                 sumOfDice = 0,               // sum of the dice
                 myPoint = 0, // point if no win/loss on first roll
                 gameStatus = CONTINUE_ROLLING; // game not over yet

             // process one roll of the dice
             function play()
             {
                if ( firstRoll ) {        // first roll of the dice
                   sumOfDice = rollDice();        

                   switch ( sumOfDice ) {
                      case 7: case 11:         // win on first roll
                         gameStatus = WON;
                         // clear point field
                         document.craps.point.value = ""; 
                         break;
                      case 2: case 3: case 12: // lose on first roll
                         gameStatus = LOST;
                         // clear point field
                         document.craps.point.value = ""; 
                         break;
                      default:                   // remember point
                         gameStatus = CONTINUE_ROLLING;
                         myPoint = sumOfDice;
                         document.craps.point.value = myPoint; 
                         firstRoll = false;
                   }
                }
                else {
                   sumOfDice = rollDice();

                   if ( sumOfDice == myPoint ) // win by making point
                      gameStatus = WON;
                   else
                      if ( sumOfDice == 7 )    // lose by rolling 7
                         gameStatus = LOST;
                }

                if ( gameStatus == CONTINUE_ROLLING )
                   window.status = "Roll again";
                else {
                   if ( gameStatus == WON )
                      window.status = "Player wins. " +
                         "Click Roll Dice to play again.";
                   else 
                      window.status = "Player loses. " + 
                         "Click Roll Dice to play again.";

                   firstRoll = true;
                }
             }

             // roll the dice
             function rollDice()
             {
                var die1, die2, workSum;   

                die1 = Math.floor( 1 + Math.random() * 6 );
                die2 = Math.floor( 1 + Math.random() * 6 );
                workSum = die1 + die2;

                document.craps.firstDie.value = die1;
                document.craps.secondDie.value = die2;
                document.craps.sum.value = workSum;

                return workSum;
             }
             </script>

       </head>
       <body>
          <form name = "craps" action = ""> // assigning rule to it 
             <table border = "1">
             <caption>Craps</caption>
             <tr><td>Die 1</td>
                 <td><input name = "firstDie" type = "text" />
                 </td></tr>
             <tr><td>Die 2</td>
                 <td><input name = "secondDie" type = "text" />
                 </td></tr>
             <tr><td>Sum</td>
                 <td><input name = "sum" type = "text" />
                 </td></tr>
             <tr><td>Point</td>
                 <td><input name = "point" type = "text" />
                 </td></tr>
             <tr><td><input type = "button" value = "Roll Dice" 
                 onclick = "play()" /></td></tr>
             </table>
          </form>        
// So at the end i need to add bank which reduces or add the bank according to the game rule.

你的问题是“你会做我的家庭作业吗?”还是你有不同的问题?这不是我家庭作业的一部分,你也不必回答我的问题。我有我自己的代码,我只是需要一点帮助,把跟踪下注金额的银行放在哪里。我错过了你评论的一部分。原谅我。