diff --git a/src/main/java/Controll/Controller.java b/src/main/java/Controll/Controller.java index 2975a96..6931376 100644 --- a/src/main/java/Controll/Controller.java +++ b/src/main/java/Controll/Controller.java @@ -195,17 +195,17 @@ public static void Game() throws FileNotFoundException { switch(cmd[0]) { case("show"): show(cmd); break; case("showobject"): showobject(cmd); break; - case("move"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else move(cmd); break; - case("breakfield"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else breakfield(cmd); break; - case("repair"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else repair(cmd); break; - case("placepump"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else placepump(cmd); break; - case("set"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else set(cmd); break; - case("disconnect"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else disconnect(cmd); break; - case("connect"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else connect(cmd); break; - case("getpump"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else getpump(cmd); break; - case("pickuppipe"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER);else pickuppipe(cmd); break; - case("makesticky"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else makesticky(cmd); break; - case("makeslippery"): moves++; if (!((Player)objectNames.get(cmd[1])).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else makeslippery(cmd); break; + case("move"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else move(cmd); break; + case("breakfield"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else breakfield(cmd); break; + case("repair"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else repair(cmd); break; + case("placepump"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else placepump(cmd); break; + case("set"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else set(cmd); break; + case("disconnect"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else disconnect(cmd); break; + case("connect"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else connect(cmd); break; + case("getpump"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else getpump(cmd); break; + case("pickuppipe"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER);else pickuppipe(cmd); break; + case("makesticky"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else makesticky(cmd); break; + case("makeslippery"): moves++; if (!objectNames.get(cmd[1]).equals(currentPlayer)) logger.log(Level.INFO, StringResourceController.WRONG_PLAYER); else makeslippery(cmd); break; case("save"): save(cmd); break; case("testall"): testAll(cmd); break; case("list"): list(); break; @@ -941,7 +941,8 @@ public static void endturn(String[] cmd){ waterCounter.count(); //léptetés for (Object obj : objectNames.values()) { - if(obj instanceof Steppable value) { + if(obj instanceof Steppable) { + Steppable value = (Steppable) obj; value.step(); } } diff --git a/src/main/java/Drawing/PipeDraw.java b/src/main/java/Drawing/PipeDraw.java index 06ab9cb..8d2b945 100644 --- a/src/main/java/Drawing/PipeDraw.java +++ b/src/main/java/Drawing/PipeDraw.java @@ -41,8 +41,11 @@ public PipeDraw(int x1, int y1, int x2, int y2) { pipeB.addActionListener(ViewGame.selectListener); } public void setCoords(Drawable pumpFrom, Drawable pumpTo) { - int fromX, toX, fromY, toY; - + int fromX; + int toX; + int fromY; + int toY; + fromX = pumpFrom.getX(); fromY = pumpFrom.getY(); toX = pumpTo.getX(); diff --git a/src/main/java/Fields/ActiveFields/Cistern.java b/src/main/java/Fields/ActiveFields/Cistern.java index 988edc9..5505de8 100644 --- a/src/main/java/Fields/ActiveFields/Cistern.java +++ b/src/main/java/Fields/ActiveFields/Cistern.java @@ -93,26 +93,26 @@ public Pipe pickUpPipe() { @Override public String toString() { ArrayList players = this.getPlayers(); - String playersNames = "null"; - + StringBuilder playerBuilder = new StringBuilder("null"); for (int i = 0; i < players.size(); i++) { - if(i == 0) playersNames = ""; - playersNames += Controller.objectReverseNames.get(players.get(i)); + if(i == 0) playerBuilder.delete(0,3); + playerBuilder.append(Controller.objectReverseNames.get(players.get(i))); if (i != players.size() - 1) { - playersNames += ", "; + playerBuilder.append(", "); } } + ArrayList pipes = this.getPipes(); - String pipesNames ="null"; + StringBuilder pipeBuilder = new StringBuilder("null"); if(pipes != null) { for (int i = 0; i < pipes.size(); i++) { - if (i == 0) pipesNames = ""; - pipesNames += Controller.objectReverseNames.get(pipes.get(i)); + if (i == 0) pipeBuilder.delete(0,3); + pipeBuilder.append(Controller.objectReverseNames.get(pipes.get(i))); if (i != pipes.size() - 1) { - pipesNames += ", "; + pipeBuilder.append(", "); } } } @@ -121,7 +121,7 @@ public String toString() { + "\noccupied: " + this.isOccupied() + "\nwater: " + getWaterNoChange() + "\nbroken: " + this.isBroken() - + "\nplayers: " + playersNames - + "\npipes: " + pipesNames + "\n"; + + "\nplayers: " + playerBuilder + + "\npipes: " + pipeBuilder + "\n"; } } diff --git a/src/main/java/Fields/ActiveFields/Pump.java b/src/main/java/Fields/ActiveFields/Pump.java index f629375..59c2d13 100644 --- a/src/main/java/Fields/ActiveFields/Pump.java +++ b/src/main/java/Fields/ActiveFields/Pump.java @@ -133,14 +133,14 @@ public String toString() { String pipesNames = getPipeNames(); - String SWaterFrom=""; - String SWaterTo=""; + String sWaterFrom=""; + String sWaterTo=""; if(getWaterFrom() == -1 && getWaterTo() == -1 ){ - SWaterFrom = SWaterTo = "null"; + sWaterFrom = sWaterTo = "null"; } else{ - SWaterFrom = ""+Controller.objectReverseNames.get(getPipes().get(getWaterFrom())); - SWaterTo = ""+Controller.objectReverseNames.get(getPipes().get(getWaterTo())); + sWaterFrom = ""+Controller.objectReverseNames.get(getPipes().get(getWaterFrom())); + sWaterTo = ""+Controller.objectReverseNames.get(getPipes().get(getWaterTo())); } @@ -151,36 +151,36 @@ public String toString() { + "\nplayers: " + playersNames + "\npipes: " + pipesNames + "\ntank: " + this.getTank() - + "\nwaterFrom: " +SWaterFrom - + "\nwaterTo: " +SWaterTo + "\n"; + + "\nwaterFrom: " +sWaterFrom + + "\nwaterTo: " +sWaterTo + "\n"; } private String getPlayerNames() { ArrayList players = this.getPlayers(); - String playersNames = "null"; + StringBuilder playerBuilder = new StringBuilder("null"); for (int i = 0; i < players.size(); i++) { - if(i == 0) playersNames = ""; - playersNames += Controller.objectReverseNames.get(players.get(i)); + if(i == 0) playerBuilder.delete(0,3); + playerBuilder.append(Controller.objectReverseNames.get(players.get(i))); if (i != players.size() - 1) { - playersNames += ", "; + playerBuilder.append(", "); } } - return playersNames; + return playerBuilder.toString(); } private String getPipeNames(){ ArrayList pipes = this.getPipes(); - String pipesNames ="null"; + StringBuilder pipeBuilder = new StringBuilder("null"); if(pipes != null) { for (int i = 0; i < pipes.size(); i++) { - if (i == 0) pipesNames = ""; - pipesNames += Controller.objectReverseNames.get(pipes.get(i)); + if (i == 0) pipeBuilder.delete(0,3); + pipeBuilder.append(Controller.objectReverseNames.get(pipes.get(i))); if (i != pipes.size() - 1) { - pipesNames += ", "; + pipeBuilder.append(", "); } } } - return pipesNames; + return pipeBuilder.toString(); } } diff --git a/src/main/java/Fields/ActiveFields/Spring.java b/src/main/java/Fields/ActiveFields/Spring.java index 44dd54c..a47c5d8 100644 --- a/src/main/java/Fields/ActiveFields/Spring.java +++ b/src/main/java/Fields/ActiveFields/Spring.java @@ -60,32 +60,35 @@ public void step() { @Override public String toString() { ArrayList players = this.getPlayers(); - - String playersNames = "null"; - + StringBuilder playerBuilder = new StringBuilder("null"); for (int i = 0; i < players.size(); i++) { - if(i == 0) playersNames = ""; - playersNames += Controller.objectReverseNames.get(players.get(i)); + if(i == 0) playerBuilder.delete(0,3); + playerBuilder.append(Controller.objectReverseNames.get(players.get(i))); if (i != players.size() - 1) { - playersNames += ", "; + playerBuilder.append(", "); } } + + + ArrayList pipes = this.getPipes(); - String pipesNames ="null"; - for (int i = 0; i < pipes.size(); i++) { - if(i == 0) pipesNames = ""; - pipesNames += Controller.objectReverseNames.get(pipes.get(i)); - if (i != pipes.size() - 1) { - pipesNames += ", "; + StringBuilder pipeBuilder = new StringBuilder("null"); + if(pipes != null) { + for (int i = 0; i < pipes.size(); i++) { + if (i == 0) pipeBuilder.delete(0,3); + pipeBuilder.append(Controller.objectReverseNames.get(pipes.get(i))); + if (i != pipes.size() - 1) { + pipeBuilder.append(", "); + } } } return "name: "+ Controller.objectReverseNames.get(this) + "\noccupied: " + this.isOccupied() + "\nwater: " + getWaterNoChange() + "\nbroken: " + this.isBroken() - + "\nplayers: " + playersNames - + "\npipes: " + pipesNames + + "\nplayers: " + playerBuilder + + "\npipes: " + pipeBuilder + "\nwaterOut: " + this.getWaterOut() + "\nmaxOutWater: " + this.getMaxOutWater() + "\n"; } diff --git a/src/main/java/Fields/Pipe.java b/src/main/java/Fields/Pipe.java index 9d8a851..658306f 100644 --- a/src/main/java/Fields/Pipe.java +++ b/src/main/java/Fields/Pipe.java @@ -336,24 +336,22 @@ public void step(){ @Override public String toString() { ArrayList players = this.getPlayers(); - - String playersNames = "null"; - + StringBuilder playerBuilder = new StringBuilder("null"); for (int i = 0; i < players.size(); i++) { - if(i == 0) playersNames = ""; - playersNames += Controller.objectReverseNames.get(players.get(i)); + if(i == 0) playerBuilder.delete(0,3); + playerBuilder.append(Controller.objectReverseNames.get(players.get(i))); if (i != players.size() - 1) { - playersNames += ", "; + playerBuilder.append(", "); } } - ArrayList loaclFields = this.getFields(); - String fieldsNames ="null"; - for (int i = 0; i < loaclFields.size(); i++) { - if(i == 0) fieldsNames = ""; - fieldsNames += Controller.objectReverseNames.get(loaclFields.get(i)); - if (i != loaclFields.size() - 1) { - fieldsNames += ", "; + ArrayList localFields = this.getFields(); + StringBuilder fieldBuilder = new StringBuilder("null"); + for (int i = 0; i < localFields.size(); i++) { + if(i == 0) fieldBuilder.delete(0,3); + fieldBuilder.append(Controller.objectReverseNames.get(localFields.get(i))); + if (i != localFields.size() - 1) { + fieldBuilder.append(", "); } } @@ -361,8 +359,8 @@ public String toString() { + "\noccupied: " + this.isOccupied() + "\nwater: " + getWaterNoChange() + "\nbroken: " + this.isBroken() - + "\nplayers: " + playersNames - + "\nfields: " + fieldsNames + + "\nplayers: " + playerBuilder + + "\nfields: " + fieldBuilder + "\ncapacity: " + this.getCapacity() + "\nbreakable: " + this.getBreakable() + "\nrfluidtime: " + this.getRemainingFluidTime() diff --git a/src/main/java/srcTMP/palya.txt b/src/palya.txt similarity index 100% rename from src/main/java/srcTMP/palya.txt rename to src/palya.txt