Touch ME Game - JS
by Francis[ Edit ] 2012-10-29 15:52:38
Touch ME Game in Javascript
Its simple Javascript Game...
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"> </script>
<script type="text/javascript">
function show_one()
{
var fir = randomFromInterval(0,4);
var sec = randomFromInterval(0,4);
var vald = validation(fir,sec);
if(vald==true)
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i==fir && j==sec)
{
$("#"+i+j).html("Touch Me!").fadeIn("slow");
}
else
{
$("#"+i+j).hide();
}
}
}
}
else
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i==fir && j==sec)
{
$("#"+i+j).html("I Touch It!").fadeIn("slow");
}
else
{
$("#"+i+j).hide();
}
}
}
}
}
function randomFromInterval(from,to)
{
return Math.floor(Math.random()*(to-from+1)+from);
}
function validation(fir,sec)
{
var pref = $("#elt1").val();
var pres = $("#elt2").val();
if(pref==fir && pres==sec)
{
fir = randomFromInterval(0,4);
sec = randomFromInterval(0,4);
$("#elt1").val(fir);
$("#elt2").val(sec);
return false;
}
else
{
$("#elt1").val(fir);
$("#elt2").val(sec);
return true;
}
}
</script>
<style type="text/css">
div {
height: 30%;
padding-top: 10px;
text-align: center;
width: 70%;
cursor: pointer;
}
</style>
<?php
echo "<input type=hidden id=elt1> <input type=hidden id=elt2>
<table width=60% height=60% align=center>";
for($i=0;$i<5;$i++)
{
echo "<tr>";
for($j=0;$j<5;$j++)
{
echo "<td width=100px height=100px> <div id=".$i.$j." onmouseover=show_one()> </div> </td>";
}
echo "</tr>";
}
echo "</table>";
?>
<script type="text/javascript">
document.onload = show_one();
</script>
Geethalakshmi
Is it enough to copy paste the script into a php file and run on a browser. I did the same but its not working
0
0
Add ReplyGuna
have you placed jquery file as said in this script?
0
0
Add ReplyFrancis
I updated the Jquery.js file, Now you can copy the code and play
0
0
Add Reply