基本上,我想要点击一张图片,这就是全部,然后我希望它再次运行该级别。最终,我想随机确定底池后面的图片,但如果这样做太难了,那么现在就不要担心。
这是我的代码:
<script language="JavaScript">
lives=3
score=0
document.write("Lives:",lives,"<br>");
document.write("Score:",score);
function clickMeIDFunction(theElementID){
var theElement = document.getElementById(theElementID);
theElement.src = "nope.gif";
}
function clickMeIDFunction2(theElementID){
var theElement = document.getElementById(theElementID);
theElement.src = 'nope.gif';
}
function clickMeIDFunction3(theElementID){
var theElement = document.getElementById(theElementID);
theElement.src = "gold-bar-icon.png";
}
if (lives=0){
document.write("Game over!");
}
</script>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><img id="pot1" src="imageedit_2_3920956067.gif" width="238" height="170" class="pot" onclick="clickMeIDFunction('pot1')">
<img id="pot2" src="imageedit_2_3920956067.gif" width="238" height="170" class="pot" onclick="clickMeIDFunction2('pot2')">
<img id="pot3" src="imageedit_2_3920956067.gif" width="238" height="170" class="pot" onclick="clickMeIDFunction3('pot3')">
</center>
</div>`enter code here`
答案 0 :(得分:1)
这是我理解的解决方案。
<p>Lives: <span id="lives"></span></p>
<p>Score: <span id="score"></span></p>
<p id="game_status"></p>
<p>
<img id="pot1" src="imageedit_2_3920956067.gif" width="238" height="170" class="pot" onclick="clickMeIDFunction('pot1')">
<img id="pot2" src="imageedit_2_3920956067.gif" width="238" height="170" class="pot" onclick="clickMeIDFunction2('pot2')">
<img id="pot3" src="imageedit_2_3920956067.gif" width="238" height="170" class="pot" onclick="clickMeIDFunction3('pot3')">
</p>
<script language="JavaScript">
lives=3
score=0
function clickMeIDFunction(theElementID){
var theElement = document.getElementById(theElementID);
theElement.src = "nope.gif";
// decrease lives by 1 as it is a nope
lives--;
// call update_game_info so that it will update the lives and scores in the DOM
update_game_info()
}
function clickMeIDFunction2(theElementID){
var theElement = document.getElementById(theElementID);
theElement.src = 'nope.gif';
// same as for clickMeIDFunction
lives--;
update_game_info()
}
function clickMeIDFunction3(theElementID){
var theElement = document.getElementById(theElementID);
theElement.src = "gold-bar-icon.png";
// a correct click, so increase score by 1, do nothing to lives
score++;
// update the info in DOM
update_game_info();
}
// Update the game info, reset/restart game if score is 0
function update_game_info(){
document.getElementById("lives").innerHTML = lives;
document.getElementById("score").innerHTML = score;
if (lives == 0){
document.getElementById("game_status").innerHTML = "Game Over!";
// Restart game
// Reset lives and score as you desire
// Randomize the pot picture
}
}
update_game_info();
</script>
答案 1 :(得分:0)
您可以添加一个功能:refreshGame,如下所示:
for outer_key, outer_val in FeatureDict.items():
if outer_val['ID'] in mypkt.Text:
for inner_key, inner_val in outer_val:
if inner_key.startswith('AreaOfInterest') and inner_val in mypkt.Text:
print found
break
并在每个clickMeIDFunctionX函数之后调用此函数,如下所示:
function refreshGame(){
for(var i = 1 ; i<=3 ; i++){
document.getElementById('pot'+i).src="imageedit_2_3920956067.gif";
}
}
不确定我的编辑因为我没有运行它,它们可能是一些语法错误,但这就是全球性的想法。 希望能帮到你