|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
MORPION A DEUX (SUR LE MÊME ORDI)
Information sur la source
Description
Un simple morpion _verifie qui a gagné _utilise un nom _sans bugs (je crois) _un tableau des scores ps je ne suit pas très doué en js alors donnez moi toues les critiques possibles pps: il faut le zip pour les images!!
Source
- <html>
-
- <head>
- <meta http-equiv="Content-Language" content="fr">
- <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
- <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
- <meta name="ProgId" content="FrontPage.Editor.Document">
- <title>morpion</title>
- <script language="javascript">
- //de rrk275
- //à ne pas supprimer ce serait gentil ;-)
- function nom()
- {
- nomwin=0
- nomwin2=0
- nom3 = ""
- nom4 = (Math.random() * 3)
- nom = prompt("donnez le nom du 1er joueur", "")
- nom2=prompt("donnez le nom du 2eme joueur", "")
- if (nom=="deblog")
- {nom = 1;
- nom2 = 2;}
- else
- {
- while(nom==nom2)
- {
- alert("donnez 2 noms différents")
- nom = prompt("donnez le nom du 1er joueur", "")
- nom2 = prompt("donnez le nom du 2eme joueur", "")
- }
- }
- decla()
- }
- function decla()
- {
- mptour = 0;
- i = 0;
- mp13 = 0;
- mp14 = 0;
- mp15 = 0;
- test = 0;
- mp16 = 0;
- mp17 = 0;
- mp10 = 0;
- mp11 = 0;
- mp12 = new Array (8);
- verf = new Array (10);
- for(i=0; i<11; i++)
- {verf[i]=0}
- mp1 = 10;
- mp4 = new Array (8);
- for(i=0; i<9; i++)
- {mp4[i]=0}
- var iw = 0;
- var iw2d = 0;
- place = new Array(2);
- for(i=0; i<3; i++)
- {
- place[i] = new Array (2);
- for(iv=0; iv<3; iv++)
- {place[i][iv]=0}
- }
- }
- function mp(mp2)
- {
- if(test==0)
- {
- if (mp2=="b1" && mp4[0]<1 )
- {start('b1','0','0')
- mp4[0] = 1}
- if (mp2=="b2" && mp4[1]<1 )
- {start('b2', '0', '1')
- mp4[1] = 1}
- if (mp2=="b3" && mp4[2]<1 )
- {start('b3', '0', '2')
- mp4[2] = 1}
- if (mp2=="b4" && mp4[3]<1 )
- {start('b4', '1', '0')
- mp4[3] = 1}
- if (mp2=="b5" && mp4[4]<1 )
- {start('b5', '1', '1')
- mp4[4] = 1}
- if (mp2=="b6" && mp4[5]<1 )
- {start('b6', '1', '2')
- mp4[5] = 1}
- if (mp2=="b7" && mp4[6]<1 )
- {start('b7', '2', '0')
- mp4[6] = 1}
- if (mp2=="b8" && mp4[7]<1 )
- {start('b8', '2', '1')
- mp4[7] = 1}
- if (mp2=="b9" && mp4[8]<1 )
- {start('b9', '2', '2')
- mp4[8] = 1}
- }
- }
- function start(mp2, mp10, mp11)
- {if (mp1==1)
- {mp1 = 10;}
- else{mp1 = 1}
- if (mp1==1){mp3 = "<img src='boutonj.jpg' width=120 height=120>"}
- else{mp3 = "<img src='boutonr.jpg' width=120 height=120>"};
- document.getElementById(mp2).innerHTML = mp3;
- mptour++
- ajout(mp10, mp11, mp1);
- }
- function ajout(mp10, mp11, mp1)
- {
- place[mp10][mp11]= mp1;
- for(i=0; i<3; i++)
- {
- mp13 = place[mp10][i];
- mp14 = mp13 + mp14
- }
- der(mp14)
- mp14 = 0;
- if(test=="0")
- {
- for(i=0; i<3; i++)
- {
- mp13 = place[i][mp11];
- mp14 = mp13 + mp14
- }
- der(mp14)
- mp14 = 0;
- if(test=="0")
- {
- mp15 = place[0][0];
- mp16 = place[1][1];
- mp17 = place[2][2];
- mp14 = mp15+mp16+mp17
- der(mp14)
- mp14 = 0;
- if(test=="0")
- {
- mp15 = place[0][2];
- mp16 = place[1][1];
- mp17 = place[2][0];
- mp14 = mp15+mp16+mp17
- der(mp14)
- mp14 = 0;
- }
- }
- }
- }
- function der(mp)
- {
- mp3 = "";
- if(mp==30)
- {test = 1;
- mp3 = '<u><b>' + nom2 + ' a gagné</b></u>';
- nomwin2++;
- nwm2="score de " + nom2 +": " + nomwin2;
- document.getElementById('nw2').innerHTML =nwm2;}
- if(mp==3)
- {
- test = 1;
- mp3 = '<u><b>' + nom + ' a gagné</b></u>';
- nomwin++;
- nwm="score de " + nom + ": "+ nomwin;
- document.getElementById('nw').innerHTML =nwm;}
- if(test==1 || mptour==9)
- {
- document.getElementById("dc").innerHTML = mp3;
- document.getElementById("new").innerHTML ="<input type=button value=relancer onClick='le_relanceur()'>";
- }
- }
- function le_relanceur()
- {
- for(i=1; i<10; i++)
- {
- mp12[i]="b"+i
- }
- for(i=1; i<10; i++)
- {document.getElementById(mp12[i]).innerHTML =" ";}
- document.getElementById("dc").innerHTML =" ";
- decla()
- document.getElementById("new").innerHTML ="";
- }
- </script>
- </head>
- <body
- onLoad=
- "nom()"
- onLoad=
- "music()">
- <div id=vs></div>
- <div id="son"></div>
- <table border="2" width="450" height="450">
- <tr>
- <a onClick="mp('b1')"><td width="150" height="150"><div id="b1"> </div></td></a>
- <a onClick="mp('b2')"><td width="150" height="150"><div id="b2"> </div></td></a>
- <a onClick="mp('b3')"><td width="150" height="150"><div id="b3"> </div></td></a>
- </tr>
- <tr>
- <a onClick="mp('b4')"><td width="150" height="150"><div id="b4"> </div></td></a>
- <a onClick="mp('b5')"><td width="150" height="150"><div id="b5"> </div></td></a>
- <a onClick="mp('b6')"><td width="150" height="150"><div id="b6"> </div></td></a>
- </tr>
- <tr>
- <a onClick="mp('b7')"><td width="150" height="150"><div id="b7"> </div></td></a>
- <a onClick="mp('b8')"><td width="150" height="150"><div id="b8"> </div></td></a>
- <a onClick="mp('b9')"><td width="150" height="150"><div id="b9"> </div></td></a>
- </tr>
- </table>
- <table border="2" width="450" height="40" align="left">
- <tr>
- <td width="450" height="40"><div id="dc"> </div></td>
- </tr>
- </table><p><br><br></p>
- <p>
- <br>
- <div id=new></div>
- <div id=nw></div>
- <div id=nw2></div>
-
-
-
-
- </body>
- </html>
<html>
<head>
<meta http-equiv="Content-Language" content="fr">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>morpion</title>
<script language="javascript">
//de rrk275
//à ne pas supprimer ce serait gentil ;-)
function nom()
{
nomwin=0
nomwin2=0
nom3 = ""
nom4 = (Math.random() * 3)
nom = prompt("donnez le nom du 1er joueur", "")
nom2=prompt("donnez le nom du 2eme joueur", "")
if (nom=="deblog")
{nom = 1;
nom2 = 2;}
else
{
while(nom==nom2)
{
alert("donnez 2 noms différents")
nom = prompt("donnez le nom du 1er joueur", "")
nom2 = prompt("donnez le nom du 2eme joueur", "")
}
}
decla()
}
function decla()
{
mptour = 0;
i = 0;
mp13 = 0;
mp14 = 0;
mp15 = 0;
test = 0;
mp16 = 0;
mp17 = 0;
mp10 = 0;
mp11 = 0;
mp12 = new Array (8);
verf = new Array (10);
for(i=0; i<11; i++)
{verf[i]=0}
mp1 = 10;
mp4 = new Array (8);
for(i=0; i<9; i++)
{mp4[i]=0}
var iw = 0;
var iw2d = 0;
place = new Array(2);
for(i=0; i<3; i++)
{
place[i] = new Array (2);
for(iv=0; iv<3; iv++)
{place[i][iv]=0}
}
}
function mp(mp2)
{
if(test==0)
{
if (mp2=="b1" && mp4[0]<1 )
{start('b1','0','0')
mp4[0] = 1}
if (mp2=="b2" && mp4[1]<1 )
{start('b2', '0', '1')
mp4[1] = 1}
if (mp2=="b3" && mp4[2]<1 )
{start('b3', '0', '2')
mp4[2] = 1}
if (mp2=="b4" && mp4[3]<1 )
{start('b4', '1', '0')
mp4[3] = 1}
if (mp2=="b5" && mp4[4]<1 )
{start('b5', '1', '1')
mp4[4] = 1}
if (mp2=="b6" && mp4[5]<1 )
{start('b6', '1', '2')
mp4[5] = 1}
if (mp2=="b7" && mp4[6]<1 )
{start('b7', '2', '0')
mp4[6] = 1}
if (mp2=="b8" && mp4[7]<1 )
{start('b8', '2', '1')
mp4[7] = 1}
if (mp2=="b9" && mp4[8]<1 )
{start('b9', '2', '2')
mp4[8] = 1}
}
}
function start(mp2, mp10, mp11)
{if (mp1==1)
{mp1 = 10;}
else{mp1 = 1}
if (mp1==1){mp3 = "<img src='boutonj.jpg' width=120 height=120>"}
else{mp3 = "<img src='boutonr.jpg' width=120 height=120>"};
document.getElementById(mp2).innerHTML = mp3;
mptour++
ajout(mp10, mp11, mp1);
}
function ajout(mp10, mp11, mp1)
{
place[mp10][mp11]= mp1;
for(i=0; i<3; i++)
{
mp13 = place[mp10][i];
mp14 = mp13 + mp14
}
der(mp14)
mp14 = 0;
if(test=="0")
{
for(i=0; i<3; i++)
{
mp13 = place[i][mp11];
mp14 = mp13 + mp14
}
der(mp14)
mp14 = 0;
if(test=="0")
{
mp15 = place[0][0];
mp16 = place[1][1];
mp17 = place[2][2];
mp14 = mp15+mp16+mp17
der(mp14)
mp14 = 0;
if(test=="0")
{
mp15 = place[0][2];
mp16 = place[1][1];
mp17 = place[2][0];
mp14 = mp15+mp16+mp17
der(mp14)
mp14 = 0;
}
}
}
}
function der(mp)
{
mp3 = "";
if(mp==30)
{test = 1;
mp3 = '<u><b>' + nom2 + ' a gagné</b></u>';
nomwin2++;
nwm2="score de " + nom2 +": " + nomwin2;
document.getElementById('nw2').innerHTML =nwm2;}
if(mp==3)
{
test = 1;
mp3 = '<u><b>' + nom + ' a gagné</b></u>';
nomwin++;
nwm="score de " + nom + ": "+ nomwin;
document.getElementById('nw').innerHTML =nwm;}
if(test==1 || mptour==9)
{
document.getElementById("dc").innerHTML = mp3;
document.getElementById("new").innerHTML ="<input type=button value=relancer onClick='le_relanceur()'>";
}
}
function le_relanceur()
{
for(i=1; i<10; i++)
{
mp12[i]="b"+i
}
for(i=1; i<10; i++)
{document.getElementById(mp12[i]).innerHTML =" ";}
document.getElementById("dc").innerHTML =" ";
decla()
document.getElementById("new").innerHTML ="";
}
</script>
</head>
<body
onLoad=
"nom()"
onLoad=
"music()">
<div id=vs></div>
<div id="son"></div>
<table border="2" width="450" height="450">
<tr>
<a onClick="mp('b1')"><td width="150" height="150"><div id="b1"> </div></td></a>
<a onClick="mp('b2')"><td width="150" height="150"><div id="b2"> </div></td></a>
<a onClick="mp('b3')"><td width="150" height="150"><div id="b3"> </div></td></a>
</tr>
<tr>
<a onClick="mp('b4')"><td width="150" height="150"><div id="b4"> </div></td></a>
<a onClick="mp('b5')"><td width="150" height="150"><div id="b5"> </div></td></a>
<a onClick="mp('b6')"><td width="150" height="150"><div id="b6"> </div></td></a>
</tr>
<tr>
<a onClick="mp('b7')"><td width="150" height="150"><div id="b7"> </div></td></a>
<a onClick="mp('b8')"><td width="150" height="150"><div id="b8"> </div></td></a>
<a onClick="mp('b9')"><td width="150" height="150"><div id="b9"> </div></td></a>
</tr>
</table>
<table border="2" width="450" height="40" align="left">
<tr>
<td width="450" height="40"><div id="dc"> </div></td>
</tr>
</table><p><br><br></p>
<p>
<br>
<div id=new></div>
<div id=nw></div>
<div id=nw2></div>
</body>
</html>
Conclusion
explication par fonction nom() : forme les variables qui durent tout au long de la partie decla(): declare les variables de la partie mp(mp2):verification que l'on n'a pas deja effectuer ce coup mp2 est la case ,c'est aussi le nom du div start(mp2, mp10, mp11): mp10 et mp11 sont juste transféré et mp1 est pour connaitre le joueur mptour est le compteur de tours il sert au matchs nuls ajout(mp10,mp11,mp1): entre les valeurs dans place avec mp1 qui vaut 1 ou 10 selon le joueur envoie a la fonction der la verification der(): s'osccupe de verifier si on a gagné ou pas et effectue en fonction de cela ce qu'il faut le_relanceur s'occupe de relancer le jeu si besoin est.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Comparez les prix Nouvelle version
|