<body>
<div class="board" style="border: 2px solid black">
<table border="1" height='200' >
<tr>
<th colspan="3">Upper Section</th>
</tr>
<tr>
<td>Aces</td>
<td>Sum of all the ones</td>
<td class="aceScore">50</td>
</tr>
<tr>
<td>Twos</td>
<td>Sum of all the twos</td>
<td class="twoScore"></td>
</tr>
<tr>
<td>Threes</td>
<td>Sum of all the threes</td>
<td class="threeScore"></td>
</tr>
<tr>
<td>Fours</td>
<td>Sum of all the fours</td>
<td class="fourScore"></td>
</tr>
<tr>
<td>Fives</td>
<td>Sum of all the fives</td>
<td class="fiveScore"></td>
</tr>
<tr>
<td>Sixes</td>
<td>Sum of all the sixes</td>
<td class="sixScore"></td>
</tr>
<tr>
<td colspan ='2'>Total</td>
<td class="totalScore"></td>
</tr>
<tr>
<td>Bonus</td>
<td>Score 35 </td>
<td class="bonus"></td>
</tr>
<tr>
<td colspan ='2'>Upper Total</td>
<td class="upperScore"></td>
</tr>
<tr>
<th colspan="3">Lower Section</th>
</tr>
<tr>
<td>3 of a Kind</td>
<td>SUm of all dice</td>
<td class="three_of_kind"></td>
</tr>
<tr>
<td>4 of a kind</td>
<td>Sum of all dice</td>
<td class="four_of_kind"></td>
</tr>
<tr>
<td>Full House</td>
<td>Score 35</td>
<td class="fullhouse"></td>
</tr>
<tr>
<td>sm. straight</td>
<td>Score 30</td>
<td class="sm"></td>
</tr>
<tr>
<td>lg. Straight</td>
<td>score 40</td>
<td class="lg"></td>
</tr>
<tr>
<td>Yahtzee</td>
<td>Score yatzee</td>
<td class="yatzee"></td>
</tr>
<tr>
<td>Chance</td>
<td>sum of all dice</td>
<td class="chance"></td>
</tr>
<tr>
<td colspan ='2'>Lower Total</td>
<td class="lowerScore"></td>
</tr>
<tr>
<td colspan ='2'>Upper Total</td>
<td class="UpperScore"></td>
</tr>
<tr>
<td colspan ='2'>Combined Total</td>
<td class="combinedScore"></td>
</tr>
<section class="dice">
<div class="die die1"></div>
<div class="die die2"></div>
<div class="die die3"></div>
<div class="die die4"></div>
<div class="die die5"></div>
</section>
<button class="button">ROll</button>
<span class="warning"></span>
</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
function roll(die,i){
rando = Math.floor(Math.random()*6)+1;
die.html("<img src=images/die"+rando+".png>");
die.find('img').attr('class', rando);
dice_value[i]=rando;
console.log(dice_value);
$('img').height(50);
};
$('.die').click(function(){
$(this).toggleClass('selected'); //adds border around die if clicked
});
// 1-6
// function firstsix(){
// for(i=0;i<5; i++){
// }
//attaches roll funcition to each die
$('.button').click(function(){
for(i=0; i<=turns; turns--){
if(turns>0){
dice =[die1,die2,die3,die4,die5];
for(i=0; i<dice.length;i++){
if (!dice[i].hasClass('selected')){
roll(dice[i],i);
}
if(dice_value[i] ==1){
ones =ones +1;
}
if(dice_value[i]== 2){
twos= twos +2;
}
if(dice_value[i]==3){
threes= threes+3;
}
if(dice_value[i]==4){
fours= fours+4;
}
if(dice_value[i]==5){
fives= fives +5;
}
if(dice_value[i]==6){
sixes= six + 6;
}
$('.aceScore').html(ones);
$('.twoScore').html(twos);
$('.threeScore').html(threes);
$('.fourScore').html(fours);
$('.fiveScore').html(fives);
$('.sixScore').html(sixes);
}
}
else{
$('.warning').html('Pick a category!');
}
}
}); //button function
});
答案 0 :(得分:0)
所以我必须创建另一个按钮,这样当用户对骰子感到满意时,那个按钮就会执行一个计算功能。