IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

MVC pour vérification


Sujet :

Java

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2013
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Landes (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2013
    Messages : 8
    Points : 6
    Points
    6
    Par défaut MVC pour vérification
    Bonjour à tous !

    Je débute et après quelques tutos je fait un exercice pour améliorer et mieux comprendre la logique des structures en Java

    l'exercice est simple sur la base du jeu Pierre Feuille Ciseaux

    1)Créer une interface qui permet de choisir pierre feuille ciseaux
    2)comparer notre choix a celui de l'ordinateur(Random)
    3)afficher l'image du coup jouer a chaque changement imgJ1 vs imgJ2.
    4)attribuer 1 point au gagnant
    5)le premier à 5pt gagne 1pt de set
    6)le premier a 2pt de set avec 2pt d’écart gagne un point de manche
    7)le premier a 2pt de manche gagne le jeu! (fiouuu)
    8) a chaque point attribuer l'humeur du joueur (statut image) doit changer
    8)statut initial=5, max=10, min=0. (ou initial=0 min=-5 et max=10)
    8)celui-ci est égale à nbrAtteindrePoint(5)+scoreJ1-scoreJ2

    j'ai réalisé l'exercice est je souhaite avoir vos critiques sur la conception du programme, le choix des variable, des I/O image, Pattern MVC, Pattern Observer, objet....... et toutes les chose qui vous dérange dans ce programme.

    le code :
    package Contrôle
    Class Bouton :
    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
    package Controle;
     
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.io.IOException;
     
    import javax.imageio.ImageIO;
    import javax.swing.JButton;
     
    public class Bouton extends JButton implements MouseListener {
    	private String name;
    	private Image img;
    	private int number;
     
    	public Bouton(String str, int n, String imgJKP,int hight, int width) {
    		super(str);
    	    this.name = str;
    	    this.setNumber(n);
    	    this.setPreferredSize(new Dimension(hight, width));
    	    try {
    	        img = ImageIO.read(getClass().getResourceAsStream(imgJKP));
    	      } catch (IOException e) {
    	        e.printStackTrace();
    	      }
    	    this.addMouseListener(this);
     
    	}
     
    	public void paintComponent(Graphics g){
    	    Graphics2D g2d = (Graphics2D)g;
    	    g2d.drawImage(img, 0, 0, this);
    	}
     
    	public void mouseClicked(MouseEvent event) {
    	    //Inutile                   
    	}
     
    	@Override
    	public void mouseEntered(MouseEvent arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
    	@Override
    	public void mouseExited(MouseEvent arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
    	@Override
    	public void mousePressed(MouseEvent arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
    	@Override
    	public void mouseReleased(MouseEvent arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
    	public int getNumber() {
    		return number;
    	}
     
    	public void setNumber(int number) {
    		this.number = number;
    	}  
    }
    Class JanKenPon
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    package Controle;
     
    import vue.Windows;
     
    public class JanKenPon {
     
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Windows w = new Windows();
    	}
    }
    package Metier
    Class Coups
    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
    package Metier;
    import java.util.ArrayList;
     
    import ObserverCoups.ObservableCoups;
    import ObserverCoups.ObservateurCoups;
     
    public class Coups implements ObservableCoups {
     
    	protected int jouer = 0;
     
    	private ArrayList<ObservateurCoups> listCoupsObservateur = new ArrayList<ObservateurCoups>();
     
    	public Coups() {
    		this.jouer = 0;
    	}
     
    	public void setCoupJouer(int c) {
    		this.jouer =  c;
    		this.updateCoupObservateur();
    	}
     
    	public int getCoupJouer() {
    		return this.jouer;
    	}
     
    	@Override
    	public void addCoupObservateur(ObservateurCoups obs) {
    		this.listCoupsObservateur.add(obs);
    	}
     
    	@Override
    	public void delCoupObservateur() {
    		this.listCoupsObservateur = new ArrayList<ObservateurCoups>();
    	}
     
    	@Override
    	public void updateCoupObservateur() {
    		for(ObservateurCoups obs : this.listCoupsObservateur )
    			obs.updateCoups(this.jouer);
    	}
    }
    Class Joueur
    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
    package Metier;
     
    public class Joueur {
     
    	// varaible
    	protected String name;
    	protected String type;
     
    	public Joueur() {
    		this.name = "anonyme";
    		this.type = "inconnu";
    	}
     
    	public Joueur(String name, String type) {
    		this.name = name;
    		this.type = type;
    	}
     
    	public String getName() {
    		return this.name;
    	}
     
    	public String getType() {
    		return this.type;
    	}
     
    }
    Class Partie
    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
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    package Metier;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Map;
     
    import vue.Windows;
    import ObserverPartie.ObservablePartie;
    import ObserverPartie.ObservateurPartie;
     
    public class Partie implements ObservablePartie {
     
    	// variable
    	protected int egaliteI = 0;
    	protected Thread reinitThread;
     
    	protected int nbrT;
    	protected int nbrS;
    	protected int nbrManche;
    	protected int nbrMatch;
    	protected int nbrSE;
    	protected int nbrJoueur;
    	protected String comment;
     
    	protected Joueur J1;
    	protected Joueur J2;
     
    	protected Score score;
    	protected Coups coup;
    	protected Personnage perso;
     
    	protected final Map<Joueur, Score> scores;
    	protected final Map<Joueur, Coups> coups;
    	protected final Map<Joueur, Personnage> persos;
     
    	private ArrayList<ObservateurPartie> listPartieObservateur = new ArrayList<ObservateurPartie>();
     
    	public Partie() {
    		this.nbrT = 5;
    		this.nbrS = 3;
    		this.nbrManche = 2;
    		this.nbrMatch = 1;
    		this.nbrSE = 2;
    		this.nbrJoueur = 2;
    		this.comment = "Jouer";
    		scores = new HashMap<Joueur, Score>();
    		getScores().put(J1 = new Joueur("J1","Humain"), score = new Score(getJ1().getName()));
    		getScores().put(J2 = new Joueur("J2","COM"), score = new Score(getJ2().getName()));
    		coups = new HashMap<Joueur, Coups>();
    		getCoups().put(J1, coup = new Coups());
    		getCoups().put(J2, coup = new Coups());
    		persos = new HashMap<Joueur, Personnage>();
    		getPersos().put(J1, perso = new Personnage("s_"));
    		getPersos().put(J2, perso = new Personnage("u_"));
    	}
     
    	public Partie(int nbrT, int nbrS, int nbrManche, int nbrMatch, int nbrSE, String persoJ1, String persoJ2) {
    		this.nbrT = nbrT;
    		this.nbrS = nbrS;
    		this.nbrManche = nbrManche;
    		this.nbrMatch = nbrMatch;
    		this.nbrSE = nbrSE;
    		this.nbrJoueur = 2;
    		this.comment = "Jouer";
    		scores = new HashMap<Joueur, Score>();
    		getScores().put(J1 = new Joueur("J1","Humain"), score = new Score(getJ1().getName()));
    		getScores().put(J2 = new Joueur("J2","COM"), score = new Score(getJ2().getName()));
    		coups = new HashMap<Joueur, Coups>();
    		getCoups().put(J1, coup = new Coups());
    		getCoups().put(J2, coup = new Coups());
    		persos = new HashMap<Joueur, Personnage>();
    		getPersos().put(J1, perso = new Personnage(persoJ1));
    		getPersos().put(J2, perso = new Personnage(persoJ2));
    	}
     
    	public void action(int coup) {
    		int hasard = (int) (1+3*Math.random());
     
    		this.getCoups().get(this.getJ1()).setCoupJouer(coup);
    		this.getCoups().get(this.getJ2()).setCoupJouer(hasard);
     
    		compareCoups(coup, hasard);
     
    		reinitThread = new Thread(new ReinitThread());
    		reinitThread.start();
    	}
     
    	protected void compareCoups(int coup, int hasard) {
    		if(coup == hasard) {
    			egalite();
    		} else if (coup == 1 && hasard == 2) {
    			J1Win();
    		} else if (coup == 2 && hasard == 3) {
    			J1Win();
    		} else if (coup == 3 && hasard == 1) {
    			J1Win();
    		} else {
    			J2Win();
    		}
    		setStatut();
    	}
     
    	protected void egalite() {
    		egaliteI++;
    		if (egaliteI <= 1)
    			setComment("Egalité !");
    		else if (egaliteI == 2)
    			setComment("Woooh "+egaliteI+"eme Egalité !");
    		else if (egaliteI < 5)
    			setComment("Enorme "+egaliteI+"eme Egalité !");
    		else if (egaliteI >= 5)
    			setComment("Whouuu quel tension ! "+egaliteI+"eme Egalité !");
    	}
     
    	/// win point
    	/// humain win
    	protected void J1Win() {
    		this.getScores().get(this.getJ1()).setPoint();
    		setComment("Joueur 1 Gagne le Point");
    		if (this.getScores().get(this.getJ1()).getPoint() == this.getNbrT()) {
    			// methode set
    			Set(this.getJ1(), this.getJ2());
    		}
    	}
    	// fin humain win
    	/// COM gagne
    	protected void J2Win() {
    		this.getScores().get(this.getJ2()).setPoint();
    		setComment("Joueur 2 Gagne le Point");
    		// test si partie.nbrT pour les points est atteint
    	}
    	// fin com gagne
    	// fin win point
     
    	protected void Set(Joueur a, Joueur b) {
    		this.getScores().get(a).setSet();
    		advantage();
    		/// verifie si le score set >= on nombre de set definit par nbrS avec l'ecart de x set
    		if (this.getScores().get(a).getSet() >= this.getNbrS()) {
    			if (this.getScores().get(a).getAdv() >= this.getNbrSE()) {
    				// methode manche
    				Manche(a, b);
    			}
    		}
    	}
     
    	protected void Manche(Joueur a, Joueur b){
    		this.getScores().get(a).setManche();
    		// si les manche == nbrManche definit
    		if (this.getScores().get(a).getManche() == this.getNbrManche()) {
    			Match(a, b);
    		}
    	}
     
    	protected void Match(Joueur a, Joueur b){
    		this.getScores().get(a).setMatch();
    		// si les manche == nbrManche definit
    		if (this.getScores().get(a).getMatch() == this.getNbrMatch()) {
    			Winner(a);
    		}
    	}
     
    	protected void Winner(Joueur a) {
    		setComment(a.getName()+" Gagne le match !");
    	}
     
    	protected void advantage() {
    		if (this.getScores().get(this.getJ1()).getSet() > this.getScores().get(this.getJ2()).getSet()) {
    			this.getScores().get(this.getJ1()).setAdv(this.getScores().get(this.getJ1()).getSet()-this.getScores().get(this.getJ2()).getSet());
    		} else {
    			this.getScores().get(this.getJ2()).setAdv(this.getScores().get(this.getJ2()).getSet()-this.getScores().get(this.getJ1()).getSet());
    		}
    	}
    	// controle des score */
     
    	/// setstatut perso
    	protected void setStatut() {
    		int J1 = this.getScores().get(this.getJ1()).getPoint();
    		int J2 = this.getScores().get(this.getJ2()).getPoint();
    		this.getPersos().get(this.getJ1()).setPersoStatut(this.getNbrT()+(J1-J2));
    		this.getPersos().get(this.getJ2()).setPersoStatut(this.getNbrT()+(J2-J1));
    	}
    	// fin setstatut perso */
     
    	public void setComment(String comment) {
    		this.comment = comment;
    		updatePartieObservateur();
    	}
     
    	public String getComment() {
    		return this.comment;
    	}
     
    	public int getNbrT() {
    		return this.nbrT;
    	}
     
    	public int getNbrS() {
    		return this.nbrS;
    	}
     
    	public int getNbrManche() {
    		return this.nbrManche;
    	}
     
    	public int getNbrMatch() {
    		return this.nbrMatch;
    	}
     
    	public int getNbrSE() {
    		return this.nbrSE;
    	}
     
    	public Joueur getJ2() {
    		return J2;
    	}
     
    	public Joueur getJ1() {
    		return J1;
    	}
     
    	public Map<Joueur, Score> getScores() {
    		return scores;
    	}
     
    	public Map<Joueur, Coups> getCoups() {
    		return coups;
    	}
     
    	public Map<Joueur, Personnage> getPersos() {
    		return persos;
    	}
     
    	/// reinit des score
    	protected void reinit() {
    		if (getScores().get(getJ2()).getPoint() == getNbrT() || getScores().get(getJ1()).getPoint() == getNbrT()) {
    			getScores().get(getJ1()).resetPoint();
    			getScores().get(getJ2()).resetPoint();
    			// labComment
    			setComment("Jouer !");
    			// reinit egalite
    			egaliteI = 0;
    			//reinit coups jouer
    			getCoups().get(getJ1()).setCoupJouer(0);
    			getCoups().get(getJ2()).setCoupJouer(0);
    			//reinit persos statut
    			getPersos().get(getJ1()).setPersoStatut(5);
    			getPersos().get(getJ2()).setPersoStatut(5);
    		}
    		if (getScores().get(getJ1()).getSet() >= getNbrS() || getScores().get(getJ2()).getSet() >= getNbrS()) {
    			if (getScores().get(getJ1()).getAdv() >= getNbrSE() || getScores().get(getJ2()).getAdv() >= getNbrSE()) {
    				getScores().get(getJ1()).resetSet();
    				getScores().get(getJ2()).resetSet();
    			}
    		}
    		if (getScores().get(getJ1()).getManche() == getNbrManche() || getScores().get(getJ2()).getManche() == getNbrManche()) {
    			getScores().get(getJ1()).resetManche();
    			getScores().get(getJ2()).resetManche();
    		}
    		if (getScores().get(getJ1()).getMatch() == getNbrMatch() || getScores().get(getJ2()).getMatch() == getNbrMatch()) {
    			getScores().get(getJ1()).resetMatch();
    			getScores().get(getJ2()).resetMatch();
    		}
    	}
     
    	protected class ReinitThread implements Runnable {
    	@Override
    		public void run() {
    			if (getScores().get(getJ2()).getPoint() == getNbrT() || getScores().get(getJ1()).getPoint() == getNbrT()) {
    				// TODO Auto-generated method stub
    				Windows.panBoutonsJeux.setVisible(false);
    				try {
    					Thread.sleep(3000);
    				} catch (InterruptedException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				reinit();
    				Windows.panBoutonsJeux.setVisible(true);
    			}
    		}
    	}
     
    	@Override
    	public void addPartieObservateur(ObservateurPartie obs) {
    		// TODO Auto-generated method stub
    		this.listPartieObservateur.add(obs);
    	}
     
    	@Override
    	public void delPartieObservateur() {
    		// TODO Auto-generated method stub
    		this.listPartieObservateur = new ArrayList<ObservateurPartie>();
    	}
     
    	@Override
    	public void updatePartieObservateur() {
    		// TODO Auto-generated method stub
    		for(ObservateurPartie obs : this.listPartieObservateur )
    			obs.updatePartie(this.comment);
    	}
    }
    Class Personnage
    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
    package Metier;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Map;
     
    import Observer.Observable;
    import Observer.Observateur;
     
    public class Personnage implements Observable {
    	protected int profil = 10;
    	protected int statut = 5;
    	protected Map<Integer, String> perso;
    	protected String pathIconPerso = "/";
     
    	private ArrayList<Observateur> listPersoObservateur = new ArrayList<Observateur>();
     
    	public Personnage(String pathImg) {
    		this.profil = 10;
    		this.statut = 5;
    		perso = new HashMap<Integer, String>();
    		for (int i = 0; i<=10; i++) {
    			perso.put(i, pathIconPerso+pathImg+i+".png");
    		}
    	}
     
    	public void setPersoStatut(int c) {
    		this.statut =  c;
    		this.updatePersoObservateur();
    	}
     
    	public int getPersoStatut() {
    		return this.statut;
    	}
     
    	public int getPersoProfil() {
    		return this.profil;
    	}
     
    	public int getPersoSize() {
    		return this.perso.size();
    	}
     
    	public String getPersoIcon() {
    		return this.perso.get(this.statut);
    	}
     
    	public String getPersoIcon(int c) {
    		return this.perso.get(c);
    	}
     
    	@Override
    	public void addPersoObservateur(Observateur obs) {
    		this.listPersoObservateur.add(obs);
    	}
     
    	@Override
    	public void delPersoObservateur() {
    		this.listPersoObservateur = new ArrayList<Observateur>();
    	}
     
    	@Override
    	public void updatePersoObservateur() {
    		for(Observateur obs : this.listPersoObservateur )
    			obs.updatePerso(this.statut);
    	}
    }
    Class Score
    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
    package Metier;
    import java.util.ArrayList;
     
    import ObserverScores.ObservableScores;
    import ObserverScores.ObservateurScores;
     
    public class Score implements ObservableScores {
     
    	/// variable de Score
    	protected String joueurName;
    	protected int point;
    	protected int set;
    	protected int manche;
    	protected int match;
    	protected int adv;
    	private ArrayList<ObservateurScores> listScoreObservateur = new ArrayList<ObservateurScores>();
     
    	/// constructeur
    	public Score(String name) {
    		this.joueurName = name;
    		this.point = 0;
    		this.set = 0;
    		this.manche = 0;
    		this.match = 0;
    		this.adv = 0;
    	}
     
    	public void setPoint() {
    		this.point += 1;
    		this.updateScoreObservateur();
    	}
     
    	public void setSet() {
    		this.set += 1;
    		this.updateScoreObservateur();
    	}
     
    	public void setManche() {
    		this.manche += 1;
    		this.updateScoreObservateur();
    	}
     
    	public void setMatch() {
    		this.match += 1;
    		this.updateScoreObservateur();
    	}
     
    	public void resetPoint() {
    		this.point = 0;
    		this.updateScoreObservateur();
    	}
     
    	public void resetSet() {
    		this.point = 0;
    		this.set = 0;
    		this.updateScoreObservateur();
    	}
     
    	public void resetManche() {
    		this.point = 0;
    		this.set = 0;
    		this.manche = 0;
    		this.updateScoreObservateur();
    	}
    	public void resetMatch() {
    		this.point = 0;
    		this.set = 0;
    		this.manche = 0;
    		this.match = 0;
    		this.updateScoreObservateur();
    	}
     
    	public int getPoint() {
    		return this.point;
    	}
     
    	public int getSet() {
    		return this.set;
    	}
     
    	public int getManche() {
    		return this.manche;
    	}
     
    	public int getMatch() {
    		return this.match;
    	}
     
    	public String getName() {
    		return this.joueurName;
    	}
     
    	public void setAdv(int adv) {
    		this.adv = adv;
    	}
     
    	public int getAdv() {
    		return this.adv;
    	}
     
    	@Override
    	public void addScoreObservateur(ObservateurScores obs) {
    		this.listScoreObservateur.add(obs);
    	}
     
    	@Override
    	public void delScoreObservateur() {
    		this.listScoreObservateur = new ArrayList<ObservateurScores>();
    	}
     
    	@Override
    	public void updateScoreObservateur() {
    		for(ObservateurScores obs : this.listScoreObservateur )
    			obs.updateScore(this.point, this.set, this.manche, this.match);
    	}
    }
    package Vue
    Class Windows
    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
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    package vue;
    import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingConstants;
     
    import Controle.Bouton;
    import Metier.Partie;
    import Observer.Observateur;
    import ObserverCoups.ObservateurCoups;
    import ObserverPartie.ObservateurPartie;
    import ObserverScores.ObservateurScores;
     
    public class Windows extends JFrame {
     
    	protected Partie partie = new Partie(5, 2, 2, 1, 1, "S_", "U_");
     
    	/// Jpanel
    	protected JPanel panContainer = new JPanel();
    	protected JPanel panGridBagAction = new JPanel();
     
    	protected JPanel panGridBagScore = new JPanel();
    	protected JPanel panJ1 = new JPanel();
    	protected JPanel panJ2 = new JPanel();
    	protected JPanel panPoint = new JPanel();
    	protected JPanel panSet = new JPanel();
    	protected JPanel panManche = new JPanel();
    	protected JPanel panMatch = new JPanel();
    	protected JPanel panIconJ1 = new JPanel();
    	protected JPanel panIconJ2 = new JPanel();
     
    	protected JPanel panStart = new JPanel();
     
    	protected JPanel panComment = new JPanel();
     
    	protected JPanel panPersonnage = new JPanel();
    	protected JPanel panPersoJ1 = new JPanel();
    	protected JPanel panPersoJ2 = new JPanel();
     
    	protected JPanel panCoups = new JPanel();
    	protected JPanel panCoupsJ1 = new JPanel();
    	protected JPanel panCoupsJ2 = new JPanel();
     
    	protected JPanel panBoutons = new JPanel();
    	public static JPanel panBoutonsJeux = new JPanel();
    	protected JPanel panBoutonsOpt = new JPanel();
     
    	// CardLayout
    	protected CardLayout clayPersoJ1;
    	protected CardLayout clayPersoJ2;
    	protected CardLayout clayCoupsJ1;
    	protected CardLayout clayCoupsJ2;
     
    	/// JLabel
    	protected JLabel labJ1 = new JLabel("Joueur 1");
    	protected JLabel labJ2 = new JLabel("Joueur 2");
     
    	protected JLabel labPoint = new JLabel("Point");
    	protected JLabel labSet = new JLabel("Set");
    	protected JLabel labManche = new JLabel("Manche");
    	protected JLabel labMatch = new JLabel("Match");
     
    	protected JLabel labPointJ1 = new JLabel("0");
    	protected JLabel labSetJ1 = new JLabel("0");
    	protected JLabel labMancheJ1 = new JLabel("0");
    	protected JLabel labMatchJ1 = new JLabel("0");
     
    	protected JLabel labPointJ2 = new JLabel("0");
    	protected JLabel labSetJ2 = new JLabel("0");
    	protected JLabel labMancheJ2 = new JLabel("0");
    	protected JLabel labMatchJ2 = new JLabel("0");
     
    	protected JLabel labVersus = new JLabel("VS");
     
    	protected JLabel labComment;
    	protected JLabel picLabCoupJ1;
    	protected JLabel picLabCoupJ2;
     
    	protected JLabel picLabIconJ1;
    	protected JLabel picLabIconJ2;
     
    	protected JLabel picLabSttPersoJ1;
    	protected JLabel picLabSttPersoJ2;
     
    	protected Bouton b1;
    	protected Bouton b2;
    	protected Bouton b3;
     
    	protected String imgPath = "/";
     
    	protected String[] tabCoups = {imgPath+"unknow.png",imgPath+"jan.png",imgPath+"ken.png",imgPath+"pon.png"};
     
    	public Windows() {
    		this.setTitle("Jan! Ken! Pon!");
    		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	    this.setLocation(0, 0);
    	    this.setResizable(false);
    	    this.setSize(700, 650);
     
    	    panJ1.setPreferredSize(new Dimension(300, 50));
    	    panJ1.setBackground(Color.BLUE);
    	    panJ2.setPreferredSize(new Dimension(300, 50));
    	    panJ2.setBackground(Color.RED);
    	    panPoint.setPreferredSize(new Dimension(200, 50));
    	    panPoint.setBackground(Color.lightGray);
    	    panSet.setPreferredSize(new Dimension(200, 50));
    	    panSet.setBackground(Color.green);
    	    panManche.setPreferredSize(new Dimension(200, 50));
    	    panManche.setBackground(Color.lightGray);
    	    panMatch.setPreferredSize(new Dimension(200, 50));
    	    panMatch.setBackground(Color.green);
    	    panIconJ1.setPreferredSize(new Dimension(300, 150));
    	    panIconJ1.setBackground(Color.blue);
    	    panIconJ2.setPreferredSize(new Dimension(300, 150));
    	    panIconJ2.setBackground(Color.red);
    	    panStart.setPreferredSize(new Dimension(200, 50));
    	    panStart.setBackground(Color.lightGray);
     
    	    panGridBagScore.setLayout(new GridBagLayout());
    	    GridBagConstraints gbcScore = new GridBagConstraints();
    	    //------------------------------------------------
    	    gbcScore.gridx = 0;
    	    gbcScore.gridy = 4;
    	    gbcScore.gridheight = 1;
    	    gbcScore.gridwidth = 1;
    	    panGridBagScore.add(panJ1, gbcScore);
    	    panJ1.add(labJ1, SwingConstants.CENTER);
    	    Font Joueur = new Font("Arial", Font.BOLD, 25);
    	    labJ1.setFont(Joueur);
    	    //-----------------
    	    gbcScore.gridy = 0;
    	    gbcScore.gridx = 1;
    	    panGridBagScore.add(panPoint, gbcScore);
    	    //-----------------
    	    gbcScore.gridwidth = GridBagConstraints.REMAINDER;
    	    gbcScore.gridy = 4;
    	    gbcScore.gridx = 2;
    	    panGridBagScore.add(panJ2, gbcScore);
    	    panJ2.add(labJ2, SwingConstants.CENTER);
    	    labJ2.setFont(Joueur);
    	    //------------------------------------------------
    	    gbcScore.gridx = 0;
    	    gbcScore.gridy = 0;
    	    gbcScore.gridheight = 4;
    	    gbcScore.gridwidth = 1;
    	    gbcScore.fill = GridBagConstraints.VERTICAL;
    	    panGridBagScore.add(panIconJ1, gbcScore);
    	    panIconJ1.setLayout(new BorderLayout());
    	    panIconJ1.add(panPersoJ1, BorderLayout.NORTH);
     
    	    panPersoJ1.setBackground(Color.white);
    	    panPersoJ1.setLayout(clayPersoJ1 = new CardLayout());
     
    	    for (int i=0; i<partie.getPersos().get(partie.getJ1()).getPersoSize(); i++) {
    	    	picLabSttPersoJ1 = new JLabel(new ImageIcon(getClass().getResource(partie.getPersos().get(partie.getJ1()).getPersoIcon(i))));
    	    	panPersoJ1.add(picLabSttPersoJ1, "img"+i);
    	    }
    	    clayPersoJ1.show(panPersoJ1, "img5");
    	    //On place un écouteur sur persoJ1
    	    partie.getPersos().get(partie.getJ1()).addPersoObservateur(
    	    new Observateur() {
    	      public void updatePerso(int nStatut) {
    	        clayPersoJ1.show(panPersoJ1, "img"+nStatut);
    	      }
    	    });
    	    //-----------------
    	    gbcScore.gridy = 1;
    	    gbcScore.gridx = 1;
    	    gbcScore.gridheight = 1;
    	    gbcScore.fill = GridBagConstraints.HORIZONTAL;
    	    panGridBagScore.add(panSet, gbcScore);
     
    	    gbcScore.gridx = 1;
    	    gbcScore.gridy = 2;
    	    gbcScore.gridheight = 1;
    	    gbcScore.gridwidth = 1;
    	    panGridBagScore.add(panManche, gbcScore);
     
    	    gbcScore.gridx = 1;
    	    gbcScore.gridy = 3;
    	    gbcScore.gridheight = 1;
    	    gbcScore.gridwidth = 1;
    	    panGridBagScore.add(panMatch, gbcScore);
     
    	    gbcScore.gridx = 1;
    	    gbcScore.gridy = 4;
    	    gbcScore.gridheight = 1;
    	    gbcScore.gridwidth = 1;
    	    panGridBagScore.add(panStart, gbcScore);
    	    //-----------------
    	    gbcScore.gridwidth = GridBagConstraints.REMAINDER;
    	    gbcScore.gridheight = 4;
    	    gbcScore.gridy = 0;
    	    gbcScore.gridx = 2;
    	    gbcScore.fill = GridBagConstraints.VERTICAL;
    	    panGridBagScore.add(panIconJ2, gbcScore);
    	    panIconJ2.setLayout(new BorderLayout());
    	    panIconJ2.add(panPersoJ2, BorderLayout.NORTH);
     
    	    panPersoJ2.setBackground(Color.white);
    	    panPersoJ2.setLayout(clayPersoJ2 = new CardLayout());
     
    	    for (int i=0; i<partie.getPersos().get(partie.getJ2()).getPersoSize(); i++) {
    	    	picLabSttPersoJ2 = new JLabel(new ImageIcon(getClass().getResource(partie.getPersos().get(partie.getJ2()).getPersoIcon(i))));
    	    	panPersoJ2.add(picLabSttPersoJ2, "img"+i);
    	    }
    	    clayPersoJ2.show(panPersoJ2, "img5");
    	    //On place un écouteur sur persoJ2
    	    partie.getPersos().get(partie.getJ2()).addPersoObservateur(new Observateur(){
    	      public void updatePerso(int nStatut) {
    		      clayPersoJ2.show(panPersoJ2, "img"+nStatut);
    	      }
    	    });
    	    //------------------------------------------------
    	    panPoint.setLayout(new BorderLayout());
    	    panSet.setLayout(new BorderLayout());
    	    panManche.setLayout(new BorderLayout());
    	    panMatch.setLayout(new BorderLayout());
     
    	    Font scores = new Font("Arial", Font.BOLD, 15);
    	    Font scoresNum = new Font("Arial", Font.BOLD, 25);
    	    Font comment = new Font("Arial", Font.BOLD, 20);
     
    	    labPoint.setFont(scores);
    	    labSet.setFont(scores);
    	    labManche.setFont(scores);
    	    labMatch.setFont(scores);
    	    labPointJ1.setFont(scoresNum);
    	    labSetJ1.setFont(scoresNum);
    	    labMancheJ1.setFont(scoresNum);
    	    labMatchJ1.setFont(scoresNum);
    	    labPointJ2.setFont(scoresNum);
    	    labSetJ2.setFont(scoresNum);
    	    labMancheJ2.setFont(scoresNum);
    	    labMatchJ2.setFont(scoresNum);
    	    labVersus.setFont(scores);
     
     
    	    panPoint.add(labPoint, BorderLayout.CENTER);
    	    labPoint.setHorizontalAlignment(SwingConstants.CENTER);
    	    panSet.add(labSet, BorderLayout.CENTER);
    	    labSet.setHorizontalAlignment(SwingConstants.CENTER);
    	    panManche.add(labManche, BorderLayout.CENTER);
    	    labManche.setHorizontalAlignment(SwingConstants.CENTER);
    	    panMatch.add(labMatch, BorderLayout.CENTER);
    	    labMatch.setHorizontalAlignment(SwingConstants.CENTER);
     
    	    panPoint.add(labPointJ1, BorderLayout.WEST);
    	    panSet.add(labSetJ1, BorderLayout.WEST);
    	    panManche.add(labMancheJ1, BorderLayout.WEST);
    	    panMatch.add(labMatchJ1, BorderLayout.WEST);
     
    	    panPoint.add(labPointJ2, BorderLayout.EAST);
    	    panSet.add(labSetJ2, BorderLayout.EAST);
    	    panManche.add(labMancheJ2, BorderLayout.EAST);
    	    panMatch.add(labMatchJ2, BorderLayout.EAST);
     
    	    panStart.add(labVersus);
    	    labVersus.setHorizontalAlignment(SwingConstants.CENTER);
     
    	    panComment.setPreferredSize(new Dimension(695, 40));
     
    	    panCoups.setPreferredSize(new Dimension(695, 200));
    	    panCoups.setLayout(new BorderLayout());
     
    	    panBoutons.setPreferredSize(new Dimension(695, 107));
    	    panBoutons.setLayout(new BorderLayout());
     
    	    panGridBagAction.setLayout(new GridBagLayout());
    	    GridBagConstraints gbcCtnr = new GridBagConstraints();
    	    panGridBagAction.setBackground(Color.black);
     
    	    //On place un écouteur sur scoreJ2
    	    partie.getScores().get(partie.getJ2()).addScoreObservateur(new ObservateurScores() {
    	      public void updateScore(int point, int set, int manche, int match) {
    	    	  labPointJ2.setText(""+point);
    	    	  labSetJ2.setText(""+set);
    	    	  labMancheJ2.setText(""+manche);
    	    	  labMatchJ2.setText(""+match);
    	      }
    	    });
     
    	    partie.getScores().get(partie.getJ1()).addScoreObservateur(new ObservateurScores() {
    		      public void updateScore(int point, int set, int manche, int match) {
    		    	  labPointJ1.setText(""+point);
    		    	  labSetJ1.setText(""+set);
    		    	  labMancheJ1.setText(""+manche);
    		    	  labMatchJ1.setText(""+match);
    		      }
    		    });
    	    //------------------------------------------------
    	    gbcCtnr.gridx = 0;
    	    gbcCtnr.gridy = 0;
    	    gbcCtnr.gridheight = 1;
    	    gbcCtnr.gridwidth = GridBagConstraints.REMAINDER;;
    	    panGridBagAction.add(panComment, gbcCtnr);
    	    panComment.add(labComment = new JLabel("Jouer !"));
    	    labComment.setHorizontalAlignment(SwingConstants.CENTER);
    	    labComment.setFont(comment);
     
    	    partie.addPartieObservateur(new ObservateurPartie(){
    	      public void updatePartie(String comment) {
    	    	  labComment.setText(comment);
    	      }
    	    });
     
    	    gbcCtnr.gridy = 1;
    	    panCoupsJ1.setBackground(Color.white);
    	    panCoupsJ2.setBackground(Color.white);
    	    panGridBagAction.add(panCoups, gbcCtnr);
     
    	    panCoupsJ1.setPreferredSize(new Dimension(350, 200));
    	    panCoups.add(panCoupsJ1, BorderLayout.WEST);
     
    	    panCoupsJ2.setPreferredSize(new Dimension(350, 200));
    	    panCoups.add(panCoupsJ2, BorderLayout.EAST);
     
    	    panCoupsJ1.setLayout(clayCoupsJ1= new CardLayout());
    	    panCoupsJ2.setLayout(clayCoupsJ2= new CardLayout());
    	    for (int i=0; i<tabCoups.length; i++) {
    	    	picLabCoupJ1 = new JLabel(new ImageIcon(getClass().getResource(tabCoups[i])));
    	    	picLabCoupJ2 = new JLabel(new ImageIcon(getClass().getResource(tabCoups[i])));
    	    	panCoupsJ1.add(picLabCoupJ1, "img"+i);
    	    	panCoupsJ2.add(picLabCoupJ2, "img"+i);
    	    }
     
    	    clayCoupsJ1.show(panCoupsJ1, "img0");
    	    clayCoupsJ2.show(panCoupsJ2, "img0");
     
    	    //On place un écouteur sur persoJ1
    	    partie.getCoups().get(partie.getJ1()).addCoupObservateur(new ObservateurCoups(){
    	      public void updateCoups(int nCoup) {
    	    	  clayCoupsJ1.show(panCoupsJ1, "img"+nCoup);
    	      }
    	    });
     
    	    //On place un écouteur sur persoJ2
    	    partie.getCoups().get(partie.getJ2()).addCoupObservateur(new ObservateurCoups(){
    	      public void updateCoups(int nCoup) {
    	    	  clayCoupsJ2.show(panCoupsJ2, "img"+nCoup);
    	      }
    	    });
     
    	    gbcCtnr.gridy = 2;
    	    panGridBagAction.add(panBoutons, gbcCtnr);
    	    panBoutons.add(panBoutonsJeux, BorderLayout.NORTH);
    	    b1 = new Bouton("Jan", 1,imgPath+"jan.png", 95, this.getWidth());
    	    b2 = new Bouton("Ken", 2,imgPath+"ken.png", 95, this.getWidth());
    	    b3 = new Bouton("Pon", 3,imgPath+"pon.png", 95, this.getWidth());
     
    	    panBoutonsJeux.add(b1);
    	    panBoutonsJeux.add(b2);
    	    panBoutonsJeux.add(b3);
    	    b1.addActionListener(new Jan());
    	    b2.addActionListener(new Ken());
    	    b3.addActionListener(new Pon());
     
    	    panBoutons.add(panBoutonsOpt, BorderLayout.SOUTH);
    	    //------------------------------------------------
     
    	    panContainer.add(panGridBagScore);
    	    panContainer.add(panGridBagAction);
     
    	    this.add(panContainer);
    	    this.setVisible(true);
     
    	}
     
    	public class Jan implements ActionListener {
    	@Override
    		public void actionPerformed(ActionEvent e) {
    			// TODO Auto-generated method stub
    			 partie.action(1);
    		}
    	}
     
    	public class Ken implements ActionListener {
    	@Override
    		public void actionPerformed(ActionEvent e) {
    			// TODO Auto-generated method stub
    			partie.action(2);
    		}
    	}
     
    	public class Pon implements ActionListener {
    	@Override
    		public void actionPerformed(ActionEvent e) {
    			// TODO Auto-generated method stub
    			partie.action(3);
    		}
    	}
    }
    je ne maîtrise pas encore très bien java mais je souhaite mieux comprendre.
    je m'en remet a vous, Merci d'avance pour votre temps.
    Bonne journée

  2. #2
    Membre averti Avatar de toutgrego
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mai 2013
    Messages
    217
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2013
    Messages : 217
    Points : 350
    Points
    350
    Par défaut
    J'ai du mal à voir la séparation des responsabilités (Modele/Vue/Controleur).

    Un bouton qui implémente un MouseListener ? Ton package vue semble s'occuper des actions et du modèle aussi.

    J'ai pas été en profondeur dans le code mais tout semble mélangé
    F*ck it ! Do it !

Discussions similaires

  1. REQ : Algo pour vérification saisie du "Numero TVA"
    Par Eric.H dans le forum Langage
    Réponses: 4
    Dernier message: 28/01/2009, 10h23
  2. Réponses: 6
    Dernier message: 15/06/2006, 15h15
  3. MVC pour connecter données et vue automatiquement
    Par tonioab dans le forum AWT/Swing
    Réponses: 6
    Dernier message: 31/01/2006, 11h58
  4. Outil pour vérification automatique des liens
    Par zazaraignée dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 20/01/2005, 20h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo