From 424d969598e6cd0e7d6724d81af8afd5ee2e83a0 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 30 Apr 2021 12:13:27 +0200 Subject: [PATCH] Partial crosses fix + fix validMoves for Random Player + partial fix an issue when clicking on right bottom corner of (1,1) box, game think is (2, 2) --- .../control/WindowMouseListener.java | 4 ++-- .../model/player/AbstractPlayer.java | 2 +- src/battleship/view/Window.java | 23 +++++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/battleship/control/WindowMouseListener.java b/src/battleship/control/WindowMouseListener.java index 296ccd8..4b1c140 100644 --- a/src/battleship/control/WindowMouseListener.java +++ b/src/battleship/control/WindowMouseListener.java @@ -28,11 +28,11 @@ public class WindowMouseListener implements MouseListener { y -= initialHeight * 2; if(x >= initialWidth && x <= initialWidth * 11) { x -= initialWidth; - lastInput = new Pair<>(y / initialHeight, x / initialWidth); + lastInput = new Pair<>((y + 2) / initialHeight, (x + 2) / initialWidth); playerIdLastInput = 1; } else if(x >= initialHeight * 13 && x <= window.width) { x -= initialWidth * 13; - lastInput = new Pair<>(y / initialHeight, x / initialWidth); + lastInput = new Pair<>((y + 2) / initialHeight, (x + 2) / initialWidth); playerIdLastInput = 2; } } diff --git a/src/battleship/model/player/AbstractPlayer.java b/src/battleship/model/player/AbstractPlayer.java index bd39075..8bdff77 100644 --- a/src/battleship/model/player/AbstractPlayer.java +++ b/src/battleship/model/player/AbstractPlayer.java @@ -45,7 +45,7 @@ public abstract class AbstractPlayer implements Player { for(int x = 0; x < 10; x++){ for(int y = 0; y < 10; y++) { Pair coords = new Pair<>(x,y); - if(!moves.contains(new Triplet<>(coords, true)) || !moves.contains(new Triplet<>(coords, false))){ + if(!(moves.contains(new Triplet<>(coords, true)) || moves.contains(new Triplet<>(coords, false)))){ validMovesList.add(new Pair<>(x,y)); } } diff --git a/src/battleship/view/Window.java b/src/battleship/view/Window.java index 2a5155f..0d47f35 100644 --- a/src/battleship/view/Window.java +++ b/src/battleship/view/Window.java @@ -213,30 +213,33 @@ public class Window extends AbstractView { g.setColor(new Color(0, 0, 255)); break; } - g2d.fillRect(x1, y1, shipWidth, shipHeight); + g2d.fillRoundRect(x1 + 1, y1 + 1, shipWidth - 1, shipHeight - 1, 25, 25); } } for(int i = 1; i < 3; ++i) { Player player = game.players[i-1]; int halfBoxSizeWidth = initialWidth / 2; int halfBoxSizeHeight = initialHeight / 2; - int sqrt = (int) Math.sqrt(initialHeight * initialHeight + initialWidth * initialWidth); + float rectangleSize = initialWidth / 4f; + int sqrt = (int) Math.sqrt(initialHeight * initialHeight + initialWidth * initialWidth) - 10; for(Triplet move : player.getMoves()) { int x1 = (i == 1 ? initialWidth * 13 : initialWidth) + initialWidth * move.getMiddle(); - int y1 = initialHeight * 2 + initialHeight * move.getLeft(); - RoundRectangle2D rect = new RoundRectangle2D.Float(x1, y1, initialWidth / 4f, sqrt, 15, 15); + int y1 = initialHeight * 2 + initialHeight * move.getLeft() + 8; + RoundRectangle2D cross1 = new RoundRectangle2D.Float(x1, y1, rectangleSize, sqrt, 15, 15); + RoundRectangle2D cross2 = new RoundRectangle2D.Float(x1 + initialWidth - 9, y1 - 9, rectangleSize, sqrt, 15, 15); if(move.getRight()) { g.setColor(new Color(255, 0, 0)); } else { g.setColor(new Color(0, 123, 255)); } - g2d.rotate(Math.toRadians(45), x1, y1); - g2d.fill(rect); - // g2d.rotate(Math.toRadians(-45), x1, y1); - g2d.rotate(Math.toRadians(-90), x1 + halfBoxSizeWidth, y1 + halfBoxSizeHeight); - g2d.fill(rect); - g2d.rotate(Math.toRadians(90), x1 + halfBoxSizeWidth, y1 + halfBoxSizeHeight); g2d.rotate(Math.toRadians(-45), x1, y1); + g2d.fill(cross1); + g2d.rotate(Math.toRadians(45), x1, y1); + g2d.rotate(Math.toRadians(45), x1 + initialWidth - 9, y1 - 9); + g2d.fill(cross2); + g2d.rotate(Math.toRadians(-45), x1 + initialWidth - 9, y1 - 9); + + } } System.out.println(window);