<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- Fig. 9.6: Craps.html -->
<!-- Craps game simulation. -->
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Program that Simulates the Game of Craps</title>
<style type = "text/css">
table { text-align: right }
body { font-family: arial, sans-serif }
div.red { color: red }
</style>
<script type = "text/javascript">
<!--
var sumOfDice = 0; // sum of the dice
var result;
var LSresult;
var bat;
var balance;
var batN = 0;
var balanceN =0;
// process one roll of the dice
function play()
{
result=0;
LSresult=0;
if ( document.getElementById( "batfield" ).value == "")
bat = 0;
else
bat = document.getElementById( "batfield" ).value;
batN = parseInt( bat );
sumOfDice = rollDice();
if ( (sumOfDice%2) == 0 )
{
if ( document.getElementById( "raeven" ).checked )
//document.getElementById( "status" ).innerHTML = "You bat Even has won.";
result = 1;
if ( document.getElementById( "raodd" ).checked )
//document.getElementById( "status" ).innerHTML = "You bat Odd has lose.";
result = 2;
document.getElementById( "oefield" ).value = "Even";
}
else
{
if ( document.getElementById( "raodd" ).checked )
//document.getElementById( "status" ).innerHTML = "You bat Odd has won.";
result = 3;
if ( document.getElementById( "raeven" ).checked )
//document.getElementById( "status" ).innerHTML = "You bat Even has lose.";
result = 4;
if ( document.getElementById( "ralarge" ).checked )
{
//document.getElementById( "status" ).innerHTML = "You bat Large has won.";
if (result ==0)
result = 5;
LSresult = 1;
}
if ( document.getElementById( "rasmall" ).checked )
{
//document.getElementById( "status" ).innerHTML = "You bat Small has lose.";
if (result ==0)
result = 6;
LSresult = 2;
}
}
else
{
document.getElementById( "lsfield" ).value = "Small";
if ( document.getElementById( "rasmall" ).checked )
{
//document.getElementById( "status" ).innerHTML = "You bat Small has won.";
if (result ==0)
result = 7;
LSresult = 3;
}
if ( document.getElementById( "ralarge" ).checked )
{
//document.getElementById( "status" ).innerHTML = "You bat Large has lose.";
if (result ==0)
result = 8;
LSresult = 4;
}
}
switch (result)
{
case 1:
switch (LSresult )
{
case 0:
document.getElementById( "status" ).innerHTML = "You bat Even has won.";
balanceN = balanceN +batN;
break;
case 1:
document.getElementById( "status" ).innerHTML = "You bat Even has won and You bat Large has won.";
balanceN = balanceN +batN +batN;
break;
case 2:
document.getElementById( "status" ).innerHTML = "You bat Even has won and You bat Small has lose.";
break;
case 3:
document.getElementById( "status" ).innerHTML = "You bat Even has won and You bat Small has won.";
balanceN = balanceN +batN +batN;
break;
case 4:
document.getElementById( "status" ).innerHTML = "You bat Even has won and You bat Large has lose.";
break;
}
break;
case 2:
//document.getElementById( "status" ).innerHTML = "You bat Odd has lose.";
switch (LSresult )
{
case 0:
document.getElementById( "status" ).innerHTML = "You bat Odd has lose.";
balanceN = balanceN - batN;
break;
case 1:
document.getElementById( "status" ).innerHTML = "You bat Odd has lose and You bat Large has won.";
break;
case 2:
document.getElementById( "status" ).innerHTML = "You bat Odd has lose and You bat Small has lose.";
balanceN = balanceN -batN -batN;
break;
case 3:
document.getElementById( "status" ).innerHTML = "You bat Odd has lose and You bat Small has won.";
break;
case 4:
document.getElementById( "status" ).innerHTML = "You bat Odd has lose and You bat Large has lose.";
balanceN = balanceN -batN -batN;
break;
}
break;
case 3:
//document.getElementById( "status" ).innerHTML = "You bat Odd has won.";
switch (LSresult )
{
case 0:
document.getElementById( "status" ).innerHTML = "You bat Odd has won.";
balanceN = balanceN +batN;
break;
case 1:
document.getElementById( "status" ).innerHTML = "You bat Odd has won and You bat Large has won.";
balanceN = balanceN +batN +batN;
break;
case 2:
document.getElementById( "status" ).innerHTML = "You bat Odd has won and You bat Small has lose.";
break;
case 3:
document.getElementById( "status" ).innerHTML = "You bat Odd has won and You bat Small has won.";
balanceN = balanceN +batN +batN;
break;
case 4:
document.getElementById( "status" ).innerHTML = "You bat Odd has won and You bat Large has lose.";
break;
}
break;
case 4:
//document.getElementById( "status" ).innerHTML = "You bat Even has lose.";
switch (LSresult )
{
case 0:
document.getElementById( "status" ).innerHTML = "You bat Even has lose.";
balanceN = balanceN -batN;
break;
case 1:
document.getElementById( "status" ).innerHTML = "You bat Even has lose and You bat Large has won.";
break;
case 2:
document.getElementById( "status" ).innerHTML = "You bat Even has lose and You bat Small has lose.";
balanceN = balanceN -batN -batN;
break;
case 3:
document.getElementById( "status" ).innerHTML = "You bat Even has lose and You bat Small has won.";
break;
case 4:
document.getElementById( "status" ).innerHTML = "You bat Even has lose and You bat Large has lose.";
balanceN = balanceN -batN -batN;
break;
}
break;
case 5:
document.getElementById( "status" ).innerHTML = "You bat Large has won.";
balanceN = balanceN +batN;
break;
case 6:
document.getElementById( "status" ).innerHTML = "You bat Small has lose.";
balanceN = balanceN -batN;
break;
case 7:
document.getElementById( "status" ).innerHTML = "You bat Small has won.";
balanceN = balanceN +batN;
break;
case 8:
document.getElementById( "status" ).innerHTML = "You bat Large has lose.";
balanceN = balanceN -batN;
break;
return workSum;
} // end function rollDice
// -->
</script>
</head>
<body>
<form action = "">
<table border="1" cellpadding="10">
<caption>Die Game</caption>
<tr>
<td>Die 1</td>
<td><input id = "die1field" type = "text" /></td>
<td> </td>
<td>
<label>Odd</label>
<input id = "raodd" type = "radio" name = "radiobutton1" value = "odd" />
</td>
</tr>
<tr>
<td>Die 2</td>
<td><input id = "die2field" type = "text" /></td>
<td> </td>
<td>
<label>Even</label>
<input id = "raeven" type = "radio" name = "radiobutton1" value = "even" />
</td>
</tr>
<tr>
<td>Die 3</td>
<td><input id = "die3field" type = "text" /></td>
<td> </td>
<td>
<label>Large</label>
<input id = "ralarge" type = "radio" name = "radiobutton2" value = "large" />
</td>
</tr>
<tr>
<td>Sum</td>
<td><input id = "sumfield" type = "text" /></td>
<td> </td>
<td>
<label>Small</label>
<input id = "rasmall" type = "radio" name = "radiobutton2" value = "small" />
</td>
</tr>
<tr>
<td>Odd/Even</td>
<td><input id = "oefield" type = "text" /></td>
<td>Bat Amount</td>
<td><input id = "batfield" type = "text" /></td>
</tr>
<tr>
<td>Large/Small</td>
<td><input id = "lsfield" type = "text" /></td>
<td>Balance</td>
<td><input id = "balancefield" type = "text" /></td>
</tr>
<tr><td /><td><input type = "button" value = "Roll Dice"
onclick = "play()" /></td></tr>
</table>
<div id = "status" class = "red">
Click the Roll Dice button to play</div>
</form>
</body>
</html>