Accueil > > > MORPION A DEUX (SUR LE MÊME ORDI)
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 de la même categorie
Commentaires et avis
|
Derniers Blogs
SLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPSSLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPS par Vko
Retrouvez les slides et les démo de ma session Fast & Furious XAML Apps. A ceux qui se posent la question : "est-ce que le code de la DataGrid est disponible?", je vous répondrais "pas encore". Je vais mettre en place un projet codeplex pour part...
Cliquez pour lire la suite de l'article par Vko XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|