Ajout de la rotation d'une tuile
This commit is contained in:
@@ -5,6 +5,7 @@ import fr.monkhanny.dorfromantik.listeners.GameZoomListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameArrowKeyListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameSpaceKeyListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameMouseClickListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameMouseWheelListener;
|
||||
import fr.monkhanny.dorfromantik.Options;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -54,6 +55,8 @@ public class Board extends JPanel{
|
||||
// Ajouter un écouteur de clavier pour déplacer le plateau
|
||||
gameFrame.addKeyListener(new GameArrowKeyListener(this));
|
||||
gameFrame.setFocusable(true);
|
||||
|
||||
this.addMouseWheelListener(new GameMouseWheelListener(this));
|
||||
|
||||
|
||||
gameFrame.addKeyListener(new GameSpaceKeyListener(this));
|
||||
@@ -70,6 +73,10 @@ public class Board extends JPanel{
|
||||
|
||||
}
|
||||
|
||||
public Tile getNextTile() {
|
||||
return nextTile;
|
||||
}
|
||||
|
||||
public void handleSpaceKeyPress() {
|
||||
// Calculer les dimensions totales du plateau (largeur et hauteur des tuiles)
|
||||
int totalWidth = 0;
|
||||
|
@@ -0,0 +1,24 @@
|
||||
package fr.monkhanny.dorfromantik.listeners;
|
||||
|
||||
import fr.monkhanny.dorfromantik.game.Board;
|
||||
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
|
||||
public class GameMouseWheelListener implements MouseWheelListener {
|
||||
private Board board;
|
||||
|
||||
// Constructeur de la classe
|
||||
public GameMouseWheelListener(Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
if (board.getNextTile() != null) {
|
||||
boolean clockwise = e.getWheelRotation() < 0; // Si la molette va vers le haut, rotation horaire
|
||||
board.getNextTile().rotate(clockwise); // Applique la rotation sur la tuile
|
||||
board.repaint();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user