Rock Paper Scissors Lizard Spock Game
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> ROCK, PAPER, SESSOR, LIZORD, SPORCK </title>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
var myarray1 = new Array();
var i,j;
var comp_select;
var myarray = new Array();
function myPlay()
{
for(i=1;i<=5;i++)
{
var fname =prompt("Please enter your "+i+" keyword like rock, paper, scissors, lizard, spock:","rock")
myarray1[i]=fname;
document.getElementById("usr"+i+"").innerHTML="user entred value : "+myarray1[i];
var temp=Math.floor((Math.random()*(6-1))+1);
switch(temp)
{
case 1 : myarray[i]="rock";
document.getElementById("cmp"+i+"").innerHTML="computr randomly genereted value : "+myarray[i];
break;
case 2 : myarray[i]="paper";
document.getElementById("cmp"+i+"").innerHTML="computr randomly genereted value : "+myarray[i];
break;
case 3 : myarray[i]="scissors";
document.getElementById("cmp"+i+"").innerHTML="computr randomly genereted value : "+myarray[i];
break;
case 4 : myarray[i]="lizard";
document.getElementById("cmp"+i+"").innerHTML="computr randomly genereted value : "+myarray[i];
break;
case 5 : myarray[i]="spock";
document.getElementById("cmp"+i+"").innerHTML="computr randomly genereted value : "+myarray[i];
break;
}
}
}
function result()
{
var rul= new Array();
rul[1]="scissors cut paper";
rul[2]="paper covers rock";
rul[3]="rock crushes lizard";
rul[4]="lizard poisons spock";
rul[5]="spock smashes scissors";
rul[6]="scissors decapitate lizard";
rul[7]="lizard eats paper";
rul[8]="paper disproves spock";
rul[9]="spock vaporizes rock";
rul[10]="rock crushes scissors";
for(var i=1,j=1;i<=5,j<=5;i++,j++)
{
if(myarray1[i]==myarray[j])
{
document.getElementById("result"+i+"").innerHTML="the result is : tie";
}
else
{
for(var k=1;k<=10;k++)
{
var comp_str=rul[k].match(myarray[i]);
var humn_str=rul[k].match(myarray1[j]);
if(comp_str && humn_str!=null)
{
var humn_count;
var comp_count;
var humn_count= rul[k].indexOf(humn_str);
var comp_count=rul[k].indexOf(comp_str);
if(humn_count || comp_count!=-1)
{
if(humn_count<10)
{
document.getElementById("result"+i+"").innerHTML=humn_str+"wins";
}
else
{
document.getElementById("result"+i+"").innerHTML=comp_str+"wins";
}
}
}
}
}
}
}
</script>
</head>
<body>
<div id="usr1"></div><br/>
<div id="cmp1"></div><br/>
<div id="result1"></div><br/><br/>
<div id="usr2"></div><br/>
<div id="cmp2"></div><br/>
<div id="result2"></div><br/><br/>
<div id="usr3"></div><br/>
<div id="cmp3"></div><br/>
<div id="result3"></div><br/><br/>
<div id="usr4"></div><br/>
<div id="cmp4"></div><br/>
<div id="result4"></div><br/><br/>
<div id="usr5"></div><br/>
<div id="cmp5"></div><br/>
<div id="result5"></div><br/><br/>
<form>
<input type="button" value="play" onclick="myPlay()">
<input type="button" value="result" onclick="result()">
</form>
</body>
</html>
Number Guessing Game
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> Guess game </title>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
function play(number)
{
var comp_selected=Math.floor((Math.random()*100)+1);
if(number == 100)
count=7;
if(number == 1000)
count=10;
for(i=1;i<=count;i++)
{
var usr_selected =prompt("Please enter your "+i+" guessing numbr form 1 to "+number+".")
if(usr_selected>comp_selected)
{
document.getElementById(i).innerHTML= ""+usr_selected+" is <b>larger</b> than computer selected value";
}
else if(usr_selected<comp_selected)
{
document.getElementById(i).innerHTML= ""+usr_selected+" is <b>smaller</b> than computer selected value";
}
else if(usr_selected==comp_selected)
{
document.getElementById(i).innerHTML= "you got the right answer: computer selected value is "+comp_selected+" .";
break;
}
if(i==count&& comp_selected!=usr_selected)
{
alert("you lose the game, computer selected value is "+comp_selected+ " .");
}
}
}
</script>
</head>
<body>
<form>
<input type="button" value="Guess from 0..100" onClick="play(100);"/>
<input type="button" value="Gusedd from 0...1000" onClick="play(1000);"/>
<div id="1"></div><br/>
<div id="2"></div><br/>
<div id="3"></div><br/>
<div id="4"></div><br/>
<div id="5"></div><br/>
<div id="6"></div><br/>
<div id="7"></div><br/>
<div id="8"></div><br/>
<div id="9"></div><br/>
<div id="10"></div><br/>
</form>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> ROCK, PAPER, SESSOR, LIZORD, SPORCK </title>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
var myarray1 = new Array();
var i,j;
var comp_select;
var myarray = new Array();
function myPlay()
{
for(i=1;i<=5;i++)
{
var fname =prompt("Please enter your "+i+" keyword like rock, paper, scissors, lizard, spock:","rock")
myarray1[i]=fname;
document.getElementById("usr"+i+"").innerHTML="user entred value : "+myarray1[i];
var temp=Math.floor((Math.random()*(6-1))+1);
switch(temp)
{
case 1 : myarray[i]="rock";
document.getElementById("cmp"+i+"").innerHTML="computr randomly genereted value : "+myarray[i];
break;
case 2 : myarray[i]="paper";
document.getElementById("cmp"+i+"").innerHTML="computr randomly genereted value : "+myarray[i];
break;
case 3 : myarray[i]="scissors";
document.getElementById("cmp"+i+"").innerHTML="computr randomly genereted value : "+myarray[i];
break;
case 4 : myarray[i]="lizard";
document.getElementById("cmp"+i+"").innerHTML="computr randomly genereted value : "+myarray[i];
break;
case 5 : myarray[i]="spock";
document.getElementById("cmp"+i+"").innerHTML="computr randomly genereted value : "+myarray[i];
break;
}
}
}
function result()
{
var rul= new Array();
rul[1]="scissors cut paper";
rul[2]="paper covers rock";
rul[3]="rock crushes lizard";
rul[4]="lizard poisons spock";
rul[5]="spock smashes scissors";
rul[6]="scissors decapitate lizard";
rul[7]="lizard eats paper";
rul[8]="paper disproves spock";
rul[9]="spock vaporizes rock";
rul[10]="rock crushes scissors";
for(var i=1,j=1;i<=5,j<=5;i++,j++)
{
if(myarray1[i]==myarray[j])
{
document.getElementById("result"+i+"").innerHTML="the result is : tie";
}
else
{
for(var k=1;k<=10;k++)
{
var comp_str=rul[k].match(myarray[i]);
var humn_str=rul[k].match(myarray1[j]);
if(comp_str && humn_str!=null)
{
var humn_count;
var comp_count;
var humn_count= rul[k].indexOf(humn_str);
var comp_count=rul[k].indexOf(comp_str);
if(humn_count || comp_count!=-1)
{
if(humn_count<10)
{
document.getElementById("result"+i+"").innerHTML=humn_str+"wins";
}
else
{
document.getElementById("result"+i+"").innerHTML=comp_str+"wins";
}
}
}
}
}
}
}
</script>
</head>
<body>
<div id="usr1"></div><br/>
<div id="cmp1"></div><br/>
<div id="result1"></div><br/><br/>
<div id="usr2"></div><br/>
<div id="cmp2"></div><br/>
<div id="result2"></div><br/><br/>
<div id="usr3"></div><br/>
<div id="cmp3"></div><br/>
<div id="result3"></div><br/><br/>
<div id="usr4"></div><br/>
<div id="cmp4"></div><br/>
<div id="result4"></div><br/><br/>
<div id="usr5"></div><br/>
<div id="cmp5"></div><br/>
<div id="result5"></div><br/><br/>
<form>
<input type="button" value="play" onclick="myPlay()">
<input type="button" value="result" onclick="result()">
</form>
</body>
</html>
Number Guessing Game
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> Guess game </title>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
function play(number)
{
var comp_selected=Math.floor((Math.random()*100)+1);
if(number == 100)
count=7;
if(number == 1000)
count=10;
for(i=1;i<=count;i++)
{
var usr_selected =prompt("Please enter your "+i+" guessing numbr form 1 to "+number+".")
if(usr_selected>comp_selected)
{
document.getElementById(i).innerHTML= ""+usr_selected+" is <b>larger</b> than computer selected value";
}
else if(usr_selected<comp_selected)
{
document.getElementById(i).innerHTML= ""+usr_selected+" is <b>smaller</b> than computer selected value";
}
else if(usr_selected==comp_selected)
{
document.getElementById(i).innerHTML= "you got the right answer: computer selected value is "+comp_selected+" .";
break;
}
if(i==count&& comp_selected!=usr_selected)
{
alert("you lose the game, computer selected value is "+comp_selected+ " .");
}
}
}
</script>
</head>
<body>
<form>
<input type="button" value="Guess from 0..100" onClick="play(100);"/>
<input type="button" value="Gusedd from 0...1000" onClick="play(1000);"/>
<div id="1"></div><br/>
<div id="2"></div><br/>
<div id="3"></div><br/>
<div id="4"></div><br/>
<div id="5"></div><br/>
<div id="6"></div><br/>
<div id="7"></div><br/>
<div id="8"></div><br/>
<div id="9"></div><br/>
<div id="10"></div><br/>
</form>
</body>
</html>
No comments:
Post a Comment