From 4f4f2992295e7fa0237296cfa6ae31edf5c9081a Mon Sep 17 00:00:00 2001 From: botondborocz Date: Wed, 22 May 2024 11:26:05 +0200 Subject: [PATCH] Fixed some more issues --- src/main/java/GraphicsDesigner.java | 4 +++- src/main/java/Main.java | 1 - src/main/java/display/DisplayPipe.java | 6 +++--- src/main/java/model/Cistern.java | 9 ++++++--- src/main/java/model/Game.java | 9 ++++++--- src/main/java/model/Graphics.java | 2 +- src/main/java/model/Source.java | 5 ++++- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/java/GraphicsDesigner.java b/src/main/java/GraphicsDesigner.java index f275309..43f60cd 100644 --- a/src/main/java/GraphicsDesigner.java +++ b/src/main/java/GraphicsDesigner.java @@ -1,3 +1,5 @@ +import model.Game; + import javax.swing.*; import javax.swing.plaf.FontUIResource; import javax.swing.text.StyleContext; @@ -7,7 +9,7 @@ import java.util.Locale; public class GraphicsDesigner extends JFrame implements ActionListener { - //private Game game; + private Game game = new Game(); private CardLayout cardLayout; private JPanel cardPanel; private JButton bPlay; diff --git a/src/main/java/Main.java b/src/main/java/Main.java index acb565c..9c0d6ba 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -2,7 +2,6 @@ public class Main { public static void main(String[] args) { defaultMap(); // load initial map - //Test18(); Graphics graphics = new Graphics(); } diff --git a/src/main/java/display/DisplayPipe.java b/src/main/java/display/DisplayPipe.java index 48d8148..78fef7d 100644 --- a/src/main/java/display/DisplayPipe.java +++ b/src/main/java/display/DisplayPipe.java @@ -54,7 +54,7 @@ public class DisplayPipe extends DisplayField { /** * A kirajzolt cső szélessége. */ - final float displayWidth = 10; + static final float DISPLAYWIDTH = 10; /** * Kiszámolja a kirajzolt sokszög helyét. A cső két vége a következő helyeken lesz, a következő kritériumok alapján: @@ -92,7 +92,7 @@ private void calculatePolygon () { // lineTo -> lineFrom Vec2 directionVector = Vec2.normalize(Vec2.subtract(lineFrom, lineTo)); Vec2 normal = new Vec2(directionVector.getY() * -1, directionVector.getX()); // perpendicular to directionVector (still unit vector) - normal = Vec2.multiply(normal, displayWidth / 2); + normal = Vec2.multiply(normal, DISPLAYWIDTH / 2); Vec2 topLeft = Vec2.add(lineTo, normal); Vec2 bottomLeft = Vec2.subtract(lineTo, normal); @@ -206,7 +206,7 @@ protected void setPlayerIcons() { if(p.getPlayers().isEmpty()) return; Point c = getCenter(); - int dim = (int)displayWidth * 3; + int dim = (int)DISPLAYWIDTH * 3; Rectangle r = new Rectangle(c.x - dim / 2, c.y - dim / 2, dim, dim); playerIcons.add(new PlayerIcon(r, p.getPlayers().get(0))); } diff --git a/src/main/java/model/Cistern.java b/src/main/java/model/Cistern.java index ecb70cd..2525cfe 100644 --- a/src/main/java/model/Cistern.java +++ b/src/main/java/model/Cistern.java @@ -4,12 +4,15 @@ import java.security.SecureRandom; import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Felelossege, hogy eltarolja folyt-e bele viz a korben (mert ha igen, akkor pontot kapnak a szerelok). Emellett * tarolja, hogy van-e rajta meg fel nem vett pumpa, melyet a szerelok felvehetnek */ public class Cistern extends Field implements Periodic { + private static final Logger logger = Logger.getLogger("logger"); private final SecureRandom random = new SecureRandom(); /** * A bemeneti csove @@ -54,7 +57,7 @@ public void addNeighbor(Field p) { if(input != null) input.setNewWaterState(false); input = (Pipe) p; } catch(Exception e) { - System.out.print("Error casting field to pipe."); + logger.log(Level.WARNING, "Error casting field to pipe."); } } @@ -83,14 +86,14 @@ public void step() { spawnedPump = new Pump(); } } else { - System.out.println("Spawnoljon pumpa?"); + logger.log(Level.INFO, "Spawnoljon pumpa?"); Scanner scanner = new Scanner(System.in); String valasz = scanner.nextLine(); if (valasz.equals("Igen")) { spawnedPump = new Pump(); } if (!valasz.equals("Nem")) { - System.out.println("Helytelen valasz, ezert nem spawnolodik pumpa."); + logger.log(Level.WARNING, "Helytelen valasz, ezert nem spawnolodik pumpa."); } } } diff --git a/src/main/java/model/Game.java b/src/main/java/model/Game.java index 9ce2f2a..b353a9b 100644 --- a/src/main/java/model/Game.java +++ b/src/main/java/model/Game.java @@ -3,12 +3,15 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Tarolja a jatek mindenkori allapotat, iranyitja azt. Ebbe bele kell erteni a jatekosok listajanak jegyzeset, * a mezok szamontartasat, az eppen soron levo jatekos es a csapatok pontjainak szamontartasat */ public class Game implements Serializable { + private static final Logger logger = Logger.getLogger("logger"); static final int ROUND_BEGIN_ACTION_NUMBER = 3; /** * Az osztaly egyetlen peldanya @@ -214,13 +217,13 @@ public void movePipe(Pipe p, Field oldEnd, Field newEnd) { //the field that needs to be changed is not neighbouring if(!p.getNeighbours().contains(oldEnd)) { - System.out.println("Old end is not neighbour!!!!!!"); + logger.log(Level.WARNING, "Old end is not neighbour!!!!!!"); return; } //the field that needs to be plugged is already a neighbour if(p.getNeighbours().contains(newEnd)) { - System.out.println("New end is neighbour!!!!!!"); + logger.log(Level.WARNING, "New end is neighbour!!!!!!"); return; } @@ -234,7 +237,7 @@ public void movePipe(Pipe p, Field oldEnd, Field newEnd) { } this.actionTaken(); } - else System.out.println("New end is same as old end!!!!!!"); + else logger.log(Level.WARNING, "New end is same as old end!!!!!!"); } /** diff --git a/src/main/java/model/Graphics.java b/src/main/java/model/Graphics.java index 7644fd7..00a6875 100644 --- a/src/main/java/model/Graphics.java +++ b/src/main/java/model/Graphics.java @@ -15,7 +15,7 @@ import java.util.logging.Logger; public class Graphics extends JFrame { - private transient Logger logger; + private static final Logger logger = Logger.getLogger("logger"); /** * all the GUI elements */ diff --git a/src/main/java/model/Source.java b/src/main/java/model/Source.java index 0ba3da2..55459b8 100644 --- a/src/main/java/model/Source.java +++ b/src/main/java/model/Source.java @@ -3,11 +3,14 @@ import interfaces.Periodic; import java.io.Serializable; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Vegtelen vizforrasnak szamit. A kimeneten mindig folyik a viz */ public class Source extends Field implements Periodic, Serializable { + private static final Logger logger = Logger.getLogger("logger"); /** * A kimeneti csove */ @@ -37,7 +40,7 @@ public void addNeighbor(Field p) { try { output = (Pipe) p; } catch(Exception e) { - System.out.print("Error casting field to pipe."); + logger.log(Level.WARNING, "Error casting field to pipe."); } }