/** La classe FrameJeu gere l'interface du jeu * * @version 1.0 * @author Tanguy Domergue et Leni Boscher */ import java.awt.*; import javax.swing.*; import java.io.*; import java.util.Random; public class FrameJeu extends JFrame { private static final long serialVersionUID = 1L; private Couleur[][] tabc; private int[][] tab; /** Constructeur qui initialise le jeu lorsque * l'utilisateur choisit une grille aléatoire */ public FrameJeu(){ JPanel score = new JPanel(); Score s = new Score(); score.add(s); JPanel pan = new JPanel(); this.setBackground(Color.WHITE); this.add(pan); this.add(score, BorderLayout.NORTH); Random rdm = new Random(); this.tabc = new Couleur[10][15]; this.tab = new int[10][15]; int i,j,x; pan.setLayout(new GridLayout(10,15)); for(i=0;i<10;i++){ for(j=0;j<15;j++){ x = rdm.nextInt(3); if(x==0){ tabc[i][j] = new Red(); pan.add(tabc[i][j]); tab[i][j] = 1; } if (x==1){ tabc[i][j] = new Green(); pan.add(tabc[i][j]); tab[i][j] = 2; } if (x==2){ tabc[i][j] = new Blue(); pan.add(tabc[i][j]); tab[i][j] = 3; } } } this.setTitle("Jeu"); Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); int height = (int)dimension.getHeight(); int width = (int)dimension.getWidth(); this.setSize(width, height); this.setVisible(true); // ControllerMouseGame controller = new ControllerMouseGame(this); for (i=0;i<10;i++){ for(j=0;j<15;j++){ this.getCaseTabC(i,j).addMouseListener(new ControllerMouseGame(this,s,i,j)); } } } /** Constructeur qui initialise le jeu * lorsque l'utilisateur choisit un fichier predefini */ public FrameJeu(File fichier) { JPanel score = new JPanel(); Score s = new Score(); score.add(s); JPanel pan = new JPanel(); this.setBackground(Color.WHITE); this.add(pan); this.add(score, BorderLayout.NORTH); this.tabc = new Couleur[10][15]; this.tab = new int[10][15]; int i,j; String line; pan.setLayout(new GridLayout(10,15)); try { FileReader reader = new FileReader (fichier); BufferedReader bufered =new BufferedReader(reader); for(i=0;i<10;i++) { line = bufered.readLine(); for(j=0;j<15;j++) { char lettre = line.charAt(j); if(lettre=='R') { tabc[i][j] = new Red(); pan.add(tabc[i][j]); tab[i][j] = 1; } if (lettre=='V') { tabc[i][j] = new Green(); pan.add(tabc[i][j]); tab[i][j] = 2; } if (lettre=='B') { tabc[i][j] = new Blue(); pan.add(tabc[i][j]); tab[i][j] = 3; } } } try { bufered.close(); } catch (IOException e) { System.out.println("Erreur de fermeture"); } } catch (IOException e) { System.out.println("Erreur d'ouverture"); } this.setTitle("Jeu"); Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); int height = (int)dimension.getHeight(); int width = (int)dimension.getWidth(); this.setSize(width, height); this.setVisible(true); // ControllerMouseGame controller = new ControllerMouseGame(this); for (i=0;i<10;i++){ for(j=0;j<15;j++){ this.getCaseTabC(i,j).addMouseListener(new ControllerMouseGame(this,s,i,j)); } } } public int[][] getTab() { return this.tab; } public Couleur[][] getTabC() { return this.tabc; } public int getCaseTab(int i, int j){ return this.tab[i][j]; } public Couleur getCaseTabC(int i, int j){ return this.tabc[i][j]; } public void setCaseTab(int i, int j, int x){ this.tab[i][j] = x; } public void setCaseTabC(int i, int j, int x){ this.tabc[i][j].setCouleur(x); } }