[Résolu]-[javascript] mon jeu de runes marche pas...
Dernière réponse : dans Programmation
Salut, autant le dire tout de suite je suis vraiment débutante en javascript, d'ailleurs il y a 48h je ne savais pas ce qu'était le javascript... En mettant bout à bout des morceaux de codes plus moins trouvés sur internet, j'ai réussit à faire quelquechose, mais ça marche pas tout à fait. Ce que je veux faire est simple, il s'agit d'un jeu de runes divinatoires qui repose uniquement sur la fonction math.random. Le jeu est fait comme ceci, une première page où se trouve 25 fois copiée la meme image (représentant une rune animée en .gif), lorsqu'on clique sur n'importe la quelle des runes affichées, ça lance math.random de 1 à 25, à chaque nombre trouvé par la fonction est affilié une page (html ou php) qui contient une rune spécifique ainsi que son interprétation divinatoire. Bon pour cette partie ça fonctionne bien, le problème c'est que math.random se lance également lorsqu'on actualise la page, ou même simplement quand elle se charge pour la première fois, ce qui fait que le joueur n'a pas le temps de cliquer sur une rune, que math.random à déjà sélectionné et redirigé vers une interprétation au hasard. En fait cette fonction est activée par 2 trucs différents n°1 le clic sur une rune, n°2 le chargement de la page. Ce que je voudrais faire c'est empécher qu'elle s'éxécute dans la solution n°2, et que seul le clic sur une rune la lance. Je met le code ci-dessous, croyez-vous qu'il y a un moyen ?
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function nb_aleatoire(nb)
{
nombre= Math.floor(Math.random() * nb)+1;
}
//-->
</script>
<script language="JavaScript">
<!--
nb_aleatoire(25)
if (nombre==1) location.replace(href="runes/tir1rune.php")
if (nombre==2) location.replace(href="runes/tir1rune2.php")
if (nombre==3) location.replace(href="runes/tir1rune3.php")
if (nombre==4) location.replace(href="runes/tir1rune4.php")
if (nombre==5) location.replace(href="runes/tir1rune5.php")
if (nombre==6) location.replace(href="runes/tir1rune6.php")
if (nombre==7) location.replace(href="runes/tir1rune7.php")
if (nombre==8) location.replace(href="runes/tir1rune8.php")
if (nombre==9) location.replace(href="runes/tir1rune9.php")
if (nombre==10) location.replace(href="runes/tir1rune10.php")
if (nombre==11) location.replace(href="runes/tir1rune11.php")
if (nombre==12) location.replace(href="runes/tir1rune12.php")
if (nombre==13) location.replace(href="runes/tir1rune13.php")
if (nombre==14) location.replace(href="runes/tir1rune14.php")
if (nombre==15) location.replace(href="runes/tir1rune15.php")
if (nombre==16) location.replace(href="runes/tir1rune16.php")
if (nombre==17) location.replace(href="runes/tir1rune17.php")
if (nombre==18) location.replace(href="runes/tir1rune18.php")
if (nombre==19) location.replace(href="runes/tir1rune19.php")
if (nombre==20) location.replace(href="runes/tir1rune20.php")
if (nombre==21) location.replace(href="runes/tir1rune21.php")
if (nombre==22) location.replace(href="runes/tir1rune22.php")
if (nombre==23) location.replace(href="runes/tir1rune23.php")
if (nombre==24) location.replace(href="runes/tir1rune24.php")
if (nombre==25) location.replace(href="runes/tir1rune25.php")
//-->
</script>
<style type="text/css">
<!--
body {
background-color: #000000;
}
-->
</style></head>
<body>
<FORM>
<div align="center">
<p> </p>
<p> </p>
<p>
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
</p>
<p>
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
</p>
<p>
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
</p>
<p>
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
</p>
</div>
</FORM>
</body>
</html>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function nb_aleatoire(nb)
{
nombre= Math.floor(Math.random() * nb)+1;
}
//-->
</script>
<script language="JavaScript">
<!--
nb_aleatoire(25)
if (nombre==1) location.replace(href="runes/tir1rune.php")
if (nombre==2) location.replace(href="runes/tir1rune2.php")
if (nombre==3) location.replace(href="runes/tir1rune3.php")
if (nombre==4) location.replace(href="runes/tir1rune4.php")
if (nombre==5) location.replace(href="runes/tir1rune5.php")
if (nombre==6) location.replace(href="runes/tir1rune6.php")
if (nombre==7) location.replace(href="runes/tir1rune7.php")
if (nombre==8) location.replace(href="runes/tir1rune8.php")
if (nombre==9) location.replace(href="runes/tir1rune9.php")
if (nombre==10) location.replace(href="runes/tir1rune10.php")
if (nombre==11) location.replace(href="runes/tir1rune11.php")
if (nombre==12) location.replace(href="runes/tir1rune12.php")
if (nombre==13) location.replace(href="runes/tir1rune13.php")
if (nombre==14) location.replace(href="runes/tir1rune14.php")
if (nombre==15) location.replace(href="runes/tir1rune15.php")
if (nombre==16) location.replace(href="runes/tir1rune16.php")
if (nombre==17) location.replace(href="runes/tir1rune17.php")
if (nombre==18) location.replace(href="runes/tir1rune18.php")
if (nombre==19) location.replace(href="runes/tir1rune19.php")
if (nombre==20) location.replace(href="runes/tir1rune20.php")
if (nombre==21) location.replace(href="runes/tir1rune21.php")
if (nombre==22) location.replace(href="runes/tir1rune22.php")
if (nombre==23) location.replace(href="runes/tir1rune23.php")
if (nombre==24) location.replace(href="runes/tir1rune24.php")
if (nombre==25) location.replace(href="runes/tir1rune25.php")
//-->
</script>
<style type="text/css">
<!--
body {
background-color: #000000;
}
-->
</style></head>
<body>
<FORM>
<div align="center">
<p> </p>
<p> </p>
<p>
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
</p>
<p>
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
</p>
<p>
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
</p>
<p>
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
<input type="image" src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire(nb)">
</p>
</div>
</FORM>
</body>
</html>
Autres pages sur : resolu javascript jeu runes marche
Lassé par la pub ? Créez un compte
au temps pour moi, j'ai fait une bétise
modifies ta function ainsi:
et remplace tes appels à la fonction par:
ONCLICK="nb_aleatoire()"
En effet, comme tu déclares au début que nb=25, il est inutile de le transmettre, il est normalement pris en compte directement dans ta fonction.
Mais si je puis me permettre, ton script est bien pour quelqu'un qui débute mais peut être très améliorer, je te le refais dans 5 minutes (avec les explications)
modifies ta function ainsi:
<script language="JavaScript">
<!--
function nb_aleatoire()
{
nombre= Math.floor(Math.random() * nb)+1;
}
//-->
</script>
et remplace tes appels à la fonction par:
ONCLICK="nb_aleatoire()"
En effet, comme tu déclares au début que nb=25, il est inutile de le transmettre, il est normalement pris en compte directement dans ta fonction.
Mais si je puis me permettre, ton script est bien pour quelqu'un qui débute mais peut être très améliorer, je te le refais dans 5 minutes (avec les explications)
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
var nb = 25; // On définit le nombre de runes
function nb_aleatoire() {
nombre= Math.floor(Math.random() * nb)+1; // tirage d'une rune aléatoire
url = "runes/tir1rune"+nombre+".php"; // on crée l'url
location.replace(href=url); // on redirige sur l'url
}
//-->
</script>
<style type="text/css">
<!--
body {
background-color: #000000;
}
-->
</style>
</head>
<body>
<div align="center">
<!-- Pas la peine d'un formulaire -->
<p>
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<!-- on peut mettre le onclick sur une image directement -->
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
</p>
<p>
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
</p>
<p>
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
</p>
<p>
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
<img src="Runes/minirune1.gif" width="51" height="71" border="0" ONCLICK="nb_aleatoire();">
</p>
</div>
</body>
</html>
Voila, c'est plus simple et plus propre, n'hésite pas à poser tes questions
Lassé par la pub ? Créez un compte
- Contenus similaires :
Tags :
- ForumMon jeu marche au ralenti
- ForumJeu ne marche pas
- ForumJeu monopoly marche pas
- articlesJeu ne marche pas sur windows 7
- ForumJeu facebook qui ne marche pas
- ForumMon jeu de sims ne marche pas
- ForumJeu ne marche pas sous windows 7
- ForumJeu ps2 marche sur ps3
- ForumComment marche un jeu telecharger
- ForumMon jeu flyff ne marche pas
- Voir plus