Bonjour à tous,
J'ai commencé à développer un jeu de cartes basé sur yugioh! Je veux savoir comment l'optimiser avant d'aller plus loin. Donc, après avoir recherché des modèles de conception, je pense à deux choix, mais je ne sais pas quel est le meilleur. Avant cela, pour expliquer le jeu :
Nous avons différents types de cartes :
->MAGIE
-> Piège
-> Monstre
->-> monstre de main deck
-> -> mostre du extra deck
>->->Lien
>->->Pendule
....
J'ai également trois types de decks lorsque je joue :
-> Deck principal (accepte les sorts, les pièges et les monstres principaux)
-> Extra deck (accepte les monstres qui sont lien, pendule...)
-> Side (accepte tout, il sert si vous souhaitez changer certaines cartes de votre main/extra entre les matchs)
Donc l'autre problème, c'est de trouver le meilleur moyen de faire le lien entre la carte et son deck afin de savoir si j'accepte ou non d'ajouter la carte au deck
OPTION 1 : utilisez le décorateur comme design pattern :
Le truc c'est que je vais créer plein de classes pour parfois rien. Par exemple, un monstre lien a 1 attribut de plus et n'a pas de points de def. Un pendule peut se transformer en spell card...
OPTION 2:
Créez une seule classe avec tous les attributs.
J'espère que mon problème est clair, merci à tous pour votre aide
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 public class Card extends javafx.scene.image.ImageView implements Serializable { private int id; private String name; private String type; //SpellCard, TrapCard, FusionMonster, SynchroMonster, Tuner monster, Pendulum monster private String desc; private String race; private String image; private String imageSmall; private Player owner; private Limit limit = Limit.NO_LIMITED; private Face face = Face.UP; /** * This constructor is used to generate a card from data formatted as JSon * @param card its type is JsonNode */ public Card(JsonNode card, Player owner) { id = card.path("id").asInt(); name = card.path("name").asText(); type = card.path("type").asText(); desc = card.path("desc").asText(); race = card.path("race").asText(); image = card.path("card_images").get(0).path("image_url").asText(); imageSmall = card.path("card_images").get(0).path("image_url_small").asText(); this.owner = owner; setCardImage(); } /** * This constructor is used to generate a card from data exported from database * @param cardInfo its type is ResultSet */ public Card(ResultSet cardInfos, Player owner) { try { id = cardInfos.getInt("id"); name = cardInfos.getString("name"); type = cardInfos.getString("type"); desc = cardInfos.getString("desc"); race = cardInfos.getString("race"); image = cardInfos.getString("image"); imageSmall = cardInfos.getString("imageSmall"); this.owner = owner; setCardImage(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * This constructor is used to generate a card manually * @param id card id * @param name card name * @param desc card description * @param race card race * @param image card images list formatted as csv (;) */ public Card(int id, String name, String type, String desc, String race, String image, String imageSmall, Player owner) { this.id = id; this.name = name; this.type = type; this.desc = desc; this.race = race; this.image = image; this.imageSmall = imageSmall; this.owner = owner; setCardImage(); } //setters and getters }
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 public class MonsterCard extends Card { private int atk; private int def; private int level; private String attribute; private Position mode; /** * This constructor is used to generate a monster card from data formated as Json * @param card its type is JsonNode * @param owner player */ public MonsterCard(JsonNode card, Player owner) { super(card, owner); this.atk = card.path("atk").asInt(); this.def = card.path("def").asInt(); this.level = card.path("level").asInt(); this.attribute = card.path("attribute").asText(); } /** * This constructor is used to generate a monster card from data exported from database * @param cardInfos its type is ResultSet */ public MonsterCard(ResultSet cardInfos, Player owner) { super(cardInfos, owner); try { this.atk = cardInfos.getInt("atk"); this.def = cardInfos.getInt("def"); this.level = cardInfos.getInt("level"); this.attribute = cardInfos.getString("attribute"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * @param id * @param name * @param type * @param desc * @param race * @param image * @param imageSmall * @param owner */ public MonsterCard(int id, String name, String type, String desc, String race, String image, String imageSmall, Player owner) { super(id, name, type, desc, race, image, imageSmall, owner); } //getter and setter
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 public class SpellCard extends Card{ public SpellCard(int id, String name, String type, String desc, String race, String image, String imageSmall, Player owner) { super(id, name, type, desc, race, image, image, owner); } public SpellCard(JsonNode card, Player owner) { super(card, owner); } public SpellCard(ResultSet cardInfos, Player owner) { super(cardInfos, owner); } //getter and setter }
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 public class TrapCard extends Card{ /** * @param id * @param name * @param type * @param desc * @param race * @param image * @param owner */ public TrapCard(int id, String name, String type, String desc, String race, String image, String imageSmall, Player owner) { super(id, name, type, desc, race, image, imageSmall, owner); // TODO Auto-generated constructor stub } //getter and setter }
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 public class Deck implements Serializable{ private List<Card> cardList ; private DeckType type; public Deck(DeckType type) { cardList = new ArrayList<Card>(type.getMinCard()); this.type = type; } public boolean checkNbCard() { //size of the deck int size = cardList.size() ; return (size >= getMinCard()&& size <= getMaxCard()); } public boolean checkCardCopies() { //count each card occurrences Map<String,Long> occurrenceMap = cardList.stream().collect(Collectors.groupingBy(card -> card.getName(),Collectors.counting())); return (cardList.stream().filter(card -> card.getLIMIT().getNbCopies()< occurrenceMap.get(card.getName())).count() > 0); } public boolean isValid() { return (checkNbCard() && checkCardCopies()); } public void addCard(Card card) { cardList.add(card); } public void removeCard(Card card) { cardList.remove(card); } public void clearDeck() { cardList.clear(); } //getter and setter }
Partager