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
| //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;
String MAIN1;
String MAIN2;
String TAPISDEJEU;
JLabel infos;
private InnerSwap innerSwap = new InnerSwap();
//Création des deux joueurs
Joueur Joueur1;
Joueur Joueur2;
private class InnerSwap {
private JButton jbStart;
public void add(JButton jb) {
if (jbStart == null) {
// Si on clique sur un Bouton de notre main
if (jb.getActionCommand().startsWith("MAIN")) {
jbStart = jb;
System.out.println("Coucou");
}
} else {
// Si on clique sur un bouton du Tapis
// Echange des images des 2 boutons
if (jb.getActionCommand().startsWith("TAPIS")) {
Icon Img = jb.getIcon();
jbStart.setIcon(Img);
jbStart = null;
}
}
}
}
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.setActionCommand("Pioche");
topPanel.add(Fin);
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(getButton(MAIN1+i, i, CartesGauche[i]));
}
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(getButton(MAIN2+i, i, CartesDroite[i]));
}
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(getButton(TAPISDEJEU+i+j, i,j,CartesMilieu[i][j]));
}
}
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++){
Carte a;
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++){
Carte b;
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]);
}
//Placement des bornes
for(int i=0;i<9;i++){
CartesMilieu[i][3].setIcon(new ImageIcon("Images/Borne.gif"));
}
}
private JButton getButton(String type, int index, JButton bt) {
bt.setActionCommand(type + index);
bt.addActionListener(this);
return bt;
}
private JButton getButton(String type, int index1, int index2, JButton bt) {
bt.setActionCommand(type + index1 + index2);
bt.addActionListener(this);
return bt;
}
public static void main(String[] args) {
SchottenTotten laPartie=new SchottenTotten();
laPartie.distribueDebut();
}
public void actionPerformed(ActionEvent e) {
innerSwap.add((JButton) e.getSource());
}
} |
Partager