Dicegame
<html>
<head>
<script type="text/JavaScript">
var total1=0;
var total2=0;
function rollDice1()
{
var die1,die2,d1,d2;
die1=document.getElementById("die1");
die2=document.getElementById("die2");
status1=document.getElementById("status1");
scoreof1 = document.getElementById("scoreof2");
d1=Math.floor(Math.random()* 6 ) + 1;
d2=Math.floor(Math.random()* 6 ) + 1;
if(d1==d2)
{
if(d1==1||d1==2||d1==4||d1==5)
{
total1=total1+5;
}
if(d1==6)
{
total1=total1+25;
}
if(d1==3)
{
total1=0;
}
}
status1.innerHTML="Player 1 rolled:"+d1+" "+d2+".";
scoreof1.innerHTML="Player 1 Totalscore:"+total1;
if(total1 >= 50)
{
document.writeln("Congratulations! Player 1 Won the game");
}
}
function rollDice2()
{
var die1,die2,d1,d2;
die1=document.getElementById("die1");
die2=document.getElementById("die2");
status2=document.getElementById("status2");
scoreof2 = document.getElementById("scoreof2");
d1=Math.floor(Math.random()* 6 ) + 1;
d2=Math.floor(Math.random()* 6 ) + 1;
if(d1==d2)
{
if(d1==1||d1==2||d1==4||d1==5)
{
total2=total2+5;
}
if(d1==6)
{
total2=total2+25;
}
if(d1==3)
{
total2=0;
}
}
status2.innerHTML="Player 2 rolled:"+d1+" "+d2+".";
scoreof2.innerHTML="Player 2 Totalscore:"+total2;
if(total2 >= 50)
{
document.writeln("Congratulations! Player 2 Won the game");
}
}
</script>
</head>
<body>
<h1> WELCOME TO THE TWO DICE GAME</h1>
<h2>RULES:</h2>
1.Each player throws both dice once per turn.You only score if you throw doubles.<br>
2.Players score five points for double ones,twos,fours or fives.A double six scores twenty five points,but if you throw a double three your score goes back to zero. <br>
3.Add your score as you play.The first player to get fifty points wins the game.<br><br>
<button onclick="rollDice1()">Throw Dice Player1</button>
<button onclick="rollDice2()">Throw Dice Player2</button><br>
<div id="die1"></div>
<div id="die2"></div>
<h5 id="status1" style="clear;"></h5>
<h5 id="status2" style="clear;"></h5>
<h5 id="scoreof1" style="clear;"></h5>
<h5 id="scoreof2" style="clear;"></h5>
<h5 id="winner1" style="clear;"></h5>
<h5 id="winner2" style="clear;"></h5>
</body>
</html>
Comments
Post a Comment