Bonjour,

Je crée actuellement un jeu de carte ou on peux crée par exemple une carte Pokémon, cependant j'arrive pas a stocké plusieurs "créations de carte" dans un ArrayList

J'ai fais un menu où la personne clique tape "4" pour lancer la classe "Paquet" où elle peux consulté son paquet de carte aprés avoir crée une /ou plusieurs cartes.
La première carte que je crée se stock bien dans le ArrayList mais lorsque je crée une deuxième carte elle remplace celle du tableau du coup le tableau n'affiche pas plus d'une carte...

Quelqu'un pourrait m'aider à ce niveau là

Ma classe PokemonCard ou je crée la carte Pokémon qui possède un String namePokemon, un int HpPokemon et un Type d'energie EnergyType :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package upmc.pcg.game;
 
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import upmc.pcg.Menu;
import upmc.pcg.ajoutCarte;
 
 
 
/**
 *
 * @author lepor
 */
public class PokemonCard {
 
 
    private String namePokemon;
    public static EnergyType energyType;
    private int hp;
 
    //Constructeur
    public PokemonCard(String namePokemon, int hp, EnergyType energyType) {
        this.namePokemon = namePokemon;
        this.hp = hp;
        this.energyType = energyType;
    }
 
    //Accesseurs
    public String getCardPokemon(){
        return namePokemon+hp+energyType;
    }
 
    public String getNamePokemon() {
        return namePokemon;
    }
 
    public int getHpPokemon() {
        return hp;
    }
 
    public EnergyType getEnergyTypePokemon() {
        return energyType;
    }
   public String toString() {
       return namePokemon+hp+energyType;
   }
 
    public String msgPokemon() {
        return "Vous avez crée "+namePokemon+" avec "+hp+" de point de vie,"+" et de type "+energyType;
}
 
public static List<PokemonCard> jeu = new ArrayList<PokemonCard>();
 
public static PokemonCard getCarte() {
    for (int x=0; x<jeu.size(); x++) {
       return jeu.get(x);
    }
        return null;
 
}
private int stId;
 
 
public boolean setIdNum(int id)
    {
        this.stId = id;
        id++;
        return true;
    }
 
 
    public static void askPokemonCard() {
            Scanner console1 = new Scanner(System.in);
            System.out.println("Nom du pokémon: ");
            System.out.flush();
            String namePokemon = console1.nextLine();
 
 
            Scanner console2 = new Scanner(System.in);
            System.out.println("HP : ");
            System.out.flush();
            int hpPokemon = console2.nextInt();
 
 
            System.out.println("Voici la liste des énergies :");
 
 
            for(EnergyType energy : EnergyType.values()){
               System.out.print(energy+" ,");
            }
            System.out.println("\n");
            Scanner console3 = new Scanner(System.in);
            System.out.println("Veuillez choisir et écrire l'une des énergies (N'oubliez pas la majuscule):");
            System.out.flush();
            String nameEnergy = console3.nextLine();
 
        //Attribution du choix utilisateur (énergie) au type energyType
            if (nameEnergy.equals("Plante")) {
                energyType = EnergyType.Plante;
                }
            else if (nameEnergy.equals("Electrique"))  {
                energyType = EnergyType.Electrique;
            }
            else if (nameEnergy.equals("Eau")) {
                energyType = EnergyType.Eau;
            }
            else if (nameEnergy.equals("Psy")) {
                energyType = EnergyType.Psy;
            }
            else if (nameEnergy.equals("Feu")) {
                energyType = EnergyType.Feu;
            }
            else if (nameEnergy.equals("Combat")) {
                energyType = EnergyType.Combat;
            }
            else if (nameEnergy.equals("Métal")) {
                energyType = EnergyType.Métal;
            }
            else if (nameEnergy.equals("Obscurité")) {
                energyType = EnergyType.Obscurité;
            }
            else if (nameEnergy.equals("Fée")) {
                energyType = EnergyType.Fée;
            }
            else if (nameEnergy.equals("Incolore")) {
                energyType = EnergyType.Incolore;
            }
            else if (nameEnergy.equals("Dragon")) {
                energyType = EnergyType.Dragon;
            }
 
        jeu.add(new PokemonCard(namePokemon, hpPokemon, energyType)); // Création objet + ajout dans Array
        for (int i=0; i<999; i++) {
 
        PokemonCard pokemon = new PokemonCard (namePokemon, hpPokemon, energyType);
 
        pokemon.setIdNum(i); 
        jeu.add(pokemon);
        }
 
 
 
 
 
 
        Scanner console4 = new Scanner(System.in);
 
        System.out.println("Voulez-vous ajouter une nouvelle carte ?");
        System.out.println("[1] YES / [2] NO");
        System.out.flush();
        int yes_no = console3.nextInt();
 
        if (yes_no == 1) {
        ajoutCarte ajoutc = new ajoutCarte(); //Lance la classe ajoutCarte
        ajoutc.texte1(); //Lancement méthode
        }
        else {
        Menu menu = new Menu(); //Lancement du menu
        menu.start();
        }
 
    }
 
  }
Ma classe Paquet qui est appeler pour voir le Paquet de carte :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
31
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package upmc.pcg;
import java.util.ArrayList;
import java.util.List;
import upmc.pcg.game.EnergyType;
import upmc.pcg.game.PokemonCard;
import static upmc.pcg.game.PokemonCard.getCarte;
import static upmc.pcg.game.PokemonCard.jeu;
 
 
/**
 *
 * @author lepor
 */
public class Paquet {
 
 
 
    public static void afficherCarte(){
 
        System.out.println(getCarte().toString());
    }
 
 
 
 
}
Cordialement,
André