2017-02-10 22 views
-4

的Yahtzee組合

<body> 
 
<div class="board" style="border: 2px solid black"> 
 
\t <table border="1" height='200' > 
 
\t  <tr> 
 

 
\t \t \t <th colspan="3">Upper Section</th> 
 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td>Aces</td> 
 
\t \t \t <td>Sum of all the ones</td> 
 
\t \t \t <td class="aceScore">50</td> 
 
\t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t <td>Twos</td> 
 
\t \t \t <td>Sum of all the twos</td> 
 
\t \t \t <td class="twoScore"></td> 
 
\t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t <td>Threes</td> 
 
\t \t \t <td>Sum of all the threes</td> 
 
\t \t \t <td class="threeScore"></td> 
 
\t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t <td>Fours</td> 
 
\t \t \t <td>Sum of all the fours</td> 
 
\t \t \t <td class="fourScore"></td> 
 
\t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t <td>Fives</td> 
 
\t \t \t <td>Sum of all the fives</td> 
 
\t \t \t <td class="fiveScore"></td> 
 

 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td>Sixes</td> 
 
\t \t \t <td>Sum of all the sixes</td> 
 
\t \t \t <td class="sixScore"></td> 
 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td colspan ='2'>Total</td> 
 
\t \t 
 
\t \t \t <td class="totalScore"></td> 
 

 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td>Bonus</td> 
 
\t \t \t <td>Score 35 </td> 
 
\t \t \t <td class="bonus"></td> 
 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td colspan ='2'>Upper Total</td> 
 
\t \t 
 
\t \t \t <td class="upperScore"></td> 
 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <th colspan="3">Lower Section</th> 
 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td>3 of a Kind</td> 
 
\t \t \t <td>SUm of all dice</td> 
 
\t \t \t <td class="three_of_kind"></td> 
 
\t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t <td>4 of a kind</td> 
 
\t \t \t <td>Sum of all dice</td> 
 
\t \t \t <td class="four_of_kind"></td> 
 
\t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t <td>Full House</td> 
 
\t \t \t <td>Score 35</td> 
 
\t \t \t <td class="fullhouse"></td> 
 
\t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t <td>sm. straight</td> 
 
\t \t \t <td>Score 30</td> 
 
\t \t \t <td class="sm"></td> 
 
\t \t </tr> 
 
\t \t \t <tr> 
 
\t \t \t <td>lg. Straight</td> 
 
\t \t \t <td>score 40</td> 
 
\t \t \t <td class="lg"></td> 
 

 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td>Yahtzee</td> 
 
\t \t \t <td>Score yatzee</td> 
 
\t \t \t <td class="yatzee"></td> 
 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td>Chance</td> 
 
\t \t \t <td>sum of all dice</td> 
 
\t \t \t <td class="chance"></td> 
 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td colspan ='2'>Lower Total</td> 
 
\t \t 
 
\t \t \t <td class="lowerScore"></td> 
 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td colspan ='2'>Upper Total</td> 
 
\t \t 
 
\t \t \t <td class="UpperScore"></td> 
 
\t \t </tr> 
 
\t \t <tr> 
 
\t \t \t <td colspan ='2'>Combined Total</td> 
 
\t \t 
 
\t \t \t <td class="combinedScore"></td> 
 
\t \t </tr> 
 
\t \t <section class="dice"> 
 
\t \t \t <div class="die die1"></div> 
 
\t \t  <div class="die die2"></div> 
 
\t \t  <div class="die die3"></div> 
 
\t \t \t <div class="die die4"></div> 
 
\t \t \t <div class="die die5"></div> 
 
\t \t \t 
 
\t \t \t \t 
 
\t \t </section> 
 
\t \t <button class="button">ROll</button> 
 
\t \t <span class="warning"></span> 
 
\t 
 

 

 
\t </table> 
 
</div> <!-- board div --> 
 

 
</body>

試圖找出加起來的得分爲我的Yahtzee遊戲中每個可能的組合的最佳方式。現在專注於前6行,這將添加所有的,兩個...等,所以它可以添加到表中。

最初它工作正常,將分數給相應的部分

我的問題是1)我不想分數繼續增加,我想重投骰子每一次,我需要它也開始了2)我有它,所以骰子不改變價值,如果選擇,因此我不希望該分數改變。我希望這是有道理的。

$(document).ready(function(){ 
 
    var die1=$('.die1'); 
 
    var die2=$('.die2'); 
 
    var die3=$('.die3'); 
 
    var die4=$('.die4'); 
 
    var die5=$('.die5'); 
 
    var turns=3; 
 
    var dice; 
 
    var dice_value = new Array(5); 
 
    var ones=0; 
 
    var twos=0; 
 
    var threes=0; 
 
    var fours=0; 
 
    var fives=0; 
 
    var sixes=0; 
 
    
 
    //roll function 
 
\t function roll(die,i){ 
 
\t  rando = Math.floor(Math.random()*6)+1; 
 
\t  
 
\t  die.html("<img src=images/die"+rando+".png>"); 
 
\t  die.find('img').attr('class', rando); 
 
\t  
 
      dice_value[i]=rando; 
 
      console.log(dice_value); 
 
\t $('img').height(50); 
 
\t }; 
 

 

 
\t $('.die').click(function(){ 
 
     $(this).toggleClass('selected'); //adds border around die if clicked 
 
    }); 
 

 
\t // 1-6 
 
\t // function firstsix(){ 
 
\t \t \t 
 
\t // \t \t for(i=0;i<5; i++){ 
 
\t 
 
\t // } 
 

 

 
//attaches roll funcition to each die 
 
$('.button').click(function(){ 
 
    
 
\t  
 
\t for(i=0; i<=turns; turns--){ 
 
\t  if(turns>0){ 
 
\t \t  dice =[die1,die2,die3,die4,die5]; 
 

 
\t \t \t for(i=0; i<dice.length;i++){ 
 
\t \t \t \t  \t 
 
\t \t \t \t  
 
\t \t \t \t \t if (!dice[i].hasClass('selected')){ 
 
\t \t \t \t \t \t roll(dice[i],i); 
 

 
\t    } 
 
\t \t \t  
 
         
 
\t \t \t \t  if(dice_value[i] ==1){ 
 
\t \t \t \t    ones =ones +1; 
 
\t \t \t \t  } 
 
\t \t \t \t  if(dice_value[i]== 2){ 
 
\t \t \t \t   \t twos= twos +2; 
 
\t \t \t \t  } 
 
\t \t \t \t  if(dice_value[i]==3){ 
 
\t \t     threes= threes+3; 
 
\t \t \t \t  } 
 
\t \t \t \t   if(dice_value[i]==4){ 
 
\t \t \t \t   \t fours= fours+4; 
 
\t \t \t \t  } 
 
\t \t \t \t   if(dice_value[i]==5){ 
 
\t \t \t \t   \t fives= fives +5; 
 
\t \t \t \t  } 
 
\t \t \t \t   if(dice_value[i]==6){ 
 
\t \t \t \t   \t sixes= six + 6; 
 
\t \t \t \t  } 
 

 
\t \t \t \t \t 
 
\t \t \t \t \t $('.aceScore').html(ones); 
 
\t \t \t \t \t $('.twoScore').html(twos); 
 
\t \t \t \t \t $('.threeScore').html(threes); 
 
\t \t \t \t \t $('.fourScore').html(fours); 
 
\t \t \t \t \t $('.fiveScore').html(fives); 
 
\t \t \t \t \t $('.sixScore').html(sixes); 
 
\t \t \t \t 
 
\t \t \t  
 
\t \t \t  } 
 
\t   
 
\t \t } 
 
\t \t else{ 
 
\t \t \t $('.warning').html('Pick a category!'); 
 
\t \t } 
 

 
     \t 
 

 
\t } 
 
\t \t 
 

 
    }); //button function 
 

 

 
});

+1

昨天你不是問同樣的問題嗎? – Steve

+0

是的,我做到了。和? –

+0

它似乎已被刪除,這個問題也沒有什麼不同。您應該編輯您的問題爲[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)並提出具體問題。現在它只是一個代碼轉儲,帶有「任何想法?」這對於SO而言是無關緊要的。 – Steve

回答

0

,所以我不得不創建另一個按鈕,以便當用戶滿意的骰子,然後該按鈕將執行計算功能。