Ok alors voici le message d'erreur:
1 2 3 4 5
| Exception in thread "main" java.lang.IllegalArgumentException: n must be positive
at java.util.Random.nextInt(Unknown Source)
at Joueur.Joueur.piocherUneCarte(Joueur.java:71)
at Joueur.Joueur.jouerSonTour(Joueur.java:138)
at Jeu.Moteur.main(Moteur.java:320) |
Voici la ligne 71
int numeroCarte1 = random.nextInt(pioche.size()-1);
et voici le bout de code qui contient la ligne 71
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| Random random = new Random();
for(int i=0;i <2;i ++ ){
int numeroCarte1 = random.nextInt(pioche.size()-1);
System.out.println("vous piochez\t"+ pioche.get(numeroCarte1));
int numeroCarte2=numeroCarte1;
while (numeroCarte2==numeroCarte1){
numeroCarte2 = random.nextInt(pioche.size()-1);
}
System.out.println("vous piochez\t"+ pioche.get(numeroCarte2));
System.out.println("Si vous voullez garder la première carte, tapez 1, sinon tapez 2.La carte que vous " +
"n'aurez pas choisie sera replacée dans le paquet");
int choix=0;
choix=Clavier.lireInt();
while((choix!=1)&&(choix!=2)){
System.out.println("Choisissez l'une des cartes");
choix=Clavier.lireInt();
}
switch (choix){
case 1: System.out.println("vous avez pioché"+pioche.get(numeroCarte1));choix=1;pioche.remove(numeroCarte1);;break;
case 2: System.out.println("vous avez pioché"+pioche.get(numeroCarte2));choix=2;pioche.remove(numeroCarte2);break;
}
} |
Je pense que les erreurs 138 et 320 sont des conséquences de la première ...
Merci bcp de votre aide
Partager