我編碼一個遊戲,在你死後我想對文本的特定遊戲,根據使用innerHTLM比分顯示和遊戲JavaScript變量的if/else如果與innerHTML的工作不
我跟着一些但它似乎並不奏效,也不知道爲什麼。
下面的代碼:
<div id="game-over">
<h3><font color="orange">Tu as courus <span id="score"></span> mètres.</font></h3>
<font color="orange"><h1 id="customegotext">Error text not found</h1></font>
<a href="javascript:void(0)" class="button restart">Ressayer ?</a>
</div>
</div>
<script>
var scoretext;
if ("score" < 45) {
scoretext = "Text1";
} else if ("score" > 100) {
scoretext = "Text2";
} else if ("score" > 500) {
scoretext = "Text3";
} else if ("score" > 750) {
scoretext = "Text4";
}
document.getElementById("customegotext").innerHTML = scoretext;
</script>
更多細節:
- 變量「得分」是在index.html的(文件specifed單獨js文件calculater其中誤差存在)通過這行代碼
<script type="text/javascript" src="ljdm.js"></script>
遊戲作品完全檔案(.html,.js文件和.css正確通過相關的代碼)
我是一個初學者到編程
感謝您幫助我!
編輯:這裏是完整的遊戲代碼。
的Index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>LE JEU DES MANDARINES</title>
<link rel="stylesheet" href="ljdm.css" type="text/css" media="screen">
<script type="text/javascript" src="jquery.2.1.1.min.js"></script>
</head>
<body>
<div class="wrapper">
<div class="sound sound-off"></div>
<div id="menu">
<div id="progress">
<div id="percent">Téléchargement: <span id="p"></span></div>
<progress id="progress-bar" value="0"></progress>
</div>
<div id="main">
<h1>LE JEU DES MANDARINES</h1>
<ul>
<li><a href="javascript:void(0)" class="button play">JOUER</a></li>
<li><a href="javascript:void(0)" class="button credits">Les Credits</a></li>
<li><a href="javascript:void(0)" class="button howto">Comment Jouer</a></li>
</ul>
</div>
<div id="credits">
<ul>
<li class="maincredits">Inspiration Première/Vidéo des Mandarines/Notre Maître a tous : <a href="https://www.youtube.com/user/legrandjd" target="_blank">LeGrandJD</a></li>
<li class="maincredits">Chef de projet/Idée du Jeu : <a href="https://twitter.com/k0spwn/" target="_blank">k0spwn</a></li>
<li class="maincredits">Graphiste : <a href="https://twitter.com/seveko00" target="_blank">Seko00</a></li>
</ul>
<ul>
<li class="artwork">Inspiration Première/Vidéo des Mandarines/Notre Maître a tous : <a href="https://www.youtube.com/user/legrandjd" target="_blank">LeGrandJD</a></li>
<li class="artwork">Character design and art: <a href="https://www.youtube.com/user/legrandjd">LeGrandJD (Julien Donzé)</a></li>
<li class="artwork">Animation du personnage : Seko00</li>
<li class="artwork">Les Plateformes: Seko00</li>
</ul>
<ul>
<li class="music">La Musique: <a href="https://www.youtube.com/watch?v=aHrc_F8xMXE" target="_blank">LeGrandJD (Julien Donzé)</a></li>
<li class="music">Jump sound effect: <a href="http://opengameart.org/content/platformer-jumping-sounds" target="_blank">dklon</a></li>
<li class="music">Game over music: <a href="https://twitter.com/k0spwn/" target="_blank">k0spwn</a></li>
</ul>
<ul>
<li class="developer">Developeurs : <a href="https://twitter.com/k0spwn/" target="_blank">k0spwn</a> et <a href="https://twitter.com/seveko00" target="_blank">Seko00</a></li>
<li class="developer">Developeur de la base Javascript/CSS : <a href="http://blog.sklambert.com/" target="_blank">Steven Lambert</a></li>
</ul>
<li class="addcredits">Remerciements : <br>- Etienne LAZURE <br>- Jimmy VALECILLOS <br>- Paul ALEXANDROPOULOS <br>- LeGrandJD (Evidemment) <br>- La 11VP2 (Pour nous avoir laissez travaillé en paix)</li>
<ul>
</ul>
<a href="javascript:void(0)" class="button back">Retour au jeu</a>
</div>
<div id="howto">
<ul>
<h2><font color="blue">Réfere toi a ce magnifique dessin pour apprendre a jouer:</font><h2>
</ul>
<a href="javascript:void(0)" class="button back">Retour au jeu</a>
</div>
</div>
<canvas id="canvas" width="800" height="480">
<p>Ton naviguateur Internet n'a pas les fonctionnalitée requise pour jouer a ce jeu</p>
<p>Veuillez télécharger un naviguateur plus récent comme <a href="www.google.com/chrome/">Google Chrome</a> pour pouvoir jouer</p>
</canvas>
<div id="game-over">
<h3><font color="orange">Tu as courus <span id="score"></span> mètres.</font></h3>
<font color="orange"><h1 id="customegotext">Error text not found</h1></font>
<a href="javascript:void(0)" class="button restart">Ressayer ?</a>
</div>
</div>
<script>
var scoretext;
if (score > 0) {
scoretext = "Text1";
}
if (score > 45) {
scoretext = "Text2";
}
if (score > 100) {
scoretext = "Text2";
}
if (score > 500) {
scoretext = "Text3";
}
if (score > 750) {
scoretext = "Text4";
}
document.getElementById("customegotext").innerHTML = scoretext;
</script>
<script type="text/javascript" src="ljdm.js"></script>
</body>
</html>
所有以在.js文件比分工作代碼:
function gameOver() {
stop = true;
$('#score').html(score);
$('#game-over').show();
assetLoader.sounds.bg.pause();
assetLoader.sounds.gameOver.currentTime = 0;
assetLoader.sounds.gameOver.play();
// draw the score
ctx.font = '15pt Calibri';
ctx.fillStyle = 'red';
ctx.fillText('Score: ' + score + 'm', canvas.width - 450, 50);
「分數」是字符串,「分數」是可變的。如果你有'score'作爲全局變量,你只需要刪除引號。 –