help=['','Eleven High is a historic dice game. In 1904, Eleven High was banned in Europe, together with several other games of hazard. You play against the computer. Start rolling the dice simply by clicking on them. For every roll, one point goes to the jackpot, and after the cast the numbers are added together. If your roll is a double six, you will immediately lose 12 points. Yet, if your roll is 11, you will win the jackpot. For every other result you will lose the difference between 11 and your roll. For example, if your roll is a five and a three (8 points), you will lose 11-8, hence 3, points. The game will end as soon as either you or the computer run out of points.'];

function preload()
{
imgnr=0;
image=['bg.jpg','0.gif','1.gif','2.gif','3.gif','4.gif','5.gif','6.gif','new.gif','help.gif','about.gif','mail.gif'];
picture=new Array(image.length);
for (i=0;i<image.length;i++)
{
picture[i]=new Image();
picture[i].onload=loadcheck;
picture[i].src=image[i];
}
}

function loadcheck()
{
imgnr++;
if (imgnr==image.length) setup();
}

function setup()
{
dice=new Array();
dicevalue=[1,1]
jackpot=0;
colplayer="strong";
colcomputer="pale";
scoreplayer=100;
scorecomputer=100;
diffplayer="";
diffcomputer="";
pointer=1;
dices();
set="<img src=\"inc.gif\" onclick=\"increase()\" id=\"button1\" alt=\"Increase bet by 10\" title=\"Increase bet by 10\">&nbsp;<img src=\"dec.gif\" onclick=\"decrease()\" id=\"button1\" alt=\"Lower bet by 10\" title=\"Lower bet by 10\">&nbsp;";
message="Game ready: The bet is "+scoreplayer+" each.";
show();
}

function rollplayer()
{
pointer=2;
set="";
scoreplayer--;
jackpot++;
rolling();
dicesblind();
calcplayer();
proveplayer();
}

function rollcomputer()
{
scorecomputer--;
jackpot++;
rolling();
dices();
calccomputer();
provecomputer();
pointer=1;
}

function rolling()
{
for (i=0;i<2;i++) dice[i]="<img src=\"0.gif\" id=\"button2\">";
show();
for (i=0;i<2;i++)
{
j=Math.random();
if (j<1/6) dicevalue[i]=1;
else if (j<2/6) dicevalue[i]=2;
else if (j<3/6) dicevalue[i]=3;
else if (j<4/6) dicevalue[i]=4;
else if (j<5/6) dicevalue[i]=5;
else dicevalue[i]=6;
}
}

function dices()
{
for (i=0;i<2;i++) dice[i]="<img src=\""+dicevalue[i]+".gif\" onclick=\"rollplayer()\" id=\"button1\">";
}

function dicesblind()
{
for (i=0;i<2;i++) dice[i]="<img src=\""+dicevalue[i]+".gif\" id=\"button2\">";
}

function show()
{
menu="<img src=\"new.gif\" onclick=\"setup()\" id=\"button1\" alt=\"Set up new game\" title=\"Set up new game\">&nbsp;"+set+"<img src=\"help.gif\" onclick=\"showhelp()\" id=\"button1\" alt=\"Toggle help on/off\" title=\"Toggle help on/off\">&nbsp;<img src=\"about.gif\" onclick=\"aboutus()\" id=\"button1\" alt=\"About this game\" title=\"About this game\">&nbsp;<a href=\"mailto:thomas.weibel@bluewin.ch\" title=\"E-mail to the author\"><img src=\"mail.gif\" id=\"button1\" border=\"0\" alt=\"E-mail to the author\"><\/a>";
display="<p id=\"title\">Eleven High<\/p><table id=\"table"+pointer+"\"><tr><td id=\"space1\" rowspan=\"2\"><\/td><td id=\"dice\">"+dice[0]+"&nbsp;"+dice[1]+"<\/td><td id=\"space2\" rowspan=\"2\"><\/td><td id=\"help\" rowspan=\"2\"><span>"+help[0]+"<\/span><\/td><\/tr><tr><td id=\"calc\"><table id=\"table3\"><tr><td id=\"pale\">Jackpot<\/td><td id=\"space1\"><\/td><td id=\""+colplayer+"\">You<\/td><td id=\"space1\"><\/td><td id=\""+colcomputer+"\">Computer<\/td><td id=\"space1\"><\/td><\/tr><tr><td id=\"pale\">"+jackpot+"<\/td><td id=\"space1\"><\/td><td id=\""+colplayer+"\">"+scoreplayer+"<\/td><td id=\"space1\"><\/td><td id=\""+colcomputer+"\">"+scorecomputer+"<\/td><td id=\"space1\"><\/td><\/tr><tr><td id=\"pale\"><\/td><td id=\"space1\"><\/td><td id=\""+colplayer+"\">"+diffplayer+"<\/td><td id=\"space1\"><\/td><td id=\""+colcomputer+"\">"+diffcomputer+"<\/td><td id=\"space1\"><\/td><\/tr><\/table><\/td><\/tr><\/table><p id=\"copyright\">&copy; 2009 twb<\/p><p>"+message+"<\/p><p id=\"menu\">"+menu+"<\/p>";
document.getElementById('screen').innerHTML=display;
}

function calcplayer()
{
debt=0;
if (dicevalue[0]+dicevalue[1]==12) {debt=12;scoreplayer=scoreplayer-debt;jackpot=jackpot+debt;}
else if (dicevalue[0]+dicevalue[1]==11) {scoreplayer=scoreplayer+jackpot;message="Eleven High: You win "+jackpot+"!";diff=jackpot;jackpot=0;}
else {debt=11-(dicevalue[0]+dicevalue[1]);scoreplayer=scoreplayer-debt;jackpot=jackpot+debt;}
if (jackpot!=0) {message="";diffplayer="-"+debt;}
else diffplayer="+"+diff;
diffcomputer="";
colcomputer="strong";
colplayer="pale";
}

function calccomputer()
{
debt=0;
if (dicevalue[0]+dicevalue[1]==12) {debt=12;scorecomputer=scorecomputer-debt;jackpot=jackpot+debt;}
else if (dicevalue[0]+dicevalue[1]==11) {scorecomputer=scorecomputer+jackpot;message="Eleven High: The computer wins "+jackpot+"!";diff=jackpot;jackpot=0;}
else {debt=11-(dicevalue[0]+dicevalue[1]);scorecomputer=scorecomputer-debt;jackpot=jackpot+debt;}
if (jackpot!=0) {message="";diffcomputer="-"+debt;}
else diffcomputer="+"+diff;
diffplayer="";
colcomputer="pale";
colplayer="strong";
}

function proveplayer()
{
if (scoreplayer<=0)
{
pointer=1;
dicesblind();
message="You bust &#150; sorry: The computer wins!";
setTimeout('show()',500);
}
else
{
setTimeout('show()',500);
setTimeout('rollcomputer()',3500);
}
}

function provecomputer()
{
if (scorecomputer<=0)
{
dicesblind();
message="Computer busts &#150; congratulations: you win!";
}
setTimeout('show()',500);
}

function increase()
{
if (scoreplayer>=10)
{
scoreplayer=scoreplayer+10;
scorecomputer=scorecomputer+10;
message="Game ready: The bet is "+scoreplayer+" each.";
show();
}
}

function decrease()
{
if (scoreplayer>=20)
{
scoreplayer=scoreplayer-10;
scorecomputer=scorecomputer-10;
message="Game ready: The bet is "+scoreplayer+" each.";
show();
}
}

function showhelp()
{
help.reverse();
show();
}

function aboutus()
{
message="Eleven High 1.0 by www.thomasweibel.ch";
show();
}
