repost
This commit is contained in:
parent
60ae8d7ed1
commit
1ed63aee8f
46
ActionPageAccueil.java
Normal file
46
ActionPageAccueil.java
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @version 1.0
|
||||
* @author Tanguy Domergue et Leni Boscher
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
*Classe heritant d'ActionListener, elle gere les trois boutons du menu principal/**
|
||||
*/
|
||||
public class ActionPageAccueil implements ActionListener
|
||||
{
|
||||
/**
|
||||
*attribut men contenant l'objet FrameAccueil, il prend la valeur de L'Objet FrameAccueil passe en argument dans le constructeur.
|
||||
*/
|
||||
private FrameAccueil menu;
|
||||
public ActionPageAccueil(FrameAccueil p)
|
||||
{
|
||||
super();
|
||||
this.menu=p;
|
||||
}
|
||||
|
||||
/**
|
||||
*actionPerformed effectue lance une action en fonction du bouton choisi par l'utilisateur grace a getActionCommand().
|
||||
*/
|
||||
public void actionPerformed (ActionEvent e) {
|
||||
String reponse;
|
||||
reponse=e.getActionCommand();
|
||||
if(reponse=="JOUER")
|
||||
{
|
||||
FrameJeu choix = new FrameJeu();
|
||||
this.menu.dispose();
|
||||
}
|
||||
else if (reponse== "GRILLE PREDEFINIE" )
|
||||
{
|
||||
ChooseFrameJeuPredefini choix = new ChooseFrameJeuPredefini();
|
||||
this.menu.dispose();
|
||||
}
|
||||
else if(reponse=="QUITTER")
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
40
ActionPageEnd.java
Normal file
40
ActionPageEnd.java
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
*@author Tanguy Domergue et Leni Boscher
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
*Classe heritant d'ActionListener, elle gère les deux boutons du menu end permettant de quitter ou de revenior au menu principal
|
||||
*/
|
||||
public class ActionPageEnd implements ActionListener
|
||||
{
|
||||
/**
|
||||
*attribut men contenant l'objet Frame_End, il prend la valeur de L'Objet Frame_End passe en argument dans le constructeur.
|
||||
*/
|
||||
private FrameEnd men;
|
||||
public ActionPageEnd(FrameEnd p)
|
||||
{
|
||||
super();
|
||||
this.men=p;
|
||||
}
|
||||
|
||||
/**
|
||||
*actionPerformed effectue lance une action en fonction du bouton choisi par l'utilisateur grace a getActionCommand().
|
||||
*/
|
||||
public void actionPerformed (ActionEvent e) {
|
||||
String reponse;
|
||||
reponse = e.getActionCommand();
|
||||
if(reponse=="REJOUER")
|
||||
{
|
||||
FrameAccueil choix=new FrameAccueil();
|
||||
this.men.dispose();
|
||||
}
|
||||
else if(reponse=="QUITTER")
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
22
BackgroundPanelAccueil.java
Normal file
22
BackgroundPanelAccueil.java
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
*@author Tanguy Domergue et Leni Boscher
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class BackgroundPanelAccueil extends JPanel
|
||||
{
|
||||
// insère une image du dossier dans une variable img
|
||||
Image img;
|
||||
public BackgroundPanelAccueil()
|
||||
{
|
||||
img = Toolkit.getDefaultToolkit().getImage("img/fondAccueil.png");
|
||||
}
|
||||
|
||||
protected void paintComponent(Graphics g)
|
||||
{
|
||||
// dessine l'image gérérée au dessus
|
||||
g.drawImage(img, 0, 0, this);
|
||||
}
|
||||
}
|
18
BackgroundPanelEnd.java
Normal file
18
BackgroundPanelEnd.java
Normal file
@ -0,0 +1,18 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class BackgroundPanelEnd extends JPanel
|
||||
{
|
||||
// insère une image du dossier dans une variable img
|
||||
Image img;
|
||||
public BackgroundPanelEnd()
|
||||
{
|
||||
img = Toolkit.getDefaultToolkit().getImage("img/fondEnd.png");
|
||||
}
|
||||
|
||||
protected void paintComponent(Graphics g)
|
||||
{
|
||||
// dessine l'image gérérée au dessus
|
||||
g.drawImage(img, 0, 0, this);
|
||||
}
|
||||
}
|
18
Blue.java
Normal file
18
Blue.java
Normal file
@ -0,0 +1,18 @@
|
||||
/** La classe Blue represente un bloc bleu
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Tanguy Domergue et Leni Boscher
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class Blue extends Couleur{
|
||||
|
||||
public Blue(){
|
||||
super();
|
||||
this.setCouleur(3);
|
||||
}
|
||||
}
|
34
ChooseFrameJeuPredefini.java
Normal file
34
ChooseFrameJeuPredefini.java
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Tanguy Domergue et Leni Boscher
|
||||
*/
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.io.*;
|
||||
|
||||
public class ChooseFrameJeuPredefini extends JFrame //cette fenetre ouvre les repertoire de l'utilisateur pour rentrer des fichiers prédéfini
|
||||
{
|
||||
public ChooseFrameJeuPredefini()
|
||||
{
|
||||
this.setTitle("Jeu2");
|
||||
Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int height = (int)dimension.getHeight();
|
||||
int width = (int)dimension.getWidth();
|
||||
this.setSize(width, height);
|
||||
this.setVisible(true);
|
||||
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
FileNameExtensionFilter filter = new FileNameExtensionFilter(
|
||||
"Fichier texte", "txt");
|
||||
chooser.setFileFilter(filter);
|
||||
this.add(chooser);
|
||||
int returnVal = chooser.showOpenDialog(this);
|
||||
|
||||
if(returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
new FrameJeu(chooser.getSelectedFile());
|
||||
this.dispose();
|
||||
}
|
||||
}
|
||||
}
|
292
ControllerMouseGame.java
Normal file
292
ControllerMouseGame.java
Normal file
@ -0,0 +1,292 @@
|
||||
/** La classe ControllerMouseGame gere les clics lies a l'utilisateur
|
||||
* ainsi que les regles du jeu
|
||||
* @version 1.0
|
||||
* @author Tanguy Domergue et Leni Boscher
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.Random;
|
||||
import java.lang.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class ControllerMouseGame implements MouseListener
|
||||
{
|
||||
|
||||
/** Tableau d'entiers qui permet de stocker
|
||||
* les objets d'un meme groupe
|
||||
*/
|
||||
private int[][] group;
|
||||
|
||||
private int score=0;
|
||||
private int group_size=0;
|
||||
private FrameJeu frame;
|
||||
private int x,y;
|
||||
private Score scoreS;
|
||||
|
||||
/** Constructeur de la classe qui cree un tableau group
|
||||
* et qui l'initialise a -1
|
||||
* @param fen : permet de reprendre la fenetre de jeu de FrameJeu
|
||||
* @param scr : permet de recuperer le score de la classe Score
|
||||
* @param x : l'indice x des cases sur lesquelles on cliquera
|
||||
* @param y : l'indice y des cases sur lesquelles on cliquera
|
||||
*/
|
||||
public ControllerMouseGame(FrameJeu fen, Score scr, int x, int y)
|
||||
{
|
||||
this.group = new int[10][15];
|
||||
this.frame = fen;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.scoreS = scr;
|
||||
for(int i=0;i<10;i++)
|
||||
{
|
||||
for(int j=0;j<15;j++)
|
||||
{
|
||||
this.group[i][j] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Methode qui teste si un bloc est deja
|
||||
* dans le tableau group
|
||||
*/
|
||||
public boolean testInGroup(int x, int y)
|
||||
{
|
||||
if(group[x][y]==this.frame.getCaseTab(x,y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Methode qui reunit les blocs en groupe
|
||||
* @param x : indice x du bloc
|
||||
* @param y : indice y du bloc
|
||||
*/
|
||||
public void testGroup(int x, int y)
|
||||
{
|
||||
|
||||
if(x>0)
|
||||
{
|
||||
if((this.frame.getCaseTab(x,y) != 0) && (this.frame.getCaseTab(x,y) == this.frame.getCaseTab(x-1,y)))
|
||||
{
|
||||
if((testInGroup(x-1,y)))
|
||||
{
|
||||
this.group_size++;
|
||||
this.group[x-1][y] = this.frame.getCaseTab(x-1,y);
|
||||
testGroup(x-1,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(y>0)
|
||||
{
|
||||
if((this.frame.getCaseTab(x,y) != 0) && (this.frame.getCaseTab(x,y) == this.frame.getCaseTab(x,y-1)))
|
||||
{
|
||||
if((testInGroup(x,y-1)))
|
||||
{
|
||||
this.group_size++;
|
||||
this.group[x][y-1] = this.frame.getCaseTab(x,y-1);
|
||||
testGroup(x,y-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(x+1<10)
|
||||
{
|
||||
if((this.frame.getCaseTab(x,y) != 0) && (this.frame.getCaseTab(x,y) == this.frame.getCaseTab(x+1,y)))
|
||||
{
|
||||
if((testInGroup(x+1,y)))
|
||||
{
|
||||
this.group_size++;
|
||||
this.group[x+1][y] = this.frame.getCaseTab(x+1,y);
|
||||
testGroup(x+1,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(y+1<15)
|
||||
{
|
||||
if((this.frame.getCaseTab(x,y) != 0) && (this.frame.getCaseTab(x,y) == this.frame.getCaseTab(x,y+1)))
|
||||
{
|
||||
if((testInGroup(x,y+1)))
|
||||
{
|
||||
this.group_size++;
|
||||
this.group[x][y+1] = this.frame.getCaseTab(x,y+1);
|
||||
testGroup(x,y+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Methode qui reorganise la colonne
|
||||
* et qui comble les vides
|
||||
* @param j : colonne a reordonner
|
||||
*/
|
||||
|
||||
public void orderColumn(int j)
|
||||
{
|
||||
for(int i=9;i>0;i--)
|
||||
{
|
||||
if(this.frame.getCaseTab(i,j)==0)
|
||||
{
|
||||
int c = this.frame.getCaseTab(i-1,j);
|
||||
this.frame.setCaseTabC(i-1,j,0);
|
||||
this.frame.setCaseTab(i-1,j,0);
|
||||
this.frame.setCaseTabC(i,j,c);
|
||||
this.frame.setCaseTab(i,j,c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Methode qui copie une colonne de droite a gauche
|
||||
* @param j : colonne a copier
|
||||
*/
|
||||
|
||||
public void copyColumn(int j)
|
||||
{
|
||||
for(int i=j;i<14;i++)
|
||||
{
|
||||
for(int k=0;k<10;k++)
|
||||
{
|
||||
int c = this.frame.getCaseTab(k,i+1);
|
||||
this.frame.setCaseTab(k,i+1,0);
|
||||
this.frame.setCaseTabC(k,i+1,0);
|
||||
this.frame.setCaseTab(k,i,c);
|
||||
this.frame.setCaseTabC(k,i,c);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** Methode qui regarde chaque colonne,
|
||||
* si certaines sont vides, elle deplace de droite
|
||||
* a gauche
|
||||
*/
|
||||
|
||||
public void checkEmptyColumn()
|
||||
{
|
||||
int check = 1;
|
||||
|
||||
for(int i=13;i>=0;i--)
|
||||
{
|
||||
if(this.frame.getCaseTab(9,i) == 0)
|
||||
{
|
||||
copyColumn(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void mouseClicked(MouseEvent e){
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void mouseEntered(MouseEvent e){
|
||||
testGroup(this.x,this.y);
|
||||
for(int i=0;i<10;i++){
|
||||
for(int j=0;j<15;j++){
|
||||
if(group[i][j] != -1)
|
||||
{
|
||||
this.frame.getCaseTabC(i,j).setBackground(new Color(250,188,23));
|
||||
}
|
||||
}
|
||||
}
|
||||
resetGroup();
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void mouseExited(MouseEvent e){
|
||||
testGroup(this.x,this.y);
|
||||
for(int i=0;i<10;i++){
|
||||
for(int j=0;j<15;j++){
|
||||
if(group[i][j] != -1)
|
||||
{
|
||||
this.frame.getCaseTabC(i,j).setBackground(new Color(238,238,238));
|
||||
}
|
||||
}
|
||||
}
|
||||
resetGroup();
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void mousePressed(MouseEvent e){
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void mouseReleased(MouseEvent e){
|
||||
mouseExited(e);
|
||||
int xi,yi;
|
||||
xi = this.x;
|
||||
yi = this.y;
|
||||
|
||||
testGroup(this.x,this.y);
|
||||
|
||||
int i=0;
|
||||
int cgrp=0;
|
||||
for(i=0;i<10;i++)
|
||||
{
|
||||
for(int j=0;j<15;j++)
|
||||
{
|
||||
if(this.group[i][j]!=-1)
|
||||
{
|
||||
this.frame.setCaseTab(i,j,0);
|
||||
this.frame.setCaseTabC(i,j,0);
|
||||
cgrp++;
|
||||
}
|
||||
orderColumn(j);
|
||||
}
|
||||
}
|
||||
checkEmptyColumn();
|
||||
|
||||
int s = (cgrp-2)*(cgrp-2);
|
||||
if(cgrp>2)
|
||||
{
|
||||
this.scoreS.updateScore(s);
|
||||
}
|
||||
resetGroup();
|
||||
this.x = xi;
|
||||
this.y = yi;
|
||||
|
||||
if(endCondition()==1){
|
||||
FrameEnd fenetre = new FrameEnd(scoreS.getScore());
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Méthode qui remet le tableau Group
|
||||
* à -1
|
||||
*/
|
||||
public void resetGroup()
|
||||
{
|
||||
for(int i=0;i<10;i++){
|
||||
for(int j=0;j<15;j++){
|
||||
this.group[i][j] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Méthode qui pose une condition pour la fin
|
||||
* de la partie
|
||||
*/
|
||||
public int endCondition(){
|
||||
for(int i=0;i<10;i++){
|
||||
for(int j=0;j<15;j++){
|
||||
testGroup(i,j);
|
||||
for(int x=0;x<10;x++){
|
||||
for(int y=0;y<15;y++){
|
||||
if(group[x][y] != -1){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
56
Couleur.java
Normal file
56
Couleur.java
Normal file
@ -0,0 +1,56 @@
|
||||
/** La classe Couleur sert a dessiner les images en fonction
|
||||
* des blocs
|
||||
* @version 1.0
|
||||
* @author Tanguy Domergue et Leni Boscher
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class Couleur extends JPanel{
|
||||
private int Couleur;
|
||||
private Image img;
|
||||
|
||||
public Couleur(){
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
|
||||
if (this.isOpaque()) {
|
||||
|
||||
secondPinceau.setColor(this.getBackground());
|
||||
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
if (this.Couleur == 0){
|
||||
secondPinceau.setColor(Color.WHITE);
|
||||
secondPinceau.fillOval(0,0,50,50);
|
||||
}
|
||||
|
||||
if (this.Couleur == 1){
|
||||
Image img = Toolkit.getDefaultToolkit().getImage("./img/rouge.png");
|
||||
secondPinceau.drawImage(img, 10, 10, this);
|
||||
}
|
||||
if (this.Couleur == 2){
|
||||
Image img = Toolkit.getDefaultToolkit().getImage("./img/vert.png");
|
||||
secondPinceau.drawImage(img, 10, 10, this);
|
||||
}
|
||||
if (this.Couleur == 3){
|
||||
Image img = Toolkit.getDefaultToolkit().getImage("./img/bleu.png");
|
||||
secondPinceau.drawImage(img, 10, 10, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCouleur(int c) {
|
||||
this.Couleur = c;
|
||||
repaint();
|
||||
}
|
||||
|
||||
public int getCouleur(){
|
||||
return Couleur;
|
||||
}
|
||||
}
|
52
FrameAccueil.java
Normal file
52
FrameAccueil.java
Normal file
@ -0,0 +1,52 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class FrameAccueil extends JFrame // fenetre d'acceuil qui propose 3 boutons qui permettront a l'utilisateur de se dirigé vers le jeu ou la sortis
|
||||
{
|
||||
public FrameAccueil()
|
||||
{
|
||||
this.setTitle("Menu");
|
||||
this.setSize(1143,855);
|
||||
this.setLocation(0, 0);
|
||||
this.setResizable(false);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
BackgroundPanelAccueil fond = new BackgroundPanelAccueil();
|
||||
this.add(fond);
|
||||
|
||||
JButton bouton_jouer = new JButton("JOUER");
|
||||
JButton bouton_grille = new JButton("GRILLE PREDEFINIE");
|
||||
JButton bouton_quitter = new JButton("QUITTER");
|
||||
|
||||
Color blue = new Color(13,122,238);
|
||||
Color vert = new Color(54,144,36);
|
||||
Color rouge = new Color(232,13,33);
|
||||
|
||||
bouton_jouer.setForeground(blue);
|
||||
bouton_jouer.setBackground(Color.WHITE);
|
||||
bouton_jouer.setPreferredSize(new Dimension(300, 50));
|
||||
|
||||
bouton_grille.setForeground(vert);
|
||||
bouton_grille.setBackground(Color.WHITE);
|
||||
bouton_grille.setPreferredSize(new Dimension(300, 50));
|
||||
|
||||
bouton_quitter.setForeground(rouge);
|
||||
bouton_quitter.setBackground(Color.WHITE);
|
||||
bouton_quitter.setPreferredSize(new Dimension(300, 50));
|
||||
|
||||
fond.add(bouton_jouer, BorderLayout.CENTER);
|
||||
fond.add(bouton_grille, BorderLayout.CENTER);
|
||||
fond.add(bouton_quitter, BorderLayout.CENTER);
|
||||
|
||||
ActionPageAccueil action = new ActionPageAccueil(this);
|
||||
bouton_jouer.addActionListener(action);
|
||||
bouton_grille.addActionListener(action);
|
||||
bouton_quitter.addActionListener(action);
|
||||
|
||||
this.setVisible(true);
|
||||
|
||||
/*fond.setLayout(null);
|
||||
fond.setBounds(0, 0, 0, 0);*/
|
||||
|
||||
}
|
||||
}
|
55
FrameEnd.java
Normal file
55
FrameEnd.java
Normal file
@ -0,0 +1,55 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class FrameEnd extends JFrame
|
||||
// fenetre qui s'ouvre à la fin de la partie nous permettant de voir le score, de retourner au menu d'accueil ou de quitter le jeu
|
||||
{
|
||||
public FrameEnd(int s)// ajout des boutons REJOUER QUITTER et affichage du score
|
||||
{
|
||||
String t;
|
||||
JPanel p = new JPanel();
|
||||
this.setTitle("Fin");
|
||||
this.setSize(1143,855);
|
||||
this.setLocation(0, 0);
|
||||
this.setResizable(false);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
t=Integer.toString(s);
|
||||
JLabel scr = new JLabel("Score : " + t);
|
||||
Font f = new Font("ARIAL", Font.BOLD, 20);
|
||||
scr.setFont(f);
|
||||
scr.setVerticalAlignment(JLabel.CENTER);
|
||||
p.add(scr);
|
||||
p.setPreferredSize(new Dimension(300, 50));
|
||||
|
||||
|
||||
BackgroundPanelEnd fond2 = new BackgroundPanelEnd();
|
||||
this.add(fond2);
|
||||
|
||||
JButton bouton_rejouer = new JButton("REJOUER");
|
||||
JButton bouton_quitter = new JButton("QUITTER");
|
||||
|
||||
Color blue = new Color(13,122,238);
|
||||
Color vert = new Color(54,144,36);
|
||||
Color rouge = new Color(232,13,33);
|
||||
|
||||
bouton_rejouer.setForeground(blue);
|
||||
bouton_rejouer.setBackground(Color.WHITE);
|
||||
bouton_rejouer.setPreferredSize(new Dimension(300, 50));
|
||||
|
||||
bouton_quitter.setForeground(rouge);
|
||||
bouton_quitter.setBackground(Color.WHITE);
|
||||
bouton_quitter.setPreferredSize(new Dimension(300, 50));
|
||||
|
||||
fond2.add(bouton_rejouer, BorderLayout.CENTER);
|
||||
fond2.add(bouton_quitter, BorderLayout.CENTER);
|
||||
|
||||
ActionPageEnd action = new ActionPageEnd(this);
|
||||
bouton_rejouer.addActionListener(action);
|
||||
bouton_quitter.addActionListener(action);
|
||||
|
||||
fond2.add(p, BorderLayout.CENTER);
|
||||
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
188
FrameJeu.java
Normal file
188
FrameJeu.java
Normal file
@ -0,0 +1,188 @@
|
||||
/** 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);
|
||||
}
|
||||
}
|
18
Green.java
Normal file
18
Green.java
Normal file
@ -0,0 +1,18 @@
|
||||
/** La classe Green represente un bloc vert
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Tanguy Domergue et Leni Boscher
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class Green extends Couleur{
|
||||
|
||||
public Green(){
|
||||
super();
|
||||
this.setCouleur(2);
|
||||
}
|
||||
}
|
8
Main.java
Normal file
8
Main.java
Normal file
@ -0,0 +1,8 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Main{//initialisation du menu
|
||||
public static void main(String[] args) {
|
||||
new FrameAccueil();
|
||||
}
|
||||
}
|
BIN
Rapport/Compte_Rendu_Samegame.pdf
Normal file
BIN
Rapport/Compte_Rendu_Samegame.pdf
Normal file
Binary file not shown.
18
Red.java
Normal file
18
Red.java
Normal file
@ -0,0 +1,18 @@
|
||||
/** La classe Red represente un bloc rouge
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Tanguy Domergue et Leni Boscher
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class Red extends Couleur{
|
||||
|
||||
public Red(){
|
||||
super();
|
||||
this.setCouleur(1);
|
||||
}
|
||||
}
|
1
Samegame
Submodule
1
Samegame
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 60ae8d7ed1f97447a879e5dd73760553a0869ebb
|
36
Score.java
Normal file
36
Score.java
Normal file
@ -0,0 +1,36 @@
|
||||
/** La classe Score represente le label qui affiche le score
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Tanguy Domergue et Leni Boscher
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class Score extends JLabel{
|
||||
private int score=0;
|
||||
/**
|
||||
* Constructeur qui initialise le score
|
||||
*/
|
||||
public Score(){
|
||||
super();
|
||||
this.setText("Score : " + this.score);
|
||||
Font font = new Font("ARIAL", Font.BOLD, 25);
|
||||
this.setFont(font);
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode qui met à jour le score en temps réel
|
||||
*/
|
||||
public void updateScore(int scr){
|
||||
this.score += scr;
|
||||
this.setText("Score : " + this.score);
|
||||
}
|
||||
|
||||
public int getScore(){
|
||||
return this.score;
|
||||
}
|
||||
|
||||
}
|
10
file/all.txt
Normal file
10
file/all.txt
Normal file
@ -0,0 +1,10 @@
|
||||
VVVVVVVVVVVVVVV
|
||||
VVVVVVVVVVVVVVV
|
||||
VVVVVVVVVVVVVVV
|
||||
VVVVVVVVVVVVVVV
|
||||
VVVVVVVVVVVVVVV
|
||||
VVVVVVVVVVVVVVV
|
||||
VVVVVVVVVVVVVVV
|
||||
VVVVVVVVVVVVVVV
|
||||
VVVVVVVVVVVVVVV
|
||||
RVVVVVVVVVVVVVV
|
10
file/test.txt
Normal file
10
file/test.txt
Normal file
@ -0,0 +1,10 @@
|
||||
RVVRRVRVBBBBRBV
|
||||
BVVVVRBVVBRRVRB
|
||||
VBBRVRBVRRBRRRR
|
||||
BRBVBRBBVVBRVRV
|
||||
RVBVBBBRRBRRRBV
|
||||
RVVVBBRBVVBVVRB
|
||||
BRBRBBBRBVRVRRV
|
||||
VRRVVBBVVBBRVVV
|
||||
BVRRVVBRVRRRBVV
|
||||
BBRBBBBRVVRRVRB
|
BIN
img/bleu.png
Normal file
BIN
img/bleu.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
BIN
img/fondAccueil.png
Normal file
BIN
img/fondAccueil.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 790 KiB |
BIN
img/fondEnd.png
Normal file
BIN
img/fondEnd.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 477 KiB |
BIN
img/rouge.png
Normal file
BIN
img/rouge.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
BIN
img/vert.png
Normal file
BIN
img/vert.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
41
makefile
Normal file
41
makefile
Normal file
@ -0,0 +1,41 @@
|
||||
### Tanguy DOMERGUE # Leni BOSCHER ###
|
||||
|
||||
JFLAGS = -g
|
||||
COMPILATION = javac
|
||||
|
||||
EX= java
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
|
||||
.java.class:
|
||||
$(COMPILATION) $(JFLAGS) $*.java
|
||||
|
||||
|
||||
CLASSES = \
|
||||
ActionPageEnd.java\
|
||||
BackgroundPanelEnd.java\
|
||||
FrameEnd.java\
|
||||
FrameAccueil.java\
|
||||
BackgroundPanelAccueil.java\
|
||||
ChooseFrameJeuPredefini.java\
|
||||
Score.java\
|
||||
ControllerMouseGame.java\
|
||||
FrameJeu.java\
|
||||
Couleur.java\
|
||||
Red.java\
|
||||
Blue.java\
|
||||
Green.java\
|
||||
ActionPageAccueil.java\
|
||||
Main.java\
|
||||
|
||||
|
||||
default: classes
|
||||
|
||||
classes: $(CLASSES:.java=.class)
|
||||
|
||||
run:
|
||||
$(EX) Main
|
||||
|
||||
clean:
|
||||
$(RM) *.class
|
||||
|
Loading…
Reference in New Issue
Block a user