TP
This commit is contained in:
BIN
DEV2.1/TP12/04_Trainee/ClicCase.class
Normal file
BIN
DEV2.1/TP12/04_Trainee/ClicCase.class
Normal file
Binary file not shown.
40
DEV2.1/TP12/04_Trainee/ClicCase.java
Normal file
40
DEV2.1/TP12/04_Trainee/ClicCase.java
Normal file
@@ -0,0 +1,40 @@
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class ClicCase implements MouseListener {
|
||||
|
||||
private JPanel[][] cases;
|
||||
private int[][] grille;
|
||||
private int caseX;
|
||||
private int caseY;
|
||||
|
||||
public ClicCase(JPanel[][] cases, int[][] grille, int caseX, int caseY) {
|
||||
this.cases = cases;
|
||||
this.grille = grille;
|
||||
this.caseX = caseX;
|
||||
this.caseY = caseY;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent evenement) {
|
||||
this.cases[this.caseX][this.caseY].setLayout(new GridLayout());
|
||||
this.cases[this.caseX][this.caseY].add(new Image());
|
||||
} // un bouton cliqué
|
||||
|
||||
public void mouseEntered(MouseEvent evenement) {
|
||||
|
||||
} // debut du survol
|
||||
|
||||
public void mouseExited(MouseEvent evenement) {
|
||||
|
||||
} // fin du survol
|
||||
|
||||
public void mousePressed(MouseEvent evenement) {
|
||||
|
||||
} // un bouton appuyé
|
||||
|
||||
public void mouseReleased(MouseEvent evenement) {
|
||||
|
||||
} // un bouton relâché
|
||||
|
||||
}
|
BIN
DEV2.1/TP12/04_Trainee/Fenetre.class
Normal file
BIN
DEV2.1/TP12/04_Trainee/Fenetre.class
Normal file
Binary file not shown.
29
DEV2.1/TP12/04_Trainee/Fenetre.java
Normal file
29
DEV2.1/TP12/04_Trainee/Fenetre.java
Normal file
@@ -0,0 +1,29 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
|
||||
public Fenetre() {
|
||||
this.setSize(500,500);
|
||||
this.setLocation(100,100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
this.setLayout(new GridLayout(10, 10));
|
||||
|
||||
JPanel[][] cases = new JPanel[10][10];
|
||||
int[][] grille = new int[10][10];
|
||||
|
||||
for (int i = 0; i != 10; i++) {
|
||||
for (int j = 0; j != 10; j++) {
|
||||
cases[i][j] = new JPanel();
|
||||
cases[i][j].setBackground(new Color(37, 150, 190));
|
||||
cases[i][j].setBorder(BorderFactory.createLineBorder(Color.WHITE));
|
||||
cases[i][j].addMouseListener(new ClicCase(cases, grille, i, j));
|
||||
this.add(cases[i][j]);
|
||||
|
||||
grille[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP12/04_Trainee/GestionGrille.class
Normal file
BIN
DEV2.1/TP12/04_Trainee/GestionGrille.class
Normal file
Binary file not shown.
35
DEV2.1/TP12/04_Trainee/GestionGrille.java
Normal file
35
DEV2.1/TP12/04_Trainee/GestionGrille.java
Normal file
@@ -0,0 +1,35 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class GestionGrille {
|
||||
|
||||
private int[][] grille;
|
||||
private Point[] coordsTrainee;
|
||||
private Point coordJoueur;
|
||||
|
||||
public GestionGrille(Point[] coordsTrainee, Point coordJoueur) {
|
||||
for (int i = 0; i != 10; i++) {
|
||||
for (int j = 0; j != 10; j++) {
|
||||
this.grille[i][j] = 0;
|
||||
}
|
||||
}
|
||||
this.coordsTrainee = coordsTrainee;
|
||||
this.coordJoueur = coordJoueur;
|
||||
}
|
||||
|
||||
public boolean deplacementPossible(Point destination) {
|
||||
if (this.coordJoueur.getX() == destination.getX()
|
||||
&& this.coordJoueur.getY() == destination.getY()-1) {
|
||||
return true;
|
||||
}
|
||||
else if (this.coordJoueur.getX() == destination.getX()
|
||||
&& this.coordJoueur.getY() == destination.getY()+1) {
|
||||
return true;
|
||||
}
|
||||
else if (this.coordJoueur.getX() == destination.getX()+1
|
||||
&& this.coordJoueur.getY() == destination.getY()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
13
DEV2.1/TP12/04_Trainee/Image.java
Normal file
13
DEV2.1/TP12/04_Trainee/Image.java
Normal file
@@ -0,0 +1,13 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Image extends JComponent {
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics pinceau) {
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
|
||||
Image img = Toolkit.getDefaultToolkit().getImage("vaisseau.png");
|
||||
secondPinceau.drawImage(img, 0, 0, this);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP12/04_Trainee/Main.class
Normal file
BIN
DEV2.1/TP12/04_Trainee/Main.class
Normal file
Binary file not shown.
6
DEV2.1/TP12/04_Trainee/Main.java
Normal file
6
DEV2.1/TP12/04_Trainee/Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP12/04_Trainee/vaisseau.png
Normal file
BIN
DEV2.1/TP12/04_Trainee/vaisseau.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 718 B |
Reference in New Issue
Block a user