Improve WindowMouseListener.java
This commit is contained in:
parent
fb636c427e
commit
c8d2d5ae25
@ -1,5 +1,6 @@
|
|||||||
package battleship.control;
|
package battleship.control;
|
||||||
|
|
||||||
|
import battleship.utils.Pair;
|
||||||
import battleship.view.Window;
|
import battleship.view.Window;
|
||||||
|
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@ -15,8 +16,24 @@ public class WindowMouseListener implements MouseListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
int x = e.getX();
|
int x = e.getX() - 7;
|
||||||
int y = e.getY();
|
int y = e.getY() - 30;
|
||||||
|
int initialHeight = window.height / 12;
|
||||||
|
int initialWidth = window.width / 23;
|
||||||
|
if(y >= initialHeight * 2 && y <= window.height) {
|
||||||
|
y -= initialHeight * 2;
|
||||||
|
if(x >= initialWidth && x <= initialWidth * 11) {
|
||||||
|
x -= initialWidth;
|
||||||
|
System.out.println("Player 1");
|
||||||
|
Pair<Integer, Integer> location = new Pair<>(y / initialHeight, x / initialWidth);
|
||||||
|
System.out.println(location);
|
||||||
|
} else if(x >= initialHeight * 13 && x <= window.width) {
|
||||||
|
x -= initialWidth * 13;
|
||||||
|
System.out.println("Player 2");
|
||||||
|
Pair<Integer, Integer> location = new Pair<>(y / initialHeight, x / initialWidth);
|
||||||
|
System.out.println("location: " + location);
|
||||||
|
}
|
||||||
|
}
|
||||||
System.out.println("(" + x + ", " + y + ")");
|
System.out.println("(" + x + ", " + y + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,10 +32,10 @@ public class Window extends AbstractView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setShips(Player player) {
|
public void setShips(Player player) {
|
||||||
upperText = "Placez votre navire joueur " + player.getId();
|
|
||||||
if(player instanceof Human) {
|
if(player instanceof Human) {
|
||||||
for(int i : shipsSize) {
|
for(int i : shipsSize) {
|
||||||
upperText += "Placez votre premier navire de taille " + i + " à l'aide de la souris";
|
upperText = "joueur " + player.getId() + ", Placez votre premier navire de taille " + i + " à l'aide de la souris";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -82,7 +82,6 @@ public class Window extends AbstractView {
|
|||||||
g.drawLine(initialWidth, ordonnee, initialWidth * 11, ordonnee);
|
g.drawLine(initialWidth, ordonnee, initialWidth * 11, ordonnee);
|
||||||
g.drawLine(initialWidth * 13, ordonnee, width - 4, ordonnee);
|
g.drawLine(initialWidth * 13, ordonnee, width - 4, ordonnee);
|
||||||
}
|
}
|
||||||
// TODO: 12/04/2021 Dessiner les navires
|
|
||||||
|
|
||||||
for(int i = 1; i < 3; ++i) {
|
for(int i = 1; i < 3; ++i) {
|
||||||
Player player = game.players[i-1];
|
Player player = game.players[i-1];
|
||||||
|
Loading…
Reference in New Issue
Block a user