<!--Copyright (C) MJ Demarco 2000

//generates a dice picture cycle

//loads the images for the dice cycle
var dicearray=new
Array("images/d1.gif","images/d2.gif","images/d3.gif","images/d4.gif","images/d5.gif","images/d6.gif")

//loads the images for the verdict
var guessarray=new Array("images/blank.gif","images/correct.gif","images/wrong.gif")

var dicestart=0 //start the dice roll with image 0 from the array
var imgcount=6 //number of images to cycle
var count=0 //this is the initial value for the timer which eventually stops the dice roll

function rolldice(){
//allows for the array starting at 0, not 1
var userguess = document.yourguess.u_guess.value - 1;

//this checks for idiots entering either none or more than one character
if (document.yourguess.u_guess.value.length !=1){
alert ("Enter a valid number " + u_name + "\n 1, 2, 3, 4, 5, or 6");
document.yourguess.u_guess.value="";document.yourguess.u_guess.focus();return true;}//returns focus to the input box

//this checks for character position (ie number or letter) and limits to a floor of "1"
for (i=0; i<document.yourguess.u_guess.value.length; i++){
if (document.yourguess.u_guess.value.charAt(i) <"1"){
alert ("Enter a valid number " + u_name + "\n 1, 2, 3, 4, 5, or 6");
document.yourguess.u_guess.value="";document.yourguess.u_guess.focus();return true;}//returns focus to the input box

//this checks for character position (ie number or letter) and limits it to a ceiling of "6"
if (document.yourguess.u_guess.value.charAt(i) >"6"){
alert ("Enter a valid number " + u_name + "\n 1, 2, 3, 4, 5, or 6");
document.yourguess.u_guess.value="";document.yourguess.u_guess.focus();return true;}//returns focus to the input box
}


document.user.src=dicearray[userguess]

if (count<=31)//sets number of cycles for the dice to "roll"
{
if (document.images)//checks for array to be loaded
	{
	dicestart++//increments the dice array to the next picture
	count++//increments the "roll" cycle counter
	if(dicestart==imgcount)//if the array has reached its end it starts at no. one (0) again

		{
		dicestart=0
		}

document.randm.src=dicearray[dicestart]//cycles the picture on the web page
setTimeout("rolldice()", 3 * 25)//sets the speed of the dice"roll"
	}
}

else

{
count = Math.floor(Math.random() * imgcount); //this is the random number generator

var result = dicestart;//sets the variable to check the result with the user's guess

if (userguess == result)//checking user's guess against Mortimer's roll
	//displays the verdict according to the result and adds to the guess score
	document.verdict.src=guessarray[1],goodguess++,document.yourguess.u_guess.focus(),document.yourguess.u_guess.value="";

	else

	document.verdict.src=guessarray[2],badguess++,document.yourguess.u_guess.focus(),document.yourguess.u_guess.value="";
}
}
//-->
