Amélioration d'un pendu

Amélioration d'un pendu - Javascript/Node.js - Programmation

Marsh Posté le 27-05-2015 à 20:19:41    

Bonjour , Merci d’abord de lire ce sujet .
Pendant plusieurs cours d'ISN notre groupe a progressé dans un pendu ( dont le professeur nous avait donner la base )  
Mais notre professeur nous a alors demander de faire :  un tableau et que les lettres sur lesquels  le joueur a cliqué s'affichent dedans à la place d'un changement de couleur mais j'ai alors rencontré des problèmes . Je ne trouve aucun moyen d'afficher les lettres dans le tableau que j'ai crée ( notre  professeur nous a demander de supprimer le changement de couleur )  
 
Voici le code source :  
 

Code :
  1. <html>
  2. <head>
  3.     <meta charset=UTF-8>
  4.  <title>Jeu de pendu en Javascipt</title>
  5.  <link rel=Stylesheet type="text/css" href=stylePendu.css>
  6.  <script language="JavaScript">
  7.   <!--
  8.    var motSecret;
  9.    var now=new Date();   // Date d'aujourd'hui
  10.    var tableauMot=new Array(); // Le tableau qui contient les lettres du mot à trouver
  11.    var mots=new Array();  // Le tableau qui contient tous les mots possibles
  12.    var tailleMot;    // Le nombre de lettres du mot à trouver
  13.    var coupsManques=0;   // Le nombre de lettres fausses essayées
  14.    var lettresTrouvees=0;  // Le nombre de lettres trouvées
  15.    var fini=false;    // true si le jeu est terminé
  16.    mots[0]="CONSOLE";
  17.    mots[1]="MANETTE";
  18.    mots[2]="POLICIER";
  19.    mots[3]="CANAPE";
  20.    mots[4]="TELEVISION";
  21.    mots[5]="GLADIATEUR";
  22.    mots[6]="ARMOIRE";
  23.    mots[7]="CAMION";
  24.    mots[8]="HORLOGE";
  25.    mots[9]="MARGUERITE";
  26.    mots[10]="ELEPHANT";
  27.    mots[11]="IGLOO";
  28.    mots[12]="SINGE";
  29.    motSecret=mots[Math.floor(Math.random() * 13)];
  30.    tailleMot=motSecret.length;
  31.    // Permet de changer la couleur des touches du clavier
  32.    function changeCouleur(element,couleur){
  33.     element.style.backgroundColor=couleur;
  34.    }
  35.    // Gère tous les traitements à faire lorsqu'on appuie sur une touche
  36.    function proposer(element){
  37.     if(element.style.backgroundColor=="black" ||fini) return;
  38.     var lettre=element.innerHTML;
  39.     // On met la variable trouve à false;
  40.     var trouve=false;
  41.     // On parcours chaque lettre du mot, on cherche si on trouve la lettre séléectionnée au clavier
  42.     for(var i=0; i<tailleMot; i++) {
  43.      // Si c'est le cas :
  44.      if(tableauMot[i].innerHTML==lettre) {
  45.       tableauMot[i].style.visibility='visible'; // On affiche la lettre
  46.       trouve=true;
  47.       lettresTrouvees++;
  48.      }
  49.     }
  50.     // Si la lettre n'est pas présente, trouvé vaut toujours false :
  51.     if(!trouve){
  52.      coupsManques++;
  53.      document.images['pendu'].src="images/pendu_"+coupsManques+".jpg"; // On change l'image du pendu
  54.      // Si on a raté 9 fois :
  55.      if(coupsManques==9){
  56.       alert("Dommage mec ! tu es nul  !" );
  57.       for(var i=0; i<tailleMot; i++) tableauMot[i].style.visibility='visible';
  58.       fini=true;
  59.       // on affiche le mot, on fini le jeu
  60.      }
  61.     }
  62.     if(lettresTrouvees==tailleMot){
  63.      alert("Bravo ! T'es trop un bonhomme !" );
  64.      fini=true;
  65.     }
  66.    }
  67.   -->
  68.  </script>
  69. </head>
  70. <body>
  71. <center>
  72. <div id="page">
  73. <img name="pendu" class="pendu" src="images/pendu_0.jpg">
  74. <h1>Jeu de pendu</h1>
  75. <h2>Entrez une lettre grâce au clavier ci-dessous ; si elle est dans le mot secret, elle sera affichée mais sinon... la sentence se rapprochera !</h2>
  76. <table id="clavier">
  77.  <tr>
  78.   <td onclick="proposer(this);" >A</td>
  79.   <td onclick="proposer(this);" >B</td>
  80.   <td onclick="proposer(this);" >C</td>
  81.   <td onclick="proposer(this);" >D</td>
  82.   <td onclick="proposer(this);" >E</td>
  83.   <td onclick="proposer(this);" >F</td>
  84.   <td onclick="proposer(this);" >G</td>
  85.   <td onclick="proposer(this);" >H</td>
  86.   <td onclick="proposer(this);" >I</td>
  87.   <td onclick="proposer(this);" >J</td>
  88.  </tr>
  89.  <tr>
  90.   <td onclick="proposer(this);" >K</td>
  91.   <td onclick="proposer(this);" >L</td>
  92.   <td onclick="proposer(this);" >M</td>
  93.   <td onclick="proposer(this);" >N</td>
  94.   <td onclick="proposer(this);" >O</td>
  95.   <td onclick="proposer(this);" >P</td>
  96.   <td onclick="proposer(this);" >Q</td>
  97.   <td onclick="proposer(this);" >R</td>
  98.   <td onclick="proposer(this);" >S</td>
  99.   <td onclick="proposer(this);" >T</td>
  100.  </tr>
  101.  <tr>
  102.   <td onclick="proposer(this);" >U</td>
  103.   <td onclick="proposer(this);" >V</td>
  104.   <td onclick="proposer(this);" >W</td>
  105.   <td onclick="proposer(this);" >X</td>
  106.   <td onclick="proposer(this);" >Y</td>
  107.   <td onclick="proposer(this);" >Z</td>
  108.  </tr>
  109. </table>
  110. <br>
  111. <a class="lien" href="javascript:location.reload();">Nouvelle partie</a>
  112. <table id="mot">
  113.  <tr>
  114.   <script language="javascript">
  115.    for(var i=0; i<tailleMot; i++) document.write("<td> <p id=\""+i+"\">"+motSecret.charAt(i)+"</p></td>" );
  116.   </script>
  117.  </tr>
  118. </table>
  119. </table>
  120.  <table border="1" style="border: medium solid #FFFF00">
  121.   <caption><h2>Lettres utilisés</h2></caption>
  122.   <tr>
  123.       <th width=150 height=50></th>
  124.    <td> </td>
  125.   </tr>
  126.   </tr>
  127.  </table>
  128. <script language="javascript">
  129.  for(var i=0; i<tailleMot; i++) tableauMot[i]=document.getElementById(i);
  130. </script>
  131. <center>
  132. </div>
  133. </body>
  134. </html>


 
le css ( on sait jamais) :

Code :
  1. #page {
  2. background-color:#0040FF;
  3. border:1px solid black;
  4. text-align:left;
  5. width:60%;
  6. padding:30px;
  7. height:450px;
  8. }
  9. h1 {
  10. font-size:30px;
  11. font-family:Arial, sans serif;
  12. }
  13. img.pendu {
  14. float:right;
  15. }
  16. h2 {
  17. font-size:16px;
  18. font-family:Arial, sans-serif;
  19. }
  20. #mot {
  21. margin:30px 0 0 0;
  22. clear:both;
  23. top:100px;
  24. }
  25. #mot td {
  26. padding:10px;
  27. background-color:#2EFE2E;
  28. border:2px inset black;
  29. width:30px;
  30. height:30px;
  31. font-weight:bold;
  32. font-size:1.5em;
  33. text-align:center;
  34. }
  35. #mot p{
  36. visibility:hidden;
  37. }
  38. #clavier{
  39. border:5px outset black;
  40. padding:20px;
  41. background-color:#8A0808;
  42. }
  43. #clavier td {
  44. background-color:Blue;
  45. border:2px solid black;
  46. width:35px;
  47. height:25px;
  48. text-align:center;
  49. font-weight:bold;
  50. cursor:pointer;
  51. }
  52. a.lien{
  53. color:Red;
  54. text-decoration:none;
  55. font-size:30px;
  56. }
  57. a.lien:hover{
  58. color:green;
  59. font-weight:bold;
  60. text-decoration:underline;
  61. }


 
Voila en espérant une aide précieuse pour le tableau =) ( si possible avant vendredi )


Message édité par sharto le 28-05-2015 à 16:30:41
Reply

Marsh Posté le 27-05-2015 à 20:19:41   

Reply

Marsh Posté le 27-05-2015 à 22:42:59    

> script language="JavaScript"
 
Donc ça fait quoi dans la section Java?
 
A+,


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
Reply

Marsh Posté le 27-05-2015 à 23:22:48    

Désolé de l'erreur c'est réparé la section est la bonne je pense A + =)

Reply

Marsh Posté le 28-05-2015 à 11:05:52    

J'aurais mis ça en Javascript, mais pourquoi pas...
A+,


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed