J'essaye de créer un jeu de pendu mais je ne sais pas comment initialiser correctement le tableau d'affichage de mot, il donne une erreur ce tableau est censé imprimer des traits de soulignement pour des lettres du mot pour deviner puis les underscores se remplacés par des lettres qui ont été devinés par le joueurArrayIndexOutOfBoundsException dans le jeu du pendu
public class Hangman
{
static Scanner userInput = new Scanner(System.in);
public static void main(String args[])
{
String strword = "wordo";
char[] theWord = strword.toCharArray();
int k = strword.length();
int c;
char[] wordDisplay;
for(c=0;c<=k;c++)
{
wordDisplay[c] = '_';
}
int hang = 0;
int i;
while(hang<k+10)
{
System.out.println("type a letter");
for(i=0;i<5;i++)
{
System.out.print(wordDisplay[i]);
}
char userLetter = userInput.next().charAt(0);
for(i=0;i<=k;i++)
{
if(userLetter==theWord[i])
{
System.out.println("a letter guessed");
wordDisplay[i] = theWord[i];
}
else
{
hang++;
}
}
}
System.out.println("you hang");
}
}
«cela donne une erreur», quelle erreur? – SomeJavaGuy
Exception dans le fil "principal" java.lang.ArrayIndexOutOfBoundsException: 5 \t at test2.Hangman.main (Hangman.java:19) – coldman1
Je suis sur le point d'écrire Q & A comment écrire un jeu de pendu en Java. – xenteros