Ajout visualisation de la case qui sera remplit

This commit is contained in:
Justine Yannis 2022-10-20 14:51:53 +02:00
parent 680a292faa
commit 3d3149a913
5 changed files with 56 additions and 3 deletions

View File

@ -29,8 +29,7 @@ Events = build/$(PACKAGE_PATH)/Event/GridChangedListener.class \
Model = build/$(PACKAGE_PATH)/Model/GrilleModel.class
Controller = build/$(PACKAGE_PATH)/Controller/GrilleMouseListener.class \
build/$(PACKAGE_PATH)/Controller/ModelEventListener.class \
build/$(PACKAGE_PATH)/Controller/Puissance4Controller.class
build/$(PACKAGE_PATH)/Controller/ModelEventListener.class
#------- Events ------

View File

@ -10,11 +10,23 @@ public class GrilleMouseListener extends MouseInputAdapter{
public GrilleMouseListener(Puissance4Controller p) {
this.controller = p;
}
@Override
public void mouseMoved(MouseEvent e) {
this.controller.hoverGrille(e.getX());
}
@Override
public void mousePressed(MouseEvent e) {
if(e.getButton() == MouseEvent.BUTTON1) {
this.controller.verifyColumn(e.getX());
this.controller.hoverGrille(e.getX());
}
}
@Override
public void mouseExited(MouseEvent e) {
this.controller.hoverGrille(-1);
}
}

View File

@ -31,7 +31,7 @@ public class Puissance4Controller {
ModelEventListener modelListener = new ModelEventListener(panel);
this.modele.addGridListener(modelListener);
this.grille.addMouseListener(mouseListener);
this.grille.addMouseMotionListener(mouseListener);
this.panel.init();
this.panel.changeLabel(this.modele.getPlayerTurn());
}
@ -54,7 +54,19 @@ public class Puissance4Controller {
}
}
public void hoverGrille(int x) {
if(this.modele.getGameStatus() == GameStatus.PLAYING) {
if(x == -1) {
this.grille.hover(-1); //Clean
return;
}
int column = (x * this.modele.getColumn() / grille.getWidth());
this.grille.hover(column);
}
}
public JPanel getPanel() {
return this.panel;
}
}

View File

@ -61,4 +61,21 @@ public class Grille extends JPanel{
this.repaint();
}
public void hover(int column) {
for(int x = 0; x < this.column; x++) {
for(int y = 0; y < this.row; y++) {
this.grille[x][y].setHover(false);
}
}
if(column != -1) {
for (int row = this.row - 1; row >= 0; row--) {
if (this.grille[column][row].getPlayer() == Constants.EMPTY_PLAYER) {
this.grille[column][row].setHover(true);
break;
}
}
}
this.repaint();
}
}

View File

@ -7,6 +7,7 @@ import fr.iutfbleau.projetAgile.Utils.Constants;
public class Pion extends JComponent{
private int player;
private boolean hover = false;
public static Dimension getPionMinimumSize() {
return new Dimension(80,80);
@ -31,6 +32,14 @@ public class Pion extends JComponent{
this.player = player;
}
public void setHover(boolean b) {
this.hover = b;
}
public int getPlayer() {
return this.player;
}
@Override
protected void paintComponent(Graphics g) {
Graphics g2 = g.create();
@ -46,6 +55,10 @@ public class Pion extends JComponent{
c = Constants.EMPTY_COLOR;
break;
}
if(this.hover) {
g2.setColor(Color.YELLOW);
g2.fillRect(0, 0, this.getWidth(), this.getHeight());
}
g2.setColor(c);
g2.fillOval(Constants.PIECE_MARGIN, Constants.PIECE_MARGIN, this.getWidth() - 2 * Constants.PIECE_MARGIN, this.getHeight() - 2 * Constants.PIECE_MARGIN);
}