//Code pour que le mot à trouver soit sélectionné au hasard String choisirMot () { String mot=dico[int(random(dico.length))]; println(mot); return mot; } //Code pour savoir si les lettres cliquées sont justes //en donnant aux boutons leurs actions void handleButtonEvents(GButton button, GEvent event) { if (button == E) { afficherLettre(getPositionLettre("E"), "E"); text("E", 782, 550); } if (button == A) { afficherLettre(getPositionLettre("A"), "A"); text("A", 701, 550); } if (button == B) { afficherLettre(getPositionLettre("B"), "B"); text("B", 722, 550); } if (button == C) { afficherLettre(getPositionLettre("C"), "C"); text("C", 738, 550); } if (button == D) { afficherLettre(getPositionLettre("D"), "D"); text("D", 760, 550); } if (button == F) { afficherLettre(getPositionLettre("F"), "F"); text("F", 800, 550); } if (button == G) { afficherLettre(getPositionLettre("G"), "G"); text("G", 817, 550); } if (button == H) { afficherLettre(getPositionLettre("H"), "H"); text("H", 839, 550); } if (button == I) { afficherLettre(getPositionLettre("I"), "I"); text("I", 861, 550); } if (button == J) { afficherLettre(getPositionLettre("J"), "J"); text("J", 867, 550); } if (button == K) { afficherLettre(getPositionLettre("K"), "K"); text("K", 873, 550); } if (button == L) { afficherLettre(getPositionLettre("L"), "L"); text ("L", 701, 582); } if (button == M) { afficherLettre(getPositionLettre("M"), "M"); text ("M", 720, 582); } if (button == N) { afficherLettre(getPositionLettre("N"), "N"); text("N", 745, 582); } if (button == O) { afficherLettre(getPositionLettre("O"), "O"); text("O", 767, 582); } if (button == P) { afficherLettre(getPositionLettre("P"), "P"); text("P", 790, 582); } if (button == Q) { afficherLettre(getPositionLettre("Q"), "Q"); text("Q", 807, 582); } if (button == R) { afficherLettre(getPositionLettre("R"), "R"); text("R", 831, 582); } if (button == S) { afficherLettre(getPositionLettre("S"), "S"); text("S", 851, 582); } if (button == T) { afficherLettre(getPositionLettre("T"), "T"); text("T", 869, 582); } if (button == U) { afficherLettre(getPositionLettre("U"), "U"); text("U", 701, 613); } if (button == V) { afficherLettre(getPositionLettre("V"), "V"); text("V", 723, 613); } if (button == W) { afficherLettre(getPositionLettre("W"), "W"); text("W", 748, 613); } if (button == X) { afficherLettre(getPositionLettre("X"), "X"); text("X", 776, 613); } if (button == Y) { afficherLettre(getPositionLettre("Y"), "Y"); text("Y", 797, 613); } if (button == Z) { afficherLettre(getPositionLettre("Z"), "Z"); text("Z", 819, 613); } } //Code pour avoir la position de la lettre sélectionnée ArrayList getPositionLettre(String c) { int i=0; ArrayList pos=new ArrayList(); while (i < mot.length () && i != -1) { i = mot.indexOf(c, i); if (i != -1) { pos.add(i); i++; } } return pos; } //Code pour afficher la lettre juste void afficherLettre(ArrayList pos, String c) { //si la lettre est fausse, la position ne renvoie rien. //Il faut aussi que la lettre ne soit pas cliquées 2 fois, qu'elle //n'apparaisse pas deux fois dans la chaine lettres. if (pos.isEmpty() && !mauvaiseslettres.contains(c)) { badcoup++; perdu(); mauvaiseslettres += c; } else { for (int val : pos) { fill(0); text(c, 148+val*28.2, 318); bonnesLettres+=c; isWin(); } } } //Apparition des formes du pendu à chaque mauvais coups //et appaition de l'image Perdu void perdu() { if (badcoup==1) { line(870, 415, 680, 415); } if (badcoup==2) { line(700, 130, 700, 415); } if (badcoup==3) { line(870, 130, 681, 130); } if (badcoup==4) { line(750, 130, 700, 190); } if (badcoup==5) { line(820, 130, 820, 180); } if (badcoup==6) { fill(255); ellipse(820, 200, 40, 45); fill(0); } if (badcoup==7) { line(820, 222, 820, 290); } if (badcoup==8) { line(820, 290, 785, 350); } if (badcoup==9) { line(820, 290, 860, 350); } if (badcoup==10) { line(820, 235, 775, 270); } if (badcoup==11) { line(820, 235, 865, 270); fill(255, 255, 255, 255); PImage imgPerdu; imgPerdu = loadImage("perdu.png"); size(1000, 700); imgPerdu.resize(1000, 700); image(imgPerdu, 0, 0); } } void isWin() { if ( bonnesLettres.length() == mot.length()) { fill(255, 255, 255, 255); PImage imgGagne; imgGagne = loadImage("gagne.png"); size(1000, 700); image(imgGagne, 0, 0); } }