Yeni24
<html>
<head>
<style type="text/css">
.inup
{
FONT-SIZE: 12px;
FONT-FAMILY: Comic Sans MS;
border: 0;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<script language="JavaScript">
var obj1 = new Array(100),
mc,mc1,
cur_obj,
total_sel,
win = false,
cpu_sel,
ost,
user_sel,
game = true;
function RemoveElementByNum(num)
{
ename="ch"+num;
document.getElementById(ename).style.visibility='hidden';
ename="im"+num;
document.getElementById(ename).src="none.gif";
};
function RemoveCpuSel(num)
{
del=num;
for (i=0; i<mc1; i++)
{
ename="ch"+i;
if (del!=0)
{
if (document.getElementById(ename).style.visibility!='hidden')
{
document.getElementById(ename).style.visibility='hidden';
ename="im"+i;
document.getElementById(ename).src="none.gif";
del-=1;
};
};
};
};
function AI()
{
if ( (mc>1) && (win==false) ) { game=true };
if (game==true)
{
if ( (mc-user_sel)==1 )
{
win=true;
game=false;
};
if ( (mc%4)!=1 )
{
ost=(mc-user_sel)%4;
if (ost==0) { ost=4; };
if (ost>1) { cpu_sel=ost-1; };
else
{
cpu_sel=Math.floor( (3*Math.random()) );
cpu_sel++;
if (cpu_sel>mc) {cpu_sel=mc};
};
};
else {cpu_sel=4-user_sel;};
RemoveCpuSel(cpu_sel);
mc=mc-(cpu_sel+user_sel);
document.getElementById("log").value='Computer select '+cpu_sel+' stick(s)';
};
if ( (mc==1) || (mc<1))
{
game=false;
if (win==true)
{
document.getElementById("log1").style.visibility='hidden';
document.getElementById("log").style.visibility='hidden';
alert('Congratulation!!! YOU WIN!!!!');
game=false;
};
else
{
document.getElementById("log1").style.visibility='hidden';
document.getElementById("log").style.visibility='hidden';
alert('You lost. Artificial intellect WIN!!!! HA- HA- HA!!!!');
game=false;
};
};
document.getElementById("log1").value=mc+" sticks left";
}
function GetClickedElement(){
total=0;
result=false;
for (i=0; i<mc1; i++)
{
ename="ch"+i;
if ((document.getElementById(ename).style.visibility!='hidden') && (document.getElementById(ename).checked)) total++;
};
if (total>3)
{
alert('Too much sticks selected. You may select not more than 3 sticks!!!');
result=false;
}; else
{
result=true;
};
document.getElementById("log").value="You select "+total+" stick(s)";
total_sel=total;
user_sel=total;
return result;
}
function RemoveSelected(){
if ((total_sel!=0) && (total_sel<4))
{
user_sel=total_sel;
for (i=0; i<mc1; i++)
{
ename="ch"+i;
if ((document.getElementById(ename).style.visibility!='hidden') && (document.getElementById(ename).checked)) {RemoveElementByNum(i);};
total_sel=0;
};
AI();
};else
{
if (total_sel>3) alert("Too much selecteed sticks");
else alert('Nothing selected');
};
}
</script>
<title>Sticks game</title>
</head>
<body>
<script language="JavaScript">
mc=prompt("Input number of sticks. Number must be between 7 and 50","23");
if (mc<7) mc=7;
if (mc>50) mc=50;
mc1=mc;
document.write('<center><table><tr>');
for (i=0; i<mc; i++)
{
document.write('<td><img src="http://webdeveloper.earthweb.com/repository/javascripts/2007/04/877231/stick.gif" name="im'+i+'"></td>');
obj1[i]=1;
};
document.write('</tr><tr>');
for (i=0; i<mc; i++) {document.write('<td><input type="checkbox" onClick="GetClickedElement();" name="ch'+i+'"></td>');};
document.write('</tr></table></center>');
</script>
<br>
<center>
<input type="button" value="Remove selected sticks" onClick="RemoveSelected()">
</center>
<br><br><br><br><br><br>
<input type="text" class=inup name="log" size=30><br>
<input type="text" class=inup name="log1" size=30><br>
<script>
document.getElementById("log1").value=mc+" sticks left";
txt='<p>Autor"s site <a href="http://www.shvaika ic.ck.ua">here</a></p>';
document.write(txt);
</script>
</body>
</html>