/    Sign up×
Community /Pin to ProfileBookmark

Set time change interval

Hello, I was wondering if someone cold show me how to make my game so that every 2 seconds, the image changes to a different cell if the user does not click it. But if the user does click the image before the 2 seconds are up, then the image changes to a different cell. Thank you very much

[code=php]<html>
<head>
<STYLE type=”text/css”>

TD
{
FONT-WEIGHT: bold;
FONT-SIZE: 75pt;
WIDTH: 75pt;

COLOR: black;
FONT-FAMILY: Wingdings;
HEIGHT: 20pt;

TEXT-ALIGN: center
}

H5
{
MARGIN-TOP: 0px;
MARGIN-BOTTOM: 0px
}

</STYLE>
<script style=”text/javascript”>

var score=0;
var now=scoreDate.valueOf();
var imgSrc = “mole.jpg”;
var imgCell;

function putscore()
{
scoreDate=new Date()
if (document.getElementById)
document.getElementById(“score”).innerHTML=score ;
}

function reset()
{
score=0;
putscore();
}

function highlight(cell)
{
var oncell = false;
var r=Math.round(9*Math.random()) +10;

if (document.getElementById) {
cell = document.getElementById(cell);
if (cell && cell.innerHTML != “&nbsp;”) {
cell.innerHTML = “&nbsp;”;
oncell = true;
}

if (oncell) {

imgCell = document.getElementById(“cell_”+r);
if (imgCell)
{
imgCell.innerHTML = ‘<img src=”mole.jpg” border=”0″ alt=”Picture Unavailable”>’;
}
else
{
document.getElementById(“cell_10″).innerHTML = ‘<img src=”mole.jpg” border=”0″ alt=””>’;
}

score++;
putscore();
}
}
}
</script>
</head>

<body>

<h2 align=”center”>Whack the Mole</h2>

<h4 align=”center”>Hits=<span id=”score”>0</span></h4>

<table border=”1″ align=”center” cellspacing=”0″ cellpadding=”0″>
<tr>

<td id=”cell_10″ onclick=”highlight(‘cell_10’);return true;”><img src=”mole.jpg”></td>
<td id=”cell_11″ onclick=”highlight(‘cell_11’);return true;”>&nbsp;</td>
<td id=”cell_12″ onclick=”highlight(‘cell_12’);return true;”>&nbsp;</td>

</tr>
<tr>
<td id=”cell_13″ onclick=”highlight(‘cell_13’);return true;”>&nbsp;</td>
<td id=”cell_14″ onclick=”highlight(‘cell_14’);return true;”>&nbsp;</td>
<td id=”cell_15″ onclick=”highlight(‘cell_15’);return true;”>&nbsp;</td>

</tr>
<tr>
<td id=”cell_16″ onclick=”highlight(‘cell_16’);return true;”>&nbsp;</td>
<td id=”cell_17″ onclick=”highlight(‘cell_17’);return true;”>&nbsp;</td>
<td id=”cell_18″ onclick=”highlight(‘cell_18’);return true;”>&nbsp;</td>

</tr>

</table>
<p align=center><input type=”reset” onclick=”javascript:reset(); return true;”></p>

</body>
</html>
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorDec 04.2007 — It was a typo? You said so, by short:, if click over 2 secs, the image should move, if click under 2 secs, the image should move. Which is the difference, then?
×

Success!

Help @asclepius spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...