diff --git a/src/main/java/Assets/Strings.java b/src/main/java/Assets/Strings.java new file mode 100644 index 0000000..1cffdb0 --- /dev/null +++ b/src/main/java/Assets/Strings.java @@ -0,0 +1,33 @@ +package Assets; + +public class Strings { + public final static String WRONG_ATTR = "wrong attribute name"; + public final static String WRONG_PIPE = "wrong pipe name"; + public final static String WRONG_PLAYER = "wrong player name"; + public final static String WRONG_MECH = "wrong mechanic name"; + public final static String FELL_DOWN_STR = "fellDown"; + public final static String STUCK_STR = "stuck"; + public final static String STANDING_ON_STR = "standingOn"; + public final static String STATE_STR = "state"; + public final static String HELD_ITEMS_STR = "heldItems"; + public final static String PIPES_STR = "pipes"; + public final static String CREATED_PICKUPABLES_STR = "createdPickupables"; + public final static String PLAYERS_STR = "players"; + public final static String SABOTEUR_POINTS_STR = "saboteurPoints"; + public final static String MECHANIC_POINTS_STR = "mechanicPoints"; + public final static String POINTS_TO_WIN_STR = "pointsToWin"; + public final static String MOVE_ACTION_STR = "moveAction"; + public final static String SPECIAL_ACTION_STR = "specialAction"; + public final static String TURN_OVER_STR = "turnOver"; + public final static String BROKEN_STR = "broken"; + public final static String WATER_CAPACITY_STR = "waterCapacity"; + public final static String HELD_WATER_STR = "heldWater"; + public final static String MAXIMUM_PIPES_STR = "maximumPipes"; + public final static String ACTIVE_IN_STR = "activeIn"; + public final static String ACTIVE_OUT_STR = "activeOut"; + public final static String READY_TO_PIERCE_STR = "readyToPierce"; + public final static String LUBRICATED_STR = "lubricated"; + public final static String GLUED_STR = "glued"; + public final static String BEING_HELD_STR = "beingHeld"; + public final static String NODES_STR = "nodes"; +} diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index 76e7877..133ff1f 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -1,5 +1,6 @@ package Controller; +import static Assets.Strings.*; import Model.*; import View.*; @@ -10,6 +11,7 @@ import java.util.LinkedList; import java.util.Map; + /** * A modell és a view egymással való működésében segít, a control funkciót látja el, singleton osztály */ @@ -28,35 +30,7 @@ static public Controller getInstance() { return controller; } - final static String WrongAttr = "wrong attribute name"; - final static String WrongPipe = "wrong pipe name"; - final static String WrongPlayer = "wrong player name"; - final static String WrongMech = "wrong mechanic name"; - final static String fellDownStr = "fellDown"; - final static String stuckStr = "stuck"; - final static String standingOnStr = "standingOn"; - final static String stateStr = "state"; - final static String heldItemsStr = "heldItems"; - final static String pipesStr = "pipes"; - final static String createdPickupablesStr = "createdPickupables"; - final static String playersStr = "players"; - final static String saboteurPointsStr = "saboteurPoints"; - final static String mechanicPointsStr = "mechanicPoints"; - final static String pointsToWinStr = "pointsToWin"; - final static String moveActionStr = "moveAction"; - final static String specialActionStr = "specialAction"; - final static String turnOverStr = "turnOver"; - final static String brokenStr = "broken"; - final static String waterCapacityStr = "waterCapacity"; - final static String heldWaterStr = "heldWater"; - final static String maximumPipesStr = "maximumPipes"; - final static String activeInStr = "activeIn"; - final static String activeOutStr = "activeOut"; - final static String readyToPierceStr = "readyToPierce"; - final static String lubricatedStr = "lubricated"; - final static String gluedStr = "glued"; - final static String beingHeldStr = "beingHeld"; - final static String nodesStr = "nodes"; + /** * Játék elkezdését mutató boolean */ @@ -241,7 +215,7 @@ public void create(String name, String type,int x, int y) { pumps.add(pump); pickupables.add(pump); objectCatalog.put(name, pump); - PumpView pumpView = new PumpView(x,y,25,pump,null,gameView); + PumpView pumpView = new PumpView(x,y,25,pump, gameView); gameView.addPumpView(pumpView); } case "spring" -> { @@ -282,7 +256,7 @@ public void create(String name, String type,int x, int y) { public void connect(String pipeName, String wNodeName) { if (!pipes.contains((Pipe)objectCatalog.get(pipeName))) { - IO_Manager.writeError(WrongPipe, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PIPE, Controller.filetoWrite != null); return; } Pipe p = (Pipe) objectCatalog.get(pipeName); @@ -308,7 +282,7 @@ public void connect(String pipeName, String wNodeName) { public void move(String playerName, String steppableName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PLAYER, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); @@ -339,7 +313,7 @@ public void move(String playerName, String steppableName) { public void pierce(String playerName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PLAYER, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); @@ -356,7 +330,7 @@ public void pierce(String playerName) { public void glue(String playerName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PLAYER, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); @@ -391,7 +365,7 @@ public void lubricate(String saboteurName) { public void repair(String mechanicName) { if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { - IO_Manager.writeError(WrongMech, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_MECH, Controller.filetoWrite != null); return; } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); @@ -414,19 +388,19 @@ public void repair(String mechanicName) { public void redirect(String playerName, String inPipeName, String outPipeName) { if (!players.contains((Player) objectCatalog.get(playerName))) { - IO_Manager.writeError(WrongPlayer, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PLAYER, Controller.filetoWrite != null); return; } Player p = (Player) objectCatalog.get(playerName); if (!pipes.contains((Pipe)objectCatalog.get(inPipeName))) { - IO_Manager.writeError(WrongPipe, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PIPE, Controller.filetoWrite != null); return; } Pipe in = (Pipe) objectCatalog.get(inPipeName); if (!pipes.contains((Pipe)objectCatalog.get(outPipeName))) { - IO_Manager.writeError(WrongPipe, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_PIPE, Controller.filetoWrite != null); return; } Pipe out = (Pipe) objectCatalog.get(outPipeName); @@ -446,7 +420,7 @@ public void redirect(String playerName, String inPipeName, String outPipeName) { public void pickup(String mechanicName, String pickupName) { if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { - IO_Manager.writeError(WrongMech, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_MECH, Controller.filetoWrite != null); return; } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); @@ -470,7 +444,7 @@ public void pickup(String mechanicName, String pickupName) { public void placedown(String mechanicName) { if (!mechanics.contains((Mechanic) objectCatalog.get(mechanicName))) { - IO_Manager.writeError(WrongMech, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_MECH, Controller.filetoWrite != null); return; } Mechanic m = (Mechanic) objectCatalog.get(mechanicName); @@ -489,65 +463,65 @@ public void stateGet(String objectName, String attribName) { Object o = objectCatalog.get(objectName); if (mechanics.contains((Mechanic) objectCatalog.get(objectName))) { switch (attribName) { - case fellDownStr -> output += Boolean.toString(((Mechanic) o).isFellDown()); - case stuckStr -> output += Boolean.toString(((Mechanic) o).isStuck()); - case standingOnStr -> output += getObjectName(((Mechanic) o).getStandingOn()); - case stateStr -> output += getObjectName(((Mechanic) o).getState()); - case heldItemsStr -> output += getObjectName(((Mechanic) o).getHeldItems()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case FELL_DOWN_STR -> output += Boolean.toString(((Mechanic) o).isFellDown()); + case STUCK_STR -> output += Boolean.toString(((Mechanic) o).isStuck()); + case STANDING_ON_STR -> output += getObjectName(((Mechanic) o).getStandingOn()); + case STATE_STR -> output += getObjectName(((Mechanic) o).getState()); + case HELD_ITEMS_STR -> output += getObjectName(((Mechanic) o).getHeldItems()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (saboteurs.contains((Saboteur) objectCatalog.get(objectName))) { switch (attribName) { - case fellDownStr -> output += Boolean.toString(((Saboteur) o).isFellDown()); - case stuckStr -> output += Boolean.toString(((Saboteur) o).isStuck()); - case standingOnStr -> output += getObjectName(((Saboteur) o).getStandingOn()); - case stateStr -> output += getObjectName(((Saboteur) o).getState()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case FELL_DOWN_STR -> output += Boolean.toString(((Saboteur) o).isFellDown()); + case STUCK_STR -> output += Boolean.toString(((Saboteur) o).isStuck()); + case STANDING_ON_STR -> output += getObjectName(((Saboteur) o).getStandingOn()); + case STATE_STR -> output += getObjectName(((Saboteur) o).getState()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (cisterns.contains((Cistern) objectCatalog.get(objectName))) { switch (attribName) { - case createdPickupablesStr -> output += listWrite(((Cistern) o).getCreatedPickupables()); - case pipesStr -> output += listWrite(((Cistern) o).getPipes()); - case playersStr -> output += listWrite(((Cistern) o).getPlayers()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case CREATED_PICKUPABLES_STR -> output += listWrite(((Cistern) o).getCreatedPickupables()); + case PIPES_STR -> output += listWrite(((Cistern) o).getPipes()); + case PLAYERS_STR -> output += listWrite(((Cistern) o).getPlayers()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (springs.contains((Spring) objectCatalog.get(objectName))) { switch (attribName) { - case pipesStr -> output += listWrite(((Spring) o).getPipes()); - case playersStr -> output += listWrite(((Spring) o).getPlayers()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case PIPES_STR -> output += listWrite(((Spring) o).getPipes()); + case PLAYERS_STR -> output += listWrite(((Spring) o).getPlayers()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (pumps.contains((Pump) objectCatalog.get(objectName))) { switch (attribName) { - case brokenStr -> output += Boolean.toString(((Pump) o).isBroken()); - case waterCapacityStr -> output += Integer.toString(((Pump) o).getWaterCapacity()); - case heldWaterStr -> output += Integer.toString(((Pump) o).getHeldWater()); - case maximumPipesStr -> output += Integer.toString(((Pump) o).getMaximumPipes()); - case activeInStr -> output += getObjectName(((Pump) o).getActiveIn()); - case activeOutStr -> output += getObjectName(((Pump) o).getActiveOut()); - case pipesStr -> output += listWrite(((Pump) o).getPipes()); - case playersStr -> output += listWrite(((Pump) o).getPlayers()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case BROKEN_STR -> output += Boolean.toString(((Pump) o).isBroken()); + case WATER_CAPACITY_STR -> output += Integer.toString(((Pump) o).getWaterCapacity()); + case HELD_WATER_STR -> output += Integer.toString(((Pump) o).getHeldWater()); + case MAXIMUM_PIPES_STR -> output += Integer.toString(((Pump) o).getMaximumPipes()); + case ACTIVE_IN_STR -> output += getObjectName(((Pump) o).getActiveIn()); + case ACTIVE_OUT_STR -> output += getObjectName(((Pump) o).getActiveOut()); + case PIPES_STR -> output += listWrite(((Pump) o).getPipes()); + case PLAYERS_STR -> output += listWrite(((Pump) o).getPlayers()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (pipes.contains((Pipe) objectCatalog.get(objectName))) { switch (attribName) { - case brokenStr -> output += Boolean.toString(((Pipe) o).isBroken()); - case waterCapacityStr -> output += Integer.toString(((Pipe) o).getWaterCapacity()); - case heldWaterStr -> output += Integer.toString(((Pipe) o).getHeldWater()); - case readyToPierceStr -> output += Boolean.toString(((Pipe) o).isReadyToPierce()); - case lubricatedStr -> output += Boolean.toString(((Pipe) o).isLubricated()); - case gluedStr -> output += Boolean.toString(((Pipe) o).isGlued()); - case beingHeldStr -> output += Boolean.toString(((Pipe) o).isBeingHeld()); - case nodesStr -> output += listWrite(((Pipe) o).getNodes()); - case playersStr -> output += listWrite(((Pipe) o).getPlayers()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case BROKEN_STR -> output += Boolean.toString(((Pipe) o).isBroken()); + case WATER_CAPACITY_STR -> output += Integer.toString(((Pipe) o).getWaterCapacity()); + case HELD_WATER_STR -> output += Integer.toString(((Pipe) o).getHeldWater()); + case READY_TO_PIERCE_STR -> output += Boolean.toString(((Pipe) o).isReadyToPierce()); + case LUBRICATED_STR -> output += Boolean.toString(((Pipe) o).isLubricated()); + case GLUED_STR -> output += Boolean.toString(((Pipe) o).isGlued()); + case BEING_HELD_STR -> output += Boolean.toString(((Pipe) o).isBeingHeld()); + case NODES_STR -> output += listWrite(((Pipe) o).getNodes()); + case PLAYERS_STR -> output += listWrite(((Pipe) o).getPlayers()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (objectName.equals("counter")) { switch (attribName) { - case saboteurPointsStr -> output += Integer.toString(PointCounter.getInstance().getSaboteurPoints()); - case mechanicPointsStr -> output += Integer.toString(PointCounter.getInstance().getMechanicPoints()); - case pointsToWinStr -> output += Integer.toString(PointCounter.getInstance().getPointsToWin()); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case SABOTEUR_POINTS_STR -> output += Integer.toString(PointCounter.getInstance().getSaboteurPoints()); + case MECHANIC_POINTS_STR -> output += Integer.toString(PointCounter.getInstance().getMechanicPoints()); + case POINTS_TO_WIN_STR -> output += Integer.toString(PointCounter.getInstance().getPointsToWin()); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else { IO_Manager.writeError("wrong object name", Controller.filetoWrite != null); @@ -566,40 +540,40 @@ public void stateSet(String objectName, String attribName, String attribValue) { Object o = objectCatalog.get(objectName); if (mechanics.contains((Mechanic) objectCatalog.get(objectName))) { switch (attribName) { - case fellDownStr: + case FELL_DOWN_STR: ((Mechanic) o).setFellDown(Boolean.parseBoolean(attribValue)); break; - case stuckStr: + case STUCK_STR: ((Mechanic) o).setStuck(Boolean.parseBoolean(attribValue)); break; - case stateStr: + case STATE_STR: switch (attribValue) { - case moveActionStr -> ((Mechanic) o).setState(PlayerActionState.MOVE_ACTION); - case specialActionStr -> ((Mechanic) o).setState(PlayerActionState.SPECIAL_ACTION); - case turnOverStr -> ((Mechanic) o).setState(PlayerActionState.TURN_OVER); + case MOVE_ACTION_STR -> ((Mechanic) o).setState(PlayerActionState.MOVE_ACTION); + case SPECIAL_ACTION_STR -> ((Mechanic) o).setState(PlayerActionState.SPECIAL_ACTION); + case TURN_OVER_STR -> ((Mechanic) o).setState(PlayerActionState.TURN_OVER); } break; default: - IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (saboteurs.contains((Saboteur) objectCatalog.get(objectName))) { switch (attribName) { - case fellDownStr: + case FELL_DOWN_STR: ((Saboteur) o).setFellDown(Boolean.parseBoolean(attribValue)); break; - case stuckStr: + case STUCK_STR: ((Saboteur) o).setStuck(Boolean.parseBoolean(attribValue)); break; - case stateStr: + case STATE_STR: switch (attribValue) { - case moveActionStr -> ((Saboteur) o).setState(PlayerActionState.MOVE_ACTION); - case specialActionStr -> ((Saboteur) o).setState(PlayerActionState.SPECIAL_ACTION); - case turnOverStr -> ((Saboteur) o).setState(PlayerActionState.TURN_OVER); + case MOVE_ACTION_STR -> ((Saboteur) o).setState(PlayerActionState.MOVE_ACTION); + case SPECIAL_ACTION_STR -> ((Saboteur) o).setState(PlayerActionState.SPECIAL_ACTION); + case TURN_OVER_STR -> ((Saboteur) o).setState(PlayerActionState.TURN_OVER); } break; default: - IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (cisterns.contains((Cistern) objectCatalog.get(objectName))) { IO_Manager.writeError("no attribute to set", Controller.filetoWrite != null); @@ -607,30 +581,30 @@ public void stateSet(String objectName, String attribName, String attribValue) { IO_Manager.writeError("no attribute to set", Controller.filetoWrite != null); } else if (pumps.contains((Pump) objectCatalog.get(objectName))) { switch (attribName) { - case brokenStr -> ((Pump) o).setBroken(Boolean.parseBoolean(attribValue)); - case waterCapacityStr -> ((Pump) o).setWaterCapacity(Integer.parseInt(attribValue)); - case heldWaterStr -> ((Pump) o).setHeldWater(Integer.parseInt(attribValue)); - case maximumPipesStr -> ((Pump) o).setMaximumPipes(Integer.parseInt(attribValue)); - case activeInStr -> { + case BROKEN_STR -> ((Pump) o).setBroken(Boolean.parseBoolean(attribValue)); + case WATER_CAPACITY_STR -> ((Pump) o).setWaterCapacity(Integer.parseInt(attribValue)); + case HELD_WATER_STR -> ((Pump) o).setHeldWater(Integer.parseInt(attribValue)); + case MAXIMUM_PIPES_STR -> ((Pump) o).setMaximumPipes(Integer.parseInt(attribValue)); + case ACTIVE_IN_STR -> { if (pipes.contains((Pipe) objectCatalog.get(attribValue))) ((Pump) o).setActiveIn((Pipe) objectCatalog.get(attribValue)); } - case activeOutStr -> { + case ACTIVE_OUT_STR -> { if (pipes.contains((Pipe) objectCatalog.get(attribValue))) ((Pump) o).setActiveOut((Pipe) objectCatalog.get(attribValue)); } - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else if (pipes.contains((Pipe) objectCatalog.get(objectName))) { switch (attribName) { - case brokenStr -> ((Pipe) o).setBroken(Boolean.parseBoolean(attribValue)); - case waterCapacityStr -> ((Pipe) o).setWaterCapacity(Integer.parseInt(attribValue)); - case heldWaterStr -> ((Pipe) o).setHeldWater(Integer.parseInt(attribValue)); - case readyToPierceStr -> ((Pipe) o).setReadyToPierce(Boolean.parseBoolean(attribValue)); - case lubricatedStr -> ((Pipe) o).setLubricated(Boolean.parseBoolean(attribValue)); - case gluedStr -> ((Pipe) o).setGlued(Boolean.parseBoolean(attribValue)); - case beingHeldStr -> ((Pipe) o).setBeingHeld(Boolean.parseBoolean(attribValue)); - default -> IO_Manager.writeError(WrongAttr, Controller.filetoWrite != null); + case BROKEN_STR -> ((Pipe) o).setBroken(Boolean.parseBoolean(attribValue)); + case WATER_CAPACITY_STR -> ((Pipe) o).setWaterCapacity(Integer.parseInt(attribValue)); + case HELD_WATER_STR -> ((Pipe) o).setHeldWater(Integer.parseInt(attribValue)); + case READY_TO_PIERCE_STR -> ((Pipe) o).setReadyToPierce(Boolean.parseBoolean(attribValue)); + case LUBRICATED_STR -> ((Pipe) o).setLubricated(Boolean.parseBoolean(attribValue)); + case GLUED_STR -> ((Pipe) o).setGlued(Boolean.parseBoolean(attribValue)); + case BEING_HELD_STR -> ((Pipe) o).setBeingHeld(Boolean.parseBoolean(attribValue)); + default -> IO_Manager.writeError(WRONG_ATTR, Controller.filetoWrite != null); } } else { IO_Manager.writeError("wrong object name", Controller.filetoWrite != null); diff --git a/src/main/java/Model/Cistern.java b/src/main/java/Model/Cistern.java index 25166d0..89ffbe4 100644 --- a/src/main/java/Model/Cistern.java +++ b/src/main/java/Model/Cistern.java @@ -15,15 +15,15 @@ public class Cistern extends WaterNode implements Serializable { /** * Ciszternáról felvehető elemek, amik generálódtak rajta */ - private LinkedList createdPickupables = new LinkedList<>(); + private final LinkedList createdPickupables = new LinkedList<>(); /** * Ciszternán keletkezett csövek listája */ - private LinkedList generatedPipes = new LinkedList<>(); + private final LinkedList generatedPipes = new LinkedList<>(); /** * Ciszternán keletkezett pumpák listája */ - private LinkedList generatedPumps = new LinkedList<>(); + private final LinkedList generatedPumps = new LinkedList<>(); /** * Pontszámításhoz használt singleton @@ -176,8 +176,10 @@ public boolean canPlaceDown(Mechanic m){ public boolean canMoveFromHere() { boolean canMove=false; for(Pipe p:pipes){ - if(p.players.isEmpty() && !generatedPipes.contains(p)) - canMove=true; + if (p.players.isEmpty() && !generatedPipes.contains(p)) { + canMove = true; + break; + } } return canMove; } diff --git a/src/main/java/Model/Pipe.java b/src/main/java/Model/Pipe.java index 91b7341..5d71634 100644 --- a/src/main/java/Model/Pipe.java +++ b/src/main/java/Model/Pipe.java @@ -211,6 +211,17 @@ public boolean placedDownTo(Pipe pickup) { return false; } + private Pipe setPipesAttr(Pipe newPipe){ + newPipe.waterCapacity = this.waterCapacity; + newPipe.heldWater = this.heldWater; + newPipe.broken = this.broken; + newPipe.readyToPierce = this.readyToPierce; + newPipe.lubricated = this.lubricated; + newPipe.glued = this.glued; + newPipe.beingHeld = this.beingHeld; + newPipe.readyToPierceTimer = this.readyToPierceTimer; + return newPipe; + } /** * Akkor hívódik meg, amikor egy pumpát a szerelő lehelyez * a csőre, a kettévágást kezeli. @@ -266,23 +277,9 @@ public void cutInHalf(Pump pump) { if (node2activeOut == this) node2.setActiveOut(newPipe2); - newPipe1.waterCapacity=this.waterCapacity; - newPipe1.heldWater=this.heldWater; - newPipe1.broken= this.broken; - newPipe1.readyToPierce=this.readyToPierce; - newPipe1.lubricated=this.lubricated; - newPipe1.glued=this.glued; - newPipe1.beingHeld= this.beingHeld; - newPipe1.readyToPierceTimer=this.readyToPierceTimer; - - newPipe2.waterCapacity=this.waterCapacity; - newPipe2.heldWater=this.heldWater; - newPipe2.broken= this.broken; - newPipe2.readyToPierce=this.readyToPierce; - newPipe2.lubricated=this.lubricated; - newPipe2.glued=this.glued; - newPipe2.beingHeld= this.beingHeld; - newPipe2.readyToPierceTimer=this.readyToPierceTimer; + newPipe1 = setPipesAttr(newPipe1); + + newPipe2 = setPipesAttr(newPipe2); boolean ignoreStates = Player.isIgnoreStates(); Player.setIgnoreStates(true); @@ -293,7 +290,7 @@ public void cutInHalf(Pump pump) { Controller.getInstance().getGameView().remove(Controller.getInstance().getGameView().getPipeViewByCorrespondingModel(this)); Controller.getInstance().getGameView().remove(Controller.getInstance().getGameView().getDrawableByCorrespondingModel(pump)); - PumpView pumpView = new PumpView(x,y,25,pump,null,Controller.getInstance().getGameView()); + PumpView pumpView = new PumpView(x,y,25,pump, Controller.getInstance().getGameView()); Controller.getInstance().getGameView().addPumpView(pumpView); PipeView pipeView1 = new PipeView( diff --git a/src/main/java/Model/Pump.java b/src/main/java/Model/Pump.java index 4431fa4..a5c6702 100644 --- a/src/main/java/Model/Pump.java +++ b/src/main/java/Model/Pump.java @@ -122,10 +122,9 @@ public void waterFlow() { if (broken) { IO_Manager.writeInfo(controller.getObjectName(this) + " is broken", controller.filetoWrite != null); } - int gained=0; if(!broken && heldWater != 0 && activeOut != null) { - gained= activeOut.gainWater(1); + int gained = activeOut.gainWater(1); if(gained==1){ heldWater--; } diff --git a/src/main/java/Model/Spring.java b/src/main/java/Model/Spring.java index f011665..addc7eb 100644 --- a/src/main/java/Model/Spring.java +++ b/src/main/java/Model/Spring.java @@ -100,7 +100,7 @@ public void waterFlow() { */ @Override public boolean addPipe(Pipe p) { - boolean valid = pipes.size() < 1; + boolean valid = pipes.isEmpty(); if (valid) pipes.add(p); else diff --git a/src/main/java/Model/WaterNode.java b/src/main/java/Model/WaterNode.java index 2cfa186..021f35a 100644 --- a/src/main/java/Model/WaterNode.java +++ b/src/main/java/Model/WaterNode.java @@ -23,7 +23,7 @@ public abstract class WaterNode extends Steppable implements Serializable { @Override public boolean playerEnter(Player player) { - boolean successful = pipes.contains(player.getStandingOn()) || player.getStandingOn() == null; + boolean successful = pipes.contains((Pipe) player.getStandingOn()) || player.getStandingOn() == null; if (successful) players.add(player); else @@ -101,8 +101,10 @@ public LinkedList getPipes() { public boolean canMoveFromHere() { boolean canMove=false; for(Pipe p:pipes){ - if(p.players.isEmpty()) - canMove=true; + if (p.players.isEmpty()) { + canMove = true; + break; + } } return canMove; } @@ -114,6 +116,6 @@ public boolean canMoveFromHere() { */ @Override public boolean canMoveToHere(Player p){ - return pipes.contains(p.getStandingOn()); + return pipes.contains((Pipe) p.getStandingOn()); } } diff --git a/src/main/java/View/AddPlayerButton.java b/src/main/java/View/AddPlayerButton.java index 59b9ebd..54b3c8b 100644 --- a/src/main/java/View/AddPlayerButton.java +++ b/src/main/java/View/AddPlayerButton.java @@ -42,13 +42,6 @@ public void clickAction(MouseEvent e) { // karakter nevének és színének megadása cc = new CharacterCreation(temp, name); } - - } else if (type == -1) { - if (name.equals("mechanic")) { - - } else if (name.equals("saboteur")) { - - } } diff --git a/src/main/java/View/CharacterCreation.java b/src/main/java/View/CharacterCreation.java index 4f62b7e..5adcb3d 100644 --- a/src/main/java/View/CharacterCreation.java +++ b/src/main/java/View/CharacterCreation.java @@ -20,7 +20,7 @@ public class CharacterCreation { - private ColorPicker characterCreationPanel; + private final ColorPicker characterCreationPanel; /** * constructor - creates the frame and sets up the layout (a color picker, a text field for the player's name, and a button for saving the data and return to the main menu) diff --git a/src/main/java/View/CisternView.java b/src/main/java/View/CisternView.java index 31fd20b..6f80ba3 100644 --- a/src/main/java/View/CisternView.java +++ b/src/main/java/View/CisternView.java @@ -17,7 +17,7 @@ public class CisternView extends Drawable implements Clickable, CreatePopUpBar, private final Cistern cistern; private final int r; private GameView gameView = null; - private BufferedImage sprite = null; + private BufferedImage sprite; /** * CisternView konstruktor @@ -106,13 +106,8 @@ public Point getRotationCenter() { * @param p - játékos * @return - játékos szöge */ - @Override public double getPlayerAngle(Player p) { - double[] angles = new double[cistern.getPlayers().size()]; - for (int i = 0; i < angles.length; ++i) { - angles[i] = i * 20 - (angles.length - 1) * 10; - } - return angles[cistern.getPlayers().indexOf(p)]; + return super.getPlayerAngle(p, cistern.getPlayers()); } @Override diff --git a/src/main/java/View/Clickable.java b/src/main/java/View/Clickable.java index 5dcc660..46635fe 100644 --- a/src/main/java/View/Clickable.java +++ b/src/main/java/View/Clickable.java @@ -12,17 +12,17 @@ public interface Clickable { * @return - igaz, ha a kattintható objektumon belül van az egér */ - public boolean isIn(MouseEvent e); + boolean isIn(MouseEvent e); /** * clickAction - kattintás eseménye * @param e - egérkattintás */ - public void clickAction(MouseEvent e); + void clickAction(MouseEvent e); /** * isDraggable - megadja, hogy a kattintható objektum húzható-e * @return - igaz, ha mozgatható */ - public boolean isDraggable(); + boolean isDraggable(); } diff --git a/src/main/java/View/ColorPicker.java b/src/main/java/View/ColorPicker.java index 8803571..1bbc99f 100644 --- a/src/main/java/View/ColorPicker.java +++ b/src/main/java/View/ColorPicker.java @@ -42,8 +42,7 @@ * Java Color Picker */ public class ColorPicker extends JPanel { - private JColorChooser tcc; - private JTextField userName; + private final JColorChooser tcc; /** * constructor - creates a text field for the username, a color picker area @@ -52,7 +51,7 @@ public ColorPicker() { super(new BorderLayout()); // creating a text field for the player's name - userName = new JTextField("User"); + JTextField userName = new JTextField("User"); userName.setBounds(new Rectangle(300, 100)); JPanel userNamePanel = new JPanel(new BorderLayout()); userNamePanel.setBorder(BorderFactory.createTitledBorder("Username:")); diff --git a/src/main/java/View/CreatePopUpBar.java b/src/main/java/View/CreatePopUpBar.java index aeb9f03..bc95541 100644 --- a/src/main/java/View/CreatePopUpBar.java +++ b/src/main/java/View/CreatePopUpBar.java @@ -16,7 +16,7 @@ public interface CreatePopUpBar { * @param view - ablak * @param creator - létrehozó */ - public default void createPopUpBar(int x, int y, int r, Window view, SteppableView creator){ + default void createPopUpBar(int x, int y, int r, Window view, SteppableView creator){ GameView gameView = (GameView) view; PopUpBar p = new PopUpBar(x, y, r, view, creator, null); @@ -24,8 +24,10 @@ public default void createPopUpBar(int x, int y, int r, Window view, SteppableVi boolean notNull = false; for (ActionType a : Controller.getInstance().getActivePlayer().availableActions(creator.getCorrespondingModelSteppable())) { - if (a != null) + if (a != null) { notNull = true; + break; + } } if (!notNull) gameView.removePopUpBar(); @@ -41,7 +43,7 @@ public default void createPopUpBar(int x, int y, int r, Window view, SteppableVi * @param creator - létrehozó * @param at - akciók */ - public default void createPopUpBarWithActions(int x, int y, int r, Window view, SteppableView creator, ActionType[] at) { + default void createPopUpBarWithActions(int x, int y, int r, Window view, SteppableView creator, ActionType[] at) { GameView gameView = (GameView) view; PopUpBar p = new PopUpBar(x, y, r, view, creator, at); gameView.addCisternDisplay(p); diff --git a/src/main/java/View/Drawable.java b/src/main/java/View/Drawable.java index e7ec078..7de8704 100644 --- a/src/main/java/View/Drawable.java +++ b/src/main/java/View/Drawable.java @@ -1,7 +1,10 @@ package View; +import Model.Player; + import javax.swing.*; import java.awt.*; +import java.util.LinkedList; /** * Drawable - kirajzolható objektumok absztrakt ősosztálya, leszármazottja a JComponent osztály @@ -47,4 +50,26 @@ public void paintOnPlayer(int x, int y, Graphics2D graphics2D){ } + public double getPlayerAngle(Player p, LinkedList players) { + double[] angles = new double[players.size()]; + for (int i = 0; i < angles.length; ++i) { + angles[i] = i * 20 - (angles.length - 1) * 10; + } + return angles[players.indexOf(p)]; + } + public int[] setCapX(int x){ + int[] capX = new int[3]; + capX[0] = x; + capX[1] = x-8; + capX[2] = x+8; + return capX; + } + + public int[] setCapY(int y) { + int[] capY = new int[3]; + capY[0] = y - 22; + capY[1] = y - 15; + capY[2] = y - 15; + return capY; + } } diff --git a/src/main/java/View/ImageUtility.java b/src/main/java/View/ImageUtility.java index ec988ec..fc851d7 100644 --- a/src/main/java/View/ImageUtility.java +++ b/src/main/java/View/ImageUtility.java @@ -18,7 +18,7 @@ public class ImageUtility { * @return The loaded image. */ public static BufferedImage ImageLoad(String file) { - BufferedImage image = null; + BufferedImage image; try { String nameOfFile = System.getProperty("user.dir") + File.separator + "src" + File.separator + "main" diff --git a/src/main/java/View/MechanicView.java b/src/main/java/View/MechanicView.java index 414f53f..ee724d2 100644 --- a/src/main/java/View/MechanicView.java +++ b/src/main/java/View/MechanicView.java @@ -31,7 +31,7 @@ public MechanicView(int x, int y, Mechanic m, Window v) { } private GameView gameView; - private Mechanic mechanic; + private final Mechanic mechanic; private Color color; private double angle; private Point rotationCenter = new Point(0, 0); @@ -68,13 +68,12 @@ public void paint(Graphics g) { // ha a játék ablakban vagyunk, akkor a játékos színével rajzoljuk ki if (WindowOptions.windowOption == WindowOptions.NEWGAME) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - int screenWidth = (int) screenSize.getWidth() * 3 / 4; int screenHeight = (int) screenSize.getHeight() * 3 / 4; AppFrame.setGraphicQuality(g); Graphics2D graphics2D = (Graphics2D) g.create(); graphics2D.setColor(color); graphics2D.setFont(new Font("Inter", Font.BOLD, 30)); - graphics2D.drawString("" + color.getRed() + "/" + color.getGreen() + "/" + color.getBlue(), 50 + imageForScale.getWidth(null) + 100, screenHeight / 2 + 20 + number * 50); + graphics2D.drawString(color.getRed() + "/" + color.getGreen() + "/" + color.getBlue(), 50 + imageForScale.getWidth(null) + 100, screenHeight / 2 + 20 + number * 50); } // ha a mechanic még nincs eltávolítva @@ -83,20 +82,14 @@ public void paint(Graphics g) { int[] pointsX = new int[3]; int[] pointsY = new int[3]; pointsX[0] = x; - pointsY[0] = y + 12 + 1; + pointsY[0] = y + 13; pointsX[1] = x - 8 + 1; pointsY[1] = y - 10 - 1; pointsX[2] = x + 8 + 1; pointsY[2] = y - 10 - 1; - int[] capX = new int[3]; - int[] capY = new int[3]; - capX[0] = x; - capY[0] = y - 22; - capX[1] = x - 8; - capY[1] = y - 15; - capX[2] = x + 8; - capY[2] = y - 15; + int[] capX = super.setCapX(x); + int[] capY = super.setCapY(y); g.setColor(color); Graphics2D graphics2D = (Graphics2D) g.create(); diff --git a/src/main/java/View/MenuView.java b/src/main/java/View/MenuView.java index 0760c29..8792693 100644 --- a/src/main/java/View/MenuView.java +++ b/src/main/java/View/MenuView.java @@ -13,8 +13,8 @@ public class MenuView extends Window { Button newGame, exit; - private BufferedImage background = ImageUtility.backgroundScale(getBackground()); - private BufferedImage bgText = ImageUtility.scaleImage(getMenuTitle(), 250); + private final BufferedImage background = ImageUtility.backgroundScale(getBackground()); + private final BufferedImage bgText = ImageUtility.scaleImage(getMenuTitle(), 250); /** * Konstruktor diff --git a/src/main/java/View/MouseIn.java b/src/main/java/View/MouseIn.java index 9c8add4..f7702d9 100644 --- a/src/main/java/View/MouseIn.java +++ b/src/main/java/View/MouseIn.java @@ -18,6 +18,7 @@ public void mouseClicked(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseClicked(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseClicked(e); case GAME -> Controller.getInstance().getGameView().mouseClicked(e); + default -> {} } } @@ -31,6 +32,7 @@ public void mousePressed(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mousePressed(e); case NEWGAME -> Controller.getInstance().getNewGameView().mousePressed(e); case GAME -> Controller.getInstance().getGameView().mousePressed(e); + default -> {} } } @@ -44,6 +46,7 @@ public void mouseReleased(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseReleased(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseReleased(e); case GAME -> Controller.getInstance().getGameView().mouseReleased(e); + default -> {} } } @@ -57,6 +60,7 @@ public void mouseEntered(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseEntered(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseEntered(e); case GAME -> Controller.getInstance().getGameView().mouseEntered(e); + default -> {} } } @@ -70,6 +74,7 @@ public void mouseExited(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseExited(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseExited(e); case GAME -> Controller.getInstance().getGameView().mouseExited(e); + default -> {} } } @@ -83,6 +88,7 @@ public void mouseDragged(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseDragged(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseDragged(e); case GAME -> Controller.getInstance().getGameView().mouseDragged(e); + default -> {} } } @@ -96,6 +102,7 @@ public void mouseMoved(MouseEvent e) { case MENU -> Controller.getInstance().getMenuView().mouseMoved(e); case NEWGAME -> Controller.getInstance().getNewGameView().mouseMoved(e); case GAME -> Controller.getInstance().getGameView().mouseMoved(e); + default -> {} } } } diff --git a/src/main/java/View/NewGameView.java b/src/main/java/View/NewGameView.java index 81841fc..fdcaaff 100644 --- a/src/main/java/View/NewGameView.java +++ b/src/main/java/View/NewGameView.java @@ -2,7 +2,6 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import Model.PointCounter; @@ -148,14 +147,6 @@ public void update() { } - /** - * A billentyűlenyomásokat kezeli - * @param e leütött billentyű - */ - public void keyTyped(KeyEvent e) { - - } - @Override public void mousePressed(MouseEvent e) { diff --git a/src/main/java/View/PipeView.java b/src/main/java/View/PipeView.java index 81c6f28..434f2d4 100644 --- a/src/main/java/View/PipeView.java +++ b/src/main/java/View/PipeView.java @@ -35,12 +35,12 @@ public PipeView(Drawable startNode, Drawable endNode, int width, Pipe p, Window } public boolean selected; private GameView gameView; - private Pipe pipe; + private final Pipe pipe; private int endX; private int endY; - private int width; - private Drawable startNode = null; - private Drawable endNode = null; + private final int width; + private Drawable startNode; + private Drawable endNode; /** * Cső kirajzolása @@ -57,14 +57,14 @@ public void paint(Graphics g) { double unitNormY = pipeNormal.y / getLength(); int x1 = (int) Math.ceil(unitNormX * width *1.4) + x; int y1 = (int) Math.ceil(unitNormY * width *1.4) + y; - int x2 = (int) Math.ceil(-unitNormX * width *1.4) + x;; + int x2 = (int) Math.ceil(-unitNormX * width *1.4) + x; int y2 = (int) Math.ceil(-unitNormY * width *1.4) + y; - int x3 = (int) Math.ceil(unitNormX * width *1.4) + endX; - int y3 = (int) Math.ceil(unitNormY * width *1.4) + endY; - int x4 = (int) Math.ceil(-unitNormX * width *1.4) + endX; - int y4 = (int) Math.ceil(-unitNormY * width *1.4) + endY; + int x3 = x1 -x +endX; + int y3 = y1-y +endY; + int x4 = x2 -x +endX; + int y4 = y2 -y +endY; - Color mainColor = BLACK; + Color mainColor; Color brokenColor = RED; Color miscColor = CYAN; boolean drawBroken = false; @@ -83,54 +83,25 @@ public void paint(Graphics g) { if (pipe.getHeldWater() == 1) { mainColor = new Color(47, 178, 245); - if (pipe.isBroken()) { - drawBroken = true; - } - - if (pipe.isGlued()) { - drawMisc = true; - miscColor = new Color(61, 153, 3); - } else if (pipe.isLubricated()) { - drawMisc = true; - miscColor = new Color(44, 121, 131); - } - } else if ( pipe.getNodes().getFirst().getActiveIn() != pipe && pipe.getNodes().getFirst().getActiveOut() != pipe && pipe.getNodes().getLast().getActiveIn() != pipe && pipe.getNodes().getLast().getActiveOut() != pipe) - { - mainColor = LIGHT_GRAY; - - if (pipe.isBroken()) { - drawBroken = true; - } - - if (pipe.isGlued()) { - drawMisc = true; - miscColor = new Color(61, 153, 3); - } else if (pipe.isLubricated()) { - drawMisc = true; - miscColor = new Color(44, 121, 131); - } - - } else { - - mainColor = BLACK; + {mainColor = LIGHT_GRAY;} + else {mainColor = BLACK;} - if (pipe.isBroken()) { - drawBroken = true; - } + if (pipe.isBroken()) { + drawBroken = true; + } - if (pipe.isGlued()) { - drawMisc = true; - miscColor = new Color(61, 153, 3); - } else if (pipe.isLubricated()) { - drawMisc = true; - miscColor = new Color(44, 121, 131); - } + if (pipe.isGlued()) { + drawMisc = true; + miscColor = new Color(61, 153, 3); + } else if (pipe.isLubricated()) { + drawMisc = true; + miscColor = new Color(44, 121, 131); } if (drawBroken) { @@ -232,7 +203,7 @@ public boolean isIn(MouseEvent e) { int[] pointsY = new int[4]; pointsX[0] = (int) Math.ceil(unitNormX * width * 4) + x; pointsY[0] = (int) Math.ceil(unitNormY * width * 4) + y; - pointsX[1] = (int) Math.ceil(-unitNormX * width * 4) + x;; + pointsX[1] = (int) Math.ceil(-unitNormX * width * 4) + x; pointsY[1] = (int) Math.ceil(-unitNormY * width * 4) + y; pointsX[2] = (int) Math.ceil(-unitNormX * width * 4) + endX; pointsY[2] = (int) Math.ceil(-unitNormY * width * 4) + endY; @@ -276,7 +247,7 @@ public Steppable getCorrespondingModelSteppable() { /** * Visszaadja, hogy egy új játékost melyik pontban lehet kirajzolni - * @return + * @return a pont */ @Override public Point getDefaultPlayerPosition() { diff --git a/src/main/java/View/PopUpBar.java b/src/main/java/View/PopUpBar.java index 66ec013..7b10244 100644 --- a/src/main/java/View/PopUpBar.java +++ b/src/main/java/View/PopUpBar.java @@ -22,9 +22,8 @@ public class PopUpBar extends Drawable { */ public PopUpBar(int x, int y, int r, Window v, SteppableView creator, ActionType[] at) { super(x, y, v); - this.r = r; - buttonLocations = new Point[6]; + Point[] buttonLocations = new Point[6]; for (int i = 0; i < buttonLocations.length; ++i) { buttonLocations[i] = new Point(); buttonLocations[i].x = (int) (Math.cos(Math.toRadians(i * -60 - 90)) * r + x); @@ -48,16 +47,13 @@ public PopUpBar(int x, int y, int r, Window v, SteppableView creator, ActionType this.creator = creator; } - private SteppableView creator; + private final SteppableView creator; public SteppableView getCreator() { return creator; } - private Point[] buttonLocations; - private int r; - - private List buttons = new LinkedList(); + private final List buttons = new LinkedList<>(); /** * A popup menü kirajzolása * @param g Graphics diff --git a/src/main/java/View/PopUpButton.java b/src/main/java/View/PopUpButton.java index 4c31ad6..d614903 100644 --- a/src/main/java/View/PopUpButton.java +++ b/src/main/java/View/PopUpButton.java @@ -29,10 +29,10 @@ public PopUpButton(int x, int y, int r, ActionType a, Window v, SteppableView cr drawLoc = ImageUtility.centerImage(new Point(x, y), sprite); this.creator = creator; } - private SteppableView creator; - private ActionType actiontype; + private final SteppableView creator; + private final ActionType actiontype; private BufferedImage sprite = null; - private int r; + private final int r; Point drawLoc; public static boolean waitingForParameter = false; public static LinkedList parameters = new LinkedList<>(); @@ -40,10 +40,7 @@ public PopUpButton(int x, int y, int r, ActionType a, Window v, SteppableView cr private float opacity = 0.0f; @Override public boolean isIn(MouseEvent e) { - if (Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r) { - return true; - } - return false; + return Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r; } @Override @@ -64,7 +61,7 @@ public void clickAction(MouseEvent e) { } case PLACEDOWN -> c.placedown(c.getObjectName(p)); case PICKUP_PIPE -> { - if (((GameView) view).cisterns.contains(creator)) { + if (((GameView) view).cisterns.contains((CisternView) creator)) { Cistern cis = (Cistern) s; Pipe pipe = cis.getGeneratedPipes().getFirst(); c.pickup(c.getObjectName(p), c.getObjectName(pipe)); @@ -123,7 +120,6 @@ public boolean isDraggable() { public static void paramsReceived() { Controller c = Controller.getInstance(); Player p = c.getActivePlayer(); - Steppable s = paramClient.creator.getCorrespondingModelSteppable(); if (paramClient.actiontype == ActionType.REDIRECT) { c.redirect(c.getObjectName(p), c.getObjectName(parameters.getFirst().getCorrespondingModelElement()), c.getObjectName(parameters.getLast().getCorrespondingModelElement())); } diff --git a/src/main/java/View/PumpView.java b/src/main/java/View/PumpView.java index 5f67b31..518dee0 100644 --- a/src/main/java/View/PumpView.java +++ b/src/main/java/View/PumpView.java @@ -14,11 +14,10 @@ public class PumpView extends Drawable implements Clickable, CreatePopUpBar, SteppableView { - public PumpView(int x, int y, int r, Pump p, CisternView c, Window v) { + public PumpView(int x, int y, int r, Pump p, Window v) { super(x, y, v); this.r = r; pump = p; - gen = c; arrowSprite = getPumpIndicatorImg(); arrowSprite = ImageUtility.scaleImage(arrowSprite, 20); @@ -27,13 +26,11 @@ public PumpView(int x, int y, int r, Pump p, CisternView c, Window v) { gameView = (GameView) v; } private GameView gameView; - private Pump pump; - private boolean generated; - private CisternView gen; - private int r; + private final Pump pump; + private final int r; private PipeView outPipe = null; - private BufferedImage arrowSprite = null; + private BufferedImage arrowSprite; private int arrowLocX; private int arrowLocY; private double arrowAngle; @@ -42,24 +39,12 @@ public PumpView(int x, int y, int r, Pump p, CisternView c, Window v) { @Override public void paint(Graphics g) { AppFrame.setGraphicQuality(g); - Color color=new Color(0,0,0); - if(pump.isBroken()) - color=new Color(250,100,100); - else { - if(pump.getHeldWater()<=pump.getWaterCapacity()*0.25 && pump.getHeldWater()!=0) - color=new Color(0,0,150); - if(pump.getHeldWater()<=pump.getWaterCapacity()*0.5 && pump.getHeldWater()>=pump.getWaterCapacity()*0.25) - color=new Color(0,0,200); - if(pump.getHeldWater()<=pump.getWaterCapacity()*0.75 && pump.getHeldWater()>=pump.getWaterCapacity()*0.5) - color=new Color(20,20,255); - if(pump.getHeldWater()<=pump.getWaterCapacity() && pump.getHeldWater()>=pump.getWaterCapacity()*0.75) - color=new Color(60,170,255); - } + Color color = getColor(); if (outPipe != null) { AffineTransform at = new AffineTransform(); at.translate(arrowLocX, arrowLocY); at.rotate(Math.toRadians(-arrowAngle)); - at.translate(-arrowSprite.getWidth() / 2, -arrowSprite.getHeight() / 2); + at.translate((double) -arrowSprite.getWidth() / 2, (double) -arrowSprite.getHeight() / 2); Graphics2D g2 = (Graphics2D) g.create(); g2.drawImage(arrowSprite, at, null); g2.setTransform(new AffineTransform()); @@ -79,6 +64,23 @@ public void paint(Graphics g) { g.drawString( Integer.toString(pump.getWaterCapacity()), x + 5, y+5); } + private Color getColor() { + Color color=new Color(0,0,0); + if(pump.isBroken()) + color=new Color(250,100,100); + else { + if(pump.getHeldWater()<=pump.getWaterCapacity()*0.25 && pump.getHeldWater()!=0) + color=new Color(0,0,150); + if(pump.getHeldWater()<=pump.getWaterCapacity()*0.5 && pump.getHeldWater()>=pump.getWaterCapacity()*0.25) + color=new Color(0,0,200); + if(pump.getHeldWater()<=pump.getWaterCapacity()*0.75 && pump.getHeldWater()>=pump.getWaterCapacity()*0.5) + color=new Color(20,20,255); + if(pump.getHeldWater()<=pump.getWaterCapacity() && pump.getHeldWater()>=pump.getWaterCapacity()*0.75) + color=new Color(60,170,255); + } + return color; + } + @Override public void paintOnPlayer(int x,int y, Graphics2D graphics2D){ graphics2D.setColor(BLACK); @@ -120,10 +122,7 @@ public void update() { @Override public boolean isIn(MouseEvent e) { - if (Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r) { - return true; - } - return false; + return Math.sqrt(Math.pow(e.getX() - x, 2) + Math.pow((e.getY() - y), 2)) < r; } @Override @@ -143,8 +142,6 @@ public Steppable getCorrespondingModelSteppable() { /** * Visszaadja, hogy egy új játékost melyik pontban lehet kirajzolni - * - * @return */ @Override public Point getDefaultPlayerPosition() { @@ -154,17 +151,11 @@ public Point getDefaultPlayerPosition() { public Point getRotationCenter() { //meg kéne nézni hány játékos van rajta - Point ret = new Point(x, y); - return ret; + return new Point(x, y); } - @Override public double getPlayerAngle(Player p) { - double[] angles = new double[pump.getPlayers().size()]; - for (int i = 0; i < angles.length; ++i) { - angles[i] = i * 20 - (angles.length - 1) * 10; - } - return angles[pump.getPlayers().indexOf(p)]; + return super.getPlayerAngle(p, pump.getPlayers()); } @Override diff --git a/src/main/java/View/SaboteurView.java b/src/main/java/View/SaboteurView.java index 1aa440a..bec2043 100644 --- a/src/main/java/View/SaboteurView.java +++ b/src/main/java/View/SaboteurView.java @@ -20,7 +20,7 @@ public SaboteurView(int x, int y, Saboteur s, Window v) { } private GameView gameView; private Color color; - private Saboteur saboteur; + private final Saboteur saboteur; private double angle; private Point rotationCenter = new Point(0, 0); @@ -44,7 +44,7 @@ public void paint(Graphics g) { Graphics2D graphics2D = (Graphics2D) g.create(); graphics2D.setColor(color); graphics2D.setFont(new Font("Inter",Font.BOLD,30)); - graphics2D.drawString(""+color.getRed()+"/"+color.getGreen()+"/"+color.getBlue(),50+imageForScale.getWidth(null)+100+220, screenHeight/2+20+number*50); + graphics2D.drawString(color.getRed()+"/"+color.getGreen()+"/"+color.getBlue(),50+imageForScale.getWidth(null)+100+220, screenHeight/2+20+number*50); } if (!saboteur.isRemoved()) { AppFrame.setGraphicQuality(g); @@ -56,14 +56,10 @@ public void paint(Graphics g) { pointsY[1] = y - 8; pointsX[2] = x + 6; pointsY[2] = y - 8; - int[] capX = new int[3]; - int[] capY = new int[3]; - capX[0] = x; - capY[0] = y - 22; - capX[1] = x - 8; - capY[1] = y - 15; - capX[2] = x + 8; - capY[2] = y - 15; + + int[] capX = super.setCapX(x); + int[] capY = super.setCapY(y); + Graphics2D graphics2D = (Graphics2D) g.create(); graphics2D.setStroke(new BasicStroke(3)); AffineTransform at = new AffineTransform(); diff --git a/src/main/java/View/SpringView.java b/src/main/java/View/SpringView.java index 68d478f..c98ed3b 100644 --- a/src/main/java/View/SpringView.java +++ b/src/main/java/View/SpringView.java @@ -35,14 +35,14 @@ public SpringView(int x, int y, int r, Spring s, Window v) { gameView = (GameView) v; } private GameView gameView; - private BufferedImage sprite = null; - private Spring spring; - private int r; + private BufferedImage sprite; + private final Spring spring; + private final int r; private int arrowLocX; private int arrowLocY; private double arrowAngle; private PipeView outPipe = null; - private BufferedImage arrowSprite = null; + private BufferedImage arrowSprite; /** * A forrás kirajzolásáért felelős függvény @@ -55,7 +55,7 @@ public void paint(Graphics g) { AffineTransform at = new AffineTransform(); at.translate(arrowLocX, arrowLocY); at.rotate(Math.toRadians(-arrowAngle)); - at.translate(-arrowSprite.getWidth()/2, -arrowSprite.getHeight()/2); + at.translate((double) -arrowSprite.getWidth() /2, (double) -arrowSprite.getHeight() /2); Graphics2D g2 = (Graphics2D) g; g2.drawImage(arrowSprite, at, null); } @@ -123,17 +123,11 @@ public Point getDefaultPlayerPosition() { public Point getRotationCenter() { //meg kéne nézni hány játékos van rajta - Point ret = new Point(x, y); - return ret; + return new Point(x, y); } - @Override public double getPlayerAngle(Player p) { - double[] angles = new double[spring.getPlayers().size()]; - for (int i = 0; i < angles.length; ++i) { - angles[i] = i * 20 - (angles.length - 1) * 10; - } - return angles[spring.getPlayers().indexOf(p)]; + return super.getPlayerAngle(p, spring.getPlayers()); } @Override diff --git a/src/main/java/View/SteppableView.java b/src/main/java/View/SteppableView.java index 9d775eb..6bcd51d 100644 --- a/src/main/java/View/SteppableView.java +++ b/src/main/java/View/SteppableView.java @@ -13,19 +13,19 @@ public interface SteppableView { /** * Visszaadja, hogy egy új játékost melyik pontban lehet kirajzolni */ - public Point getDefaultPlayerPosition(); + Point getDefaultPlayerPosition(); /** * Játékos szögének meghatározása * @param p - játékos * @return - szög */ - public double getPlayerAngle(Player p); + double getPlayerAngle(Player p); /** * Forgatás középpontjának lekérdezése * @return - forgatás középpontja */ - public Point getRotationCenter(); + Point getRotationCenter(); - public Steppable getCorrespondingModelSteppable(); + Steppable getCorrespondingModelSteppable(); } diff --git a/src/main/java/View/Window.java b/src/main/java/View/Window.java index fc2878f..f03bf2a 100644 --- a/src/main/java/View/Window.java +++ b/src/main/java/View/Window.java @@ -1,14 +1,9 @@ package View; -import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.*; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.LinkedList; -import java.awt.image.BufferedImage; import java.io.*; /** @@ -52,10 +47,6 @@ public void addClickable(Clickable c, boolean highClickPriority) { clickables.add(c); } - public void addComponent(JComponent component) { - components.add(component); - } - public void remove(Object o) { drawables.remove(o); clickables.remove(o);