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
| //IMPLEMENTATION DES INTERFACES
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class SchottenTotten extends JFrame implements ActionListener {
JButton[] CartesGauche;
JButton[] CartesDroite;
JButton[][] CartesMilieu;
ArrayList<Carte> cartes;
ArrayList<Carte> copie;
ImageIcon[] Im1;
ImageIcon[] Im2;
ImageIcon[][] Images;
Carte a;
Carte b;
JLabel infos;
//Création des deux joueurs
Joueur Joueur1;
Joueur Joueur2;
//Cartes intermédaires lors de la distribution
public SchottenTotten(){
JButton Bpioche = new JButton ("pioche");
JButton Fin= new JButton("Fin");
JFrame fen = new JFrame ("Schotten Totten ");
fen.setLocation(200,100);
fen.setPreferredSize (new Dimension (900 ,600));
fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fen.setLayout(new BorderLayout ());
// Boutons situés en haut de la fenêtre, pioche et le nom des joueurs //
JPanel topPanel = new JPanel (new GridLayout(1,4));
topPanel.add(new JLabel ("Joueur 1"));
topPanel.add(Bpioche);
Bpioche.addActionListener(this);
topPanel.add(Fin);
Bpioche.addActionListener(this);
topPanel.add(new JLabel ("Joueur 2"));
fen.add(topPanel,BorderLayout.NORTH );
// Cartes du joueur 1
CartesGauche = new JButton[6];
JPanel leftPanel = new JPanel (new GridLayout(6,1));
for(int i=0;i<6;i++){
CartesGauche[i]= new JButton();
leftPanel.add(CartesGauche[i]);
CartesGauche[i].addActionListener(this);
}
fen.add(leftPanel, BorderLayout.WEST);
// Cartes du joueur 2
CartesDroite = new JButton[6];
JPanel rightPanel = new JPanel (new GridLayout(6,1));
for(int i=0;i<6;i++){
CartesDroite[i]= new JButton();
rightPanel.add(CartesDroite[i]);
CartesDroite[i].addActionListener(this);
}
fen.add(rightPanel, BorderLayout.EAST);
//Tapis de Jeu
JPanel centerPanel = new JPanel (new GridLayout (9 ,7));
CartesMilieu= new JButton[9][7];
for(int i=0; i<9;i++){
for(int j=0;j<7; j++){
CartesMilieu[i][j]=new JButton();
centerPanel.add(CartesMilieu[i][j]);
CartesMilieu[i][j].addActionListener(this);
}
}
fen.add(centerPanel,BorderLayout.CENTER);
//Statistiques de jeu
JPanel bottomPanel = new JPanel (new GridLayout(1,1));
JLabel infos=new JLabel("infos du jeu");
bottomPanel.add(infos);
fen.add(bottomPanel,BorderLayout.SOUTH);
fen.pack ();
fen.setVisible(true);
}
//Méthode de distribution des cartes
void distribueDebut(){
Paquet p = new Paquet();
Collections.shuffle(p.cartes);
//Tableau d'images pour pouvoir gérer les échanges d'images quand les joueurs jouent
Im1=new ImageIcon[6];
Im2=new ImageIcon[6];
Images=new ImageIcon[9][7];
for(int i=0; i<6;i++){
a=p.cartes.get(i);
p.cartes.remove(i);
Im1[i]=new ImageIcon("Images/"+a.clan.name()+a.val+".GIF");
CartesGauche[i].setIcon(Im1[i]);
}
for(int i=0;i<6;i++){
b=p.cartes.get(i);
p.cartes.remove(i);
Im2[i]=new ImageIcon(("Images/"+b.clan.name()+b.val+".GIF"));
CartesDroite[i].setIcon(Im2[i]);
}
for(int i=0;i<9;i++){
CartesMilieu[i][3].setIcon(new ImageIcon("Images/Borne.gif"));
}
}
public static void main(String[] args) {
SchottenTotten laPartie=new SchottenTotten();
laPartie.distribueDebut();
}
public void actionPerformed(ActionEvent evt) {
for(int i=0;i<6;i++){
if (evt.getActionCommand().equals(CartesGauche[i])) {
for(int j=0;j<10;j++){
for(int k=0;k<7;k++){
if(evt.getActionCommand().equals(CartesMilieu[j][k])){
CartesMilieu[j][k].setIcon(Im1[i]);
CartesGauche[i].setIcon(new ImageIcon());
}
}
}
}
}
}
} |
Partager