Bien avant de concevoir des jeux d'arcades, des Pac-Man, Tetris et des City of Heroes, il faut savoir programmer des jeux simples et que tous le monde comprennent parfaitement. Un de ceux-ci est sans nulle doute le jeux de Mot Mystère dans lequel il faut trouvé dans une grille une liste de mots pour enfin trouver des lettres éparpillé correspondant au mot mystère. Voici de quoi devrait avoir l'air de Mot Mystère :
A l'aide du code source JavaScript suivant, vous trouverez la réponse que vous souhaitez :
- <HTML>
- <BODY>
- <script type="text/javascript" language="javascript">
- var HiddenX = new Array();
- var HiddenY = new Array();
- var HiddenI = 0;
- var MaGrille = new Array();
- var MaGrilleX = new Array();
- var MaGrilleY = new Array();
- var MaGrilleOk = new Array();
- var MaGrilleI = 0;
- var MaGrilleFinish = false;
- var MotCacheGrille = "";
- var NumberToChar = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
- "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
- "U", "V", "W", "X", "Y", "Z", "AA","AB","AC","AD");
-
- document.write("<TABLE><TR><TD VALIGN=TOP>");
- document.write("<TABLE>");
- for(J = 0;J < 31;J++) {
- document.write("<TR>");
- for(I = 0;I < 31;I++) {
- document.write("<TD ID=T",NumberToChar[I],J,"></TD>");
- }
- document.write("</TR>");
- }
- document.write("</TABLE>");
- document.write("<SPAN ID=CurrWord></SPAN><BR>");
- document.write("<INPUT TYPE=BUTTON VALUE='Effacer' ONCLICK='document.getElementById(\"CurrWord\").innerHTML=\"\";HiddenI=0;RefreshBoard();'>");
- document.write("<SPAN ID=StatusString></SPAN><BR>");
- document.write("</TD><TD>");
- document.write("<SPAN ID=WordString></SPAN><BR>");
- document.write("</TD></TR></TABLE>");
-
- function PutButton(X,Y,Valeur,Color) {
- document.getElementById("T"+NumberToChar[MaGrilleX[Y][X]-1]+(MaGrilleY[Y][X])).innerHTML="<INPUT TYPE=BUTTON ID="+"I"+NumberToChar[MaGrilleX[Y][X]-1]+(MaGrilleY[Y][X])+" VALUE='"+Valeur+"' "+(Color!=""?"STYLE='background-color : "+Color+"'":"")+" ONCLICK='CheckGrille("+(MaGrilleX[Y][X])+","+(MaGrilleY[Y][X])+")'>";
- }
-
- function RefreshBoard() {
- for(J=0;J<MaGrilleI;J++) if(!MaGrilleOk[J]) {
- text=MaGrille[J];
- for(I=0;I<text.length;I++) PutButton(I,J,text.charAt(I),"");
- }
- for(J=0;J<MaGrilleI;J++) if(MaGrilleOk[J]) {
- text=MaGrille[J];
- for(I=0;I<text.length;I++) PutButton(I,J,text.charAt(I),"#00FF00");
- }
- }
-
- function InitGrille() {
- MaGrilleX[MaGrilleI]=new Array();
- MaGrilleY[MaGrilleI]=new Array();
- }
-
- function FinishGrille(text) {
- document.getElementById("WordString").innerHTML+="<BR>"+text;
- MaGrille[MaGrilleI]=text;
- MaGrilleOk[MaGrilleI]=false;
- MaGrilleI++;
- }
-
- function AddButton(X,Y,I,Valeur) {
- document.getElementById("T"+NumberToChar[X-1]+(Y)).innerHTML="<INPUT TYPE=BUTTON ID="+"I"+NumberToChar[X-1]+(Y)+" VALUE='"+Valeur+"' ONCLICK='CheckGrille("+(X)+","+Y+")'>";
- MaGrilleX[MaGrilleI][I]=X;
- MaGrilleY[MaGrilleI][I]=Y;
- }
-
- function AddHorizontalWord(X,Y,text) {
- InitGrille();
- for(I=0;I < text.length;I++) AddButton(X+I,Y,I,text.charAt(I));
- FinishGrille(text);
- }
-
- function AddDiagonalHorizontalWord(X,Y,text) {
- InitGrille();
- for(I = 0;I < text.length;I++) AddButton(X+I,Y-I,I,text.charAt(I));
- FinishGrille(text);
- }
-
- function AddHorizontalReverseWord(X,Y,text) {
- InitGrille();
- for(I = 0;I < text.length;I++) AddButton(X-I,Y,I,text.charAt(I));
- FinishGrille(text);
- }
-
- function AddDiagonalHorizontalReverseWord(X,Y,text) {
- InitGrille();
- for(I = 0;I < text.length;I++) AddButton(X-I,Y-I,I,text.charAt(I));
- FinishGrille(text);
- }
-
-
- function AddVerticalWord(X,Y,text) {
- InitGrille();
- for(I = 0;I < text.length;I++) AddButton(X,Y+I,I,text.charAt(I));
- FinishGrille(text);
- }
-
- function AddVerticalReverseWord(X,Y,text) {
- InitGrille();
- for(I = 0;I < text.length;I++) AddButton(X,Y-I,I,text.charAt(I));
- FinishGrille(text);
- }
-
- function AddDiagonalVerticalWord(X,Y,text) {
- InitGrille();
- for(I = 0;I < text.length;I++) AddButton(X+I,Y+I,I,text.charAt(I));
- FinishGrille(text);
- }
-
- function AddDiagonalVerticalReverseWord(X,Y,text) {
- InitGrille();
- for(I = 0;I < text.length;I++) AddButton(X-I,Y+I,I,text.charAt(I));
- FinishGrille(text);
- }
-
- function AddLetter(X,Y,text) {
- document.getElementById("T"+NumberToChar[X-1]+(Y)).innerHTML="<INPUT TYPE=BUTTON ID="+"I"+NumberToChar[X-1]+(Y)+" VALUE='"+text+"' ONCLICK='CheckGrille("+(X)+","+Y+")'>";
- }
-
- function AddChar(X,Y,Letter) {
- document.getElementById("CurrWord").innerHTML=document.getElementById("CurrWord").innerHTML+Letter;
- HiddenX[HiddenI]=X;
- HiddenY[HiddenI]=Y;
- HiddenI++;
- }
-
- function CheckGrille(X,Y) {
- CurrChar = document.getElementById("I"+NumberToChar[X-1]+Y).value;
- AddChar(X,Y,CurrChar);
- text = document.getElementById("CurrWord").innerHTML;
- if(MaGrilleFinish && (MotCacheGrille==text)) {
- document.getElementById("StatusString").innerHTML="Félicitation! Vous avez trouvé le mot caché!";
- } else {
- if(text.length>0) {
- for(J=0;J<MaGrilleI;J++) {
- Ok = true;
- for(I=0;I<text.length;I++) {
- if((HiddenX[I]!=MaGrilleX[J][I])||(HiddenY[I]!=MaGrilleY[J][I])||(text.charAt(I)!=MaGrille[J].charAt(I))) {
- Ok=false;
- break;
- }
- }
- if((text.length==MaGrille[J].length)&& Ok) {
- for(I=0;I<text.length;I++) {
- document.getElementById("T"+NumberToChar[HiddenX[I]-1]+(HiddenY[I])).innerHTML="<INPUT TYPE=BUTTON ID="+"I"+NumberToChar[HiddenX[I]-1]+(HiddenY[I])+" VALUE='"+text.charAt(I)+"' STYLE='background-color : #00FF00' ONCLICK='CheckGrille("+(HiddenX[I])+","+(HiddenY[I])+")'>";
- }
- MaGrilleOk[J]=true;
- document.getElementById("WordString").innerHTML=document.getElementById("WordString").innerHTML.replace(">"+text+"<","><S>"+text+"</S><");
- document.getElementById("CurrWord").innerHTML="";
- HiddenI=0;
- break;
- } else {
- Ok = false;
- }
- }
- } else {
- Ok = false;
- }
- if(!Ok) document.getElementById("T"+NumberToChar[X-1]+(Y)).innerHTML="<INPUT TYPE=BUTTON ID="+"I"+NumberToChar[X-1]+(Y)+" VALUE='"+CurrChar+"' STYLE='background-color : #FFFF00' ONCLICK='CheckGrille("+(X)+","+(Y)+")'>";
- else {
- Ok=true;
- DebugI=0;
- for(J=0;J<MaGrilleI;J++) {
- Ok=Ok && MaGrilleOk[J];
- if(MaGrilleOk[J]) DebugI++;
- }
- if(Ok) {
- MaGrilleFinish = true;
- document.getElementById("StatusString").innerHTML="Grille terminer! Trouver le mot caché maintenant!";
- } else {
- document.getElementById("StatusString").innerHTML=DebugI+"/"+MaGrilleI;
- }
-
- }
- }
- }
-
- function FinishAllGrille(MotCache) {
- document.getElementById("StatusString").innerHTML="0/"+MaGrilleI;
- document.getElementById("WordString").innerHTML+="<BR>";
- MotCacheGrille=MotCache;
- }
-
- AddHorizontalReverseWord(11,11,"AGE");
- AddDiagonalVerticalReverseWord(10,9,"AME");
- AddDiagonalVerticalWord(4,3,"AMI");
- AddDiagonalVerticalWord(4,5,"AMOUR");
- AddVerticalWord(10,9,"ANGE");
- AddHorizontalWord(3,11,"BIBLE");
- AddHorizontalReverseWord(3,11,"BON");
- AddVerticalReverseWord(11,12,"CATHECHESE");
- AddHorizontalWord(6,3,"CIERGE");
- AddHorizontalWord(3,2,"COEUR");
- AddHorizontalWord(3,1,"CONFIANCE");
- AddDiagonalVerticalWord(3,1,"CONSERVE");
- AddVerticalWord(8,5,"CROIRE");
- AddHorizontalWord(4,8,"DIEU");
- AddDiagonalHorizontalWord(4,8,"DIME");
- AddVerticalWord(1,2,"EGLISE");
- AddDiagonalVerticalReverseWord(11,1,"ETRE");
- AddVerticalWord(7,6,"FEU");
- AddVerticalWord(10,3,"GLOIRE");
- AddDiagonalHorizontalReverseWord(5,6,"MARIE");
- AddHorizontalWord(3,9,"MESSE");
- AddDiagonalVerticalReverseWord(5,6,"MOINE");
- AddDiagonalVerticalReverseWord(9,1,"NAISSANCE");
- AddDiagonalVerticalReverseWord(5,3,"NOEL");
- AddDiagonalHorizontalWord(1,8,"PAPA");
- AddHorizontalReverseWord(7,10,"PARDON");
- AddHorizontalReverseWord(4,12,"PRIE");
- AddHorizontalWord(4,12,"PARTAGE");
- AddDiagonalHorizontalWord(6,12,"REEL");
- AddVerticalWord(2,1,"SAINT");
- AddVerticalReverseWord(9,7,"VIE");
- FinishAllGrille("MIRACLE");
-
- AddLetter(1,1,"M");
- AddLetter(9,2,"I");
- AddLetter(3,3,"R");
- AddLetter(9,4,"A");
- AddLetter(7,4,"C");
- AddLetter(9,8,"L");
- AddLetter(11,2,"E");
- </script>
- </BODY>
- </HTML>
Dernière mise à jour : Mercredi, le 5 octobre 2011