diff --git a/pom.xml b/pom.xml index bcc37e4..9c8caf3 100644 --- a/pom.xml +++ b/pom.xml @@ -89,7 +89,7 @@ true - main.java.Controll.ViewGame + main.java.Control.ViewGame diff --git a/src/main/java/Drawing/CisternDraw.java b/src/main/java/Drawing/CisternDraw.java deleted file mode 100644 index eb08615..0000000 --- a/src/main/java/Drawing/CisternDraw.java +++ /dev/null @@ -1,55 +0,0 @@ -package main.java.drawing; - -import javax.swing.*; - -import main.java.control.ViewGame; - -import java.awt.*; - -/** - * CisternDraw class - */ -public class CisternDraw extends Drawable { - JButton cistern = new JButton(); - JButton cisternB = new JButton(); - - /** - * CisternDraw constructor - * @param tmpX - * @param tmpY - */ - public CisternDraw(int tmpX, int tmpY) { - x = tmpX; - y = tmpY; - cistern.setVisible(true); - cistern.setBackground(new Color(150, 75, 0)); - - ViewGame.buttonToElement.put(cisternB, this); - cisternB.addActionListener(ViewGame.selectListener); - } - - /** - * Draw method - * @param panel - * @param g - */ - @Override - public void Draw(JPanel panel, Graphics2D g) { - cistern.setBounds(x, y, 50, 50); - cistern.setBorder(BorderFactory.createLineBorder(Color.blue, 5)); - - if(ViewGame.getChosen()) { - cisternB.setVisible(true); - cisternB.setBackground(new Color(255, 0, 0)); - cisternB.setBounds(x, y, 50, 50); - cisternB.setBorder(BorderFactory.createLineBorder(Color.blue, 5)); - panel.add(cisternB); - } else { - cisternB.setVisible(false); - panel.remove(cisternB); - } - - panel.add(cistern); - panel.repaint(); - } -} diff --git a/src/main/java/Drawing/Drawable.java b/src/main/java/Drawing/Drawable.java deleted file mode 100644 index c4c5ce5..0000000 --- a/src/main/java/Drawing/Drawable.java +++ /dev/null @@ -1,36 +0,0 @@ -package main.java.drawing; - -import javax.swing.*; -import java.awt.*; - -/** - * Drawable class - */ -public abstract class Drawable { - protected int x; - protected int y; - - /** - * Get X method - * @return - */ - public int getX() { - return x; - } - - /** - * Get Y method - * @return - */ - public int getY() { - return y; - } - - /** - * Draw method - * @param panel - * @param g - */ - public void Draw(JPanel panel, Graphics2D g) { - } -} diff --git a/src/main/java/Drawing/MechanicDraw.java b/src/main/java/Drawing/MechanicDraw.java deleted file mode 100644 index 256b7fd..0000000 --- a/src/main/java/Drawing/MechanicDraw.java +++ /dev/null @@ -1,81 +0,0 @@ -package main.java.drawing; - -import main.java.control.Controller; -import main.java.control.ViewGame; -import main.java.fields.Field; -import main.java.fields.Pipe; -import main.java.fields.activefields.Cistern; -import main.java.fields.activefields.Pump; -import main.java.fields.activefields.Spring; -import main.java.players.Mechanic; -import main.java.players.Player; - -import javax.swing.*; -import java.awt.*; -import java.util.ArrayList; - -/** - * Class for drawing the mechanic. - * */ -public class MechanicDraw extends Drawable { - String mecName = ""; - JButton mec = new JButton(); - - /** - * Constructor for the mechanic. - * @param tmpX X coordinate of the mechanic. - * @param tmpY Y coordinate of the mechanic. - * */ - public MechanicDraw(int tmpX, int tmpY) { - x = tmpX; - y = tmpY; - mec.setVisible(true); - } - - /** - * Draw method for the mechanic. - * @param panel - * @param g - */ - @Override - public void Draw(JPanel panel, Graphics2D g) { - Mechanic m = (Mechanic)ViewGame.objectDrawNames.get(this); - Player current = Controller.getActivePlayer(); - mecName = Controller.objectReverseNames.get(m); - mec.setText(mecName); - Field f = m.getStandingField(); - if (f instanceof Pipe) { - PipeDraw pd = (PipeDraw)ViewGame.objectDrawReverseNames.get(f); - ArrayList players = f.getPlayers(); - int i = players.indexOf(m); - x = (pd.getxFrom()+pd.getxTo())/2-25; - y = (pd.getYFrom()+pd.getYTo())/2 - (i+1)*25; - } - else if (f instanceof Pump) { - PumpDraw pd = (PumpDraw)ViewGame.objectDrawReverseNames.get(f); - ArrayList players = f.getPlayers(); - int i = players.indexOf(m); - x = pd.getX(); - y = pd.getY() - (i+1)*25; - } - else if (f instanceof Cistern) { - CisternDraw pd = (CisternDraw)ViewGame.objectDrawReverseNames.get(f); - ArrayList players = f.getPlayers(); - int i = players.indexOf(m); - x = pd.getX(); - y = pd.getY() - (i+1)*25; - } - else if (f instanceof Spring) { - SpringDraw pd = (SpringDraw)ViewGame.objectDrawReverseNames.get(f); - ArrayList players = f.getPlayers(); - int i = players.indexOf(m); - x = pd.getX(); - y = pd.getY() - (i+1)*25; - } - mec.setBounds(x, y, 50, 20); - if (m.equals(current)) mec.setBorder(BorderFactory.createLineBorder(Color.green, 5)); - else mec.setBorder(BorderFactory.createLineBorder(Color.red, 5)); - panel.add(mec); - panel.repaint(); - } -} diff --git a/src/main/java/Drawing/PipeDraw.java b/src/main/java/Drawing/PipeDraw.java deleted file mode 100644 index 7e366a9..0000000 --- a/src/main/java/Drawing/PipeDraw.java +++ /dev/null @@ -1,111 +0,0 @@ -package main.java.drawing; - -import javax.swing.*; - -import main.java.control.ViewGame; - -import java.awt.*; - -/** - * PipeDraw class - */ -public class PipeDraw extends Drawable { - private int xFrom; - private int xTo; - private int yFrom; - private int yTo; - JButton pipeB = new JButton(); - - /** - * Getters - * @return xFrom, xTo, yFrom, yTo - */ - public int getxFrom() { return xFrom; } - public int getxTo() { return xTo; } - public int getYFrom() { return yFrom; } - public int getYTo() { return yTo; } - - /** - * Constructor for PipeDraw - * @param x1 - * @param y1 - * @param x2 - * @param y2 - */ - public PipeDraw(int x1, int y1, int x2, int y2) { - xFrom = x1; - yFrom = y1; - xTo = x2; - yTo = y2; - - ViewGame.buttonToElement.put(pipeB, this); - pipeB.addActionListener(ViewGame.selectListener); - } - public void setCoords(Drawable pumpFrom, Drawable pumpTo) { - int fromX; - int toX; - int fromY; - int toY; - - fromX = pumpFrom.getX(); - fromY = pumpFrom.getY(); - toX = pumpTo.getX(); - toY = pumpTo.getY(); - - //A cél pumpa - if(toY < fromY) { - //felettünk van - toY += 50; - } else if(toY > fromY) { - //alattunk - fromY += 50; - } else { - //velünk egy magasságban - toY += 25; - fromY += 25; - - } - if(toX < fromX) { - //balra - toX += 50; - } else if(fromX > toX) { - //jobbra - fromX += 50; - } else { - //egy oszlopban - toX += 25; - fromX += 25; - } - setCoords(fromX, fromY, toX, toY); - - - } - public void setCoords(int x1, int y1, int x2, int y2) { - xFrom = x1; - yFrom = y1; - xTo = x2; - yTo = y2; - } - - /** - * Draw method - * @param panel - * @param g2d - */ - @Override - public void Draw(JPanel panel, Graphics2D g2d) { - - if(ViewGame.getChosen()) { - pipeB.setVisible(true); - pipeB.setBackground(new Color(255, 0, 0)); - pipeB.setBounds(xFrom + (xTo - xFrom) / 2 - 25, yFrom + (yTo - yFrom) / 2 - 12, 50, 25); - pipeB.setBorder(BorderFactory.createLineBorder(Color.black, 5)); - panel.add(pipeB); - } else { - pipeB.setVisible(false); - panel.remove(pipeB); - } - - panel.repaint(); - } -} diff --git a/src/main/java/Drawing/PumpDraw.java b/src/main/java/Drawing/PumpDraw.java deleted file mode 100644 index 6a1743f..0000000 --- a/src/main/java/Drawing/PumpDraw.java +++ /dev/null @@ -1,57 +0,0 @@ -package main.java.drawing; - -import main.java.control.ViewGame; -import main.java.fields.activefields.Pump; - -import javax.swing.*; -import java.awt.*; - -/** - * Class for drawing the mechanic. - * */ -public class PumpDraw extends Drawable { - JButton pump = new JButton(); - JButton pumpB = new JButton(); - /** - * Constructor for the mechanic. - * @param tmpX X coordinate of the mechanic. - * @param tmpY Y coordinate of the mechanic. - * */ - public PumpDraw(int tmpX, int tmpY) { - x = tmpX; - y = tmpY; - pump.setVisible(true); - pump.setBackground(new Color(150, 75, 0)); - - ViewGame.buttonToElement.put(pumpB, this); - pumpB.addActionListener(ViewGame.selectListener); - } - /** - * Draws the mechanic. - * @param panel The panel to draw on. - * @param g The graphics to draw with. - * */ - @Override - public void Draw(JPanel panel, Graphics2D g) { - pump.setBounds(x, y, 50, 50); - Pump p = (Pump)ViewGame.objectDrawNames.get(this); - - if (p.isBroken()) pump.setBorder(BorderFactory.createDashedBorder(Color.black, 5, 2, 2, false)); - else pump.setBorder(BorderFactory.createLineBorder(Color.black, 5)); - - if(ViewGame.getChosen()) { - pumpB.setVisible(true); - pumpB.setBackground(new Color(255, 0, 0)); - pumpB.setBounds(x, y, 50, 50); - if (p.isBroken()) pumpB.setBorder(BorderFactory.createDashedBorder(Color.black, 5, 2, 2, false)); - else pumpB.setBorder(BorderFactory.createLineBorder(Color.black, 5)); - panel.add(pumpB); - } else { - pumpB.setVisible(false); - panel.remove(pumpB); - } - - panel.add(pump); - panel.repaint(); - } -} diff --git a/src/main/java/Drawing/SaboteurDraw.java b/src/main/java/Drawing/SaboteurDraw.java deleted file mode 100644 index 0400953..0000000 --- a/src/main/java/Drawing/SaboteurDraw.java +++ /dev/null @@ -1,83 +0,0 @@ -package main.java.drawing; - -import main.java.control.Controller; -import main.java.control.ViewGame; -import main.java.fields.Field; -import main.java.fields.Pipe; -import main.java.fields.activefields.Cistern; -import main.java.fields.activefields.Pump; -import main.java.fields.activefields.Spring; -import main.java.players.Player; -import main.java.players.Saboteur; - -import javax.swing.*; -import java.awt.*; -import java.util.ArrayList; - -/** - * Class for drawing the mechanic. - * */ -public class SaboteurDraw extends Drawable { - String sabName = ""; - JButton sab = new JButton(); - - /** - * Constructor for the mechanic. - * @param tmpX X coordinate of the mechanic. - * @param tmpY Y coordinate of the mechanic. - * @param tmpX - * @param tmpY - */ - public SaboteurDraw(int tmpX, int tmpY) { - x = tmpX; - y = tmpY; - sab.setVisible(true); - } - - /** - * Draw method for the mechanic. - * @param panel - * @param g - */ - @Override - public void Draw(JPanel panel, Graphics2D g) { - Saboteur s = (Saboteur)ViewGame.objectDrawNames.get(this); - Player current = Controller.getActivePlayer(); - sabName = Controller.objectReverseNames.get(s); - sab.setText(sabName); - Field f = s.getStandingField(); - if (f instanceof Pipe) { - PipeDraw pd = (PipeDraw)ViewGame.objectDrawReverseNames.get(f); - ArrayList players = f.getPlayers(); - int i = players.indexOf(s); - x = (pd.getxFrom()+pd.getxTo())/2-25; - y = (pd.getYFrom()+pd.getYTo())/2 - (i+1)*25; - } - else if (f instanceof Pump) { - PumpDraw pd = (PumpDraw)ViewGame.objectDrawReverseNames.get(f); - ArrayList players = f.getPlayers(); - int i = players.indexOf(s); - x = pd.getX(); - y = pd.getY() - (i+1)*25; - } - else if (f instanceof Cistern) { - CisternDraw pd = (CisternDraw)ViewGame.objectDrawReverseNames.get(f); - ArrayList players = f.getPlayers(); - int i = players.indexOf(s); - x = pd.getX(); - y = pd.getY() - (i+1)*25; - } - else if (f instanceof Spring) { - SpringDraw pd = (SpringDraw)ViewGame.objectDrawReverseNames.get(f); - ArrayList players = f.getPlayers(); - int i = players.indexOf(s); - x = pd.getX(); - y = pd.getY() - (i+1)*25; - } - sab.setBounds(x, y, 50, 20); - if (s.equals(current)) sab.setBorder(BorderFactory.createLineBorder(Color.green, 5)); - else sab.setBorder(BorderFactory.createLineBorder(Color.red, 5)); - panel.add(sab); - panel.repaint(); - } -} diff --git a/src/main/java/Drawing/SpringDraw.java b/src/main/java/Drawing/SpringDraw.java deleted file mode 100644 index 7a47545..0000000 --- a/src/main/java/Drawing/SpringDraw.java +++ /dev/null @@ -1,43 +0,0 @@ -package main.java.drawing; - -import javax.swing.*; - -import main.java.control.ViewGame; - -import java.awt.*; - -public class SpringDraw extends Drawable { - JButton spring = new JButton(); - JButton springB = new JButton(); - - public SpringDraw(int tmpX, int tmpY) { - x = tmpX; - y = tmpY; - spring.setVisible(true); - spring.setBackground(new Color(150, 75, 0)); - - ViewGame.buttonToElement.put(springB, this); - springB.addActionListener(ViewGame.selectListener); - - } - - @Override - public void Draw(JPanel panel, Graphics2D g) { - spring.setBounds(x, y, 50, 50); - spring.setBorder(BorderFactory.createLineBorder(Color.white, 5)); - - if(ViewGame.getChosen()) { - springB.setVisible(true); - springB.setBackground(new Color(255, 0, 0)); - springB.setBounds(x, y, 50, 50); - springB.setBorder(BorderFactory.createLineBorder(Color.white, 5)); - panel.add(springB); - } else { - springB.setVisible(false); - panel.remove(springB); - } - - panel.add(spring); - panel.repaint(); - } -} diff --git a/src/main/java/Enums/Fluid.java b/src/main/java/Enums/Fluid.java deleted file mode 100644 index c046226..0000000 --- a/src/main/java/Enums/Fluid.java +++ /dev/null @@ -1,5 +0,0 @@ -package main.java.enums; - -public enum Fluid { - DRY, STICKY, SLIPPERY -} \ No newline at end of file diff --git a/src/main/java/Fields/ActiveFields/ActiveFields.java b/src/main/java/Fields/ActiveFields/ActiveFields.java deleted file mode 100644 index a9bc09c..0000000 --- a/src/main/java/Fields/ActiveFields/ActiveFields.java +++ /dev/null @@ -1,78 +0,0 @@ -package main.java.fields.activefields; - -import main.java.fields.Field; -import main.java.fields.Pipe; -import main.java.players.Player; - -import java.util.ArrayList; - -/** - * Abstract class for active fields. - * */ -public abstract class ActiveFields extends Field { - - /** - * Pipes connected to the active field. Default is empty. - */ - private ArrayList pipes = new ArrayList<>(); - @Override - public ArrayList getNeighborFields(){ return new ArrayList<>(pipes);} - /** - * Getter for pipes. Only for child classes. - * @return The pipes connected to the active field - */ - public ArrayList getPipes() { - if (pipes.isEmpty()) return new ArrayList<>(); - return pipes; - } - - /** - * Setter for pipes. Only for initialization. - */ - public void setPipes(ArrayList pipes) { //Basic setter if it is needed - this.pipes = pipes; - } - - /** - * Method for adding a pipe to the active field. - * @param p The pipe to be added - * @return True if the pipe was added - */ - @Override - public boolean addPipe(Pipe p) { - pipes.add(p); - return true; - } - - /** - * Method for removing a pipe from the active field. - * @param p The pipe to be removed - * @return True if the pipe was removed - */ - @Override - public boolean removePipe(Pipe p) { - pipes.remove(p); - return true; - } - - /** - * Method for the game controlled events. - */ - @Override - public void step() { - } - - /** - * Methods for accepting players. - * - * @param p The player to be accepted. - * @return - */ - @Override - public Field accept(Player p) { - this.setOccupied(false); - this.setPlayers(p); - return this; - } - -} diff --git a/src/main/java/Fields/ActiveFields/Cistern.java b/src/main/java/Fields/ActiveFields/Cistern.java deleted file mode 100644 index f6fedff..0000000 --- a/src/main/java/Fields/ActiveFields/Cistern.java +++ /dev/null @@ -1,99 +0,0 @@ -package main.java.fields.activefields; - -import main.java.control.Controller; -import main.java.fields.Pipe; -import main.java.players.Player; -import main.java.stringresource.StringResourceController; - -import java.util.ArrayList; -import java.util.Random; - -/** - * Class for Cistern - * */ -public class Cistern extends ActiveFields{ - private Random random = new Random(); - /** - * Last created Pipe. Null if the last pump was just taken. - */ - private Pipe createdPipe; - /** - * Constructor for the cistern. - */ - public Cistern() { - createdPipe = null; - super.setWater(0); - } - - /** - * Method for the game controlled events. - * Gets the water from the pipes and stores it. - * Creates a new pipe - */ - @Override - public void step() { - if (!getPipes().isEmpty()) { - for (Pipe pipe : getPipes()) { - super.setWater(super.getWater() + pipe.getWater()); - } - } - if(createdPipe == null){ - if(Controller.isTest()){ - createdPipe = new Pipe(65); - } - else createdPipe = new Pipe(30+random.nextInt(41)); - } - } - - /** - * Method for creating a new pump. - * @param b True if the player get a new pump. - * @return The new pump. - * */ - @Override - public Pump createNewPump(boolean b) { - if(b){ - if(Controller.isTest()){ - return new Pump(100); - } - else return new Pump(80+random.nextInt(41)); - } - else return null; - } - - /** - * Method for picking up a (new) pipe from the field. - * @return The new pipe. - */ - @Override - public Pipe pickUpPipe() { - Controller.waterCounter.addPipe(createdPipe); - Controller.pipes++; - Controller.objectNames.put("newPipe"+Controller.pipes, createdPipe); - Controller.objectReverseNames.put(createdPipe, "newPipe"+Controller.pipes); - this.addPipe(createdPipe); - createdPipe.connect(this); - Pipe tmp = createdPipe; - createdPipe = null; - return tmp; - } - /** - * Method for getting a string containing all the important information about the cistern. - * @return String - returns the important information. - */ - @Override - public String toString() { - ArrayList players = this.getPlayers(); - String playerBuilder = StringResourceController.stringBuilder(players); - - ArrayList pipes = this.getPipes(); - String pipeBuilder = StringResourceController.stringBuilder(pipes); - - return "name: "+ Controller.objectReverseNames.get(this) - + "\noccupied: " + this.isOccupied() - + "\nwater: " + getWaterNoChange() - + "\nbroken: " + this.isBroken() - + "\nplayers: " + playerBuilder - + "\npipes: " + pipeBuilder + "\n"; - } -} diff --git a/src/main/java/Fields/ActiveFields/Pump.java b/src/main/java/Fields/ActiveFields/Pump.java deleted file mode 100644 index ca1fa5e..0000000 --- a/src/main/java/Fields/ActiveFields/Pump.java +++ /dev/null @@ -1,167 +0,0 @@ -package main.java.fields.activefields; - -import main.java.control.Controller; -import main.java.fields.Pipe; -import main.java.players.Player; -import main.java.stringresource.StringResourceController; - -import java.util.ArrayList; -import java.util.Random; - -/** - * Class for Pump - * */ -@SuppressWarnings("UnusedAssignment") -public class Pump extends ActiveFields { - private Random random = new Random(); - /** - * The amount of water in the tank. Default value is 0. - */ - private final int tank; - - /** - * The index of the pipe from which the pump gets water. - */ - private int waterFrom; - - /** - * The index of the pipe to which the pump gives water. - */ - private int waterTo; - - /** - * Constructor for the pump. - */ - public Pump(int tank) { - this.tank = tank; - this.waterFrom = -1; - this.waterTo = -1; - } - /** - * Getter for the tank. - * @return tank - returns tank. - */ - public int getTank() { return tank; } - - /** - * Setter for the waterFrom. - * @param waterFrom The index of the pipe from which the pump gets water. Only for initialization. - */ - public void setWaterFrom(int waterFrom) { - this.waterFrom = waterFrom; - } - /** - * Getter for the waterFrom. - * @return waterFrom - returns waterFrom. - */ - public int getWaterFrom() { return waterFrom; } - /** - * Setter for the waterTo. - * @param waterTo The index of the pipe to which the pump gives water. Only for initialization. - */ - public void setWaterTo(int waterTo) { - this.waterTo = waterTo; - } - /** - * Getter for the waterTo. - * @return waterTo - returns waterTo. - */ - public int getWaterTo() { return waterTo; } - /** - * Method for the game controlled events. - * Gets the water pumps the water from the tank to the pipe and gets the water from the input and store it. - */ - @Override - public void step() { - super.step(); - if(!(super.isBroken()) && waterTo != -1 && waterFrom != -1) { - super.setWater((this.getPipes().get(waterTo)).fillInWater(super.getWater())); - int newWater = (this.getPipes().get(waterFrom)).getWater(); - if(newWater < 0) this.getPipes().get(waterFrom).fillInWater(-newWater); - else{ - if(super.getWaterNoChange() + newWater > tank){ - super.setWater(tank); - this.getPipes().get(waterFrom).fillInWater(newWater-tank); - } - else super.setWater(super.getWaterNoChange() + newWater); - } - } - int r; - if (!Controller.isTest()) { - r = random.nextInt(31); - - if(r < 3) { - super.setBroken(true); - } - } - } - /** - * Method for setting the water flow in the pump. - * @param input Pipe - The input pipe of the pump. - * @param output Pipe - The output pipe of the pump. - * @return True if the water flow was set. - always false. - * */ - @Override - public boolean set(Pipe input, Pipe output) { - int newWaterFrom = this.getPipes().indexOf(input); - int newWaterTo = this.getPipes().indexOf(output); - if(newWaterFrom == -1 || newWaterTo == -1) return false; - this.setWaterFrom(newWaterFrom); - this.setWaterTo(newWaterTo); - return true; - } - /** - * Method for repairing the pump. - * @return true - Always true. - * */ - @Override - public boolean repair() { - super.setBroken(false); - return true; - } - /** - * Method for getting a string containing all the important information about the pump. - * @return String - returns the important information. - */ - @Override - public String toString() { - - - String playersNames = getPlayerNames(); - - String pipesNames = getPipeNames(); - - - String sWaterFrom=""; - String sWaterTo=""; - if(getWaterFrom() == -1 && getWaterTo() == -1 ){ - sWaterFrom = sWaterTo = "null"; - } - else{ - sWaterFrom = ""+Controller.objectReverseNames.get(getPipes().get(getWaterFrom())); - sWaterTo = ""+Controller.objectReverseNames.get(getPipes().get(getWaterTo())); - } - - - return "name: "+ Controller.objectReverseNames.get(this) - + "\noccupied: " + this.isOccupied() - + "\nwater: " + getWaterNoChange() - + "\nbroken: " + this.isBroken() - + "\nplayers: " + playersNames - + "\npipes: " + pipesNames - + "\ntank: " + this.getTank() - + "\nwaterFrom: " +sWaterFrom - + "\nwaterTo: " +sWaterTo + "\n"; - } - - private String getPlayerNames() { - ArrayList players = this.getPlayers(); - return StringResourceController.stringBuilder(players); - } - - - private String getPipeNames(){ - ArrayList pipes = this.getPipes(); - return StringResourceController.stringBuilder(pipes); - } -} diff --git a/src/main/java/Fields/ActiveFields/Spring.java b/src/main/java/Fields/ActiveFields/Spring.java deleted file mode 100644 index 822e46b..0000000 --- a/src/main/java/Fields/ActiveFields/Spring.java +++ /dev/null @@ -1,79 +0,0 @@ -package main.java.fields.activefields; - -import main.java.control.Controller; -import main.java.fields.Pipe; -import main.java.players.Player; -import main.java.stringresource.StringResourceController; - -import java.util.ArrayList; - -/** - * Class for Spring - * */ -public class Spring extends ActiveFields{ - - /** - * The amount of water that the spring gives out. Default value is maxOutWater. - */ - int waterOut; - /** - * The maximum amount of water that the spring can give out. - */ - int maxOutWater; - - /** - * Constructor for Spring. - * @param maxOutWater The maximum amount of water that the spring can give out. - */ - public Spring(int maxOutWater) { - this.waterOut = maxOutWater; - this.maxOutWater = maxOutWater; - } - /** - * Getter for waterOut. - * @return waterOut - returns waterOut. - */ - public int getWaterOut() { return waterOut; } - /** - * Getter for maxOutWater. - * @return maxOutWater - returns maxOutWater. - */ - public int getMaxOutWater() { return maxOutWater; } - - /** - * Method for the game controlled events. - * Give the water to the pipes. - */ - @Override - public void step() { - waterOut = maxOutWater; - for(int i = 0; i < this.getPipes().size(); i++){ - waterOut = getPipes().get(i).fillInWater(waterOut); - if(waterOut <= 0){ - break; - } - } - } - /** - * Method for getting a string containing all the important information about the spring. - * @return String - returns the important information. - */ - @Override - public String toString() { - ArrayList players = this.getPlayers(); - String playerBuilder = StringResourceController.stringBuilder(players); - - - ArrayList pipes = this.getPipes(); - String pipeBuilder = StringResourceController.stringBuilder(pipes); - - return "name: "+ Controller.objectReverseNames.get(this) - + "\noccupied: " + this.isOccupied() - + "\nwater: " + getWaterNoChange() - + "\nbroken: " + this.isBroken() - + "\nplayers: " + playerBuilder - + "\npipes: " + pipeBuilder - + "\nwaterOut: " + this.getWaterOut() - + "\nmaxOutWater: " + this.getMaxOutWater() + "\n"; - } -} \ No newline at end of file diff --git a/src/main/java/Fields/Field.java b/src/main/java/Fields/Field.java deleted file mode 100644 index 21830c1..0000000 --- a/src/main/java/Fields/Field.java +++ /dev/null @@ -1,257 +0,0 @@ -package main.java.fields; - -import main.java.fields.activefields.ActiveFields; -import main.java.fields.activefields.Pump; -import main.java.interfaces.Steppable; -import main.java.players.Player; - -import java.util.ArrayList; - -/** - * Abstract class for the fields. - * */ -public abstract class Field implements Steppable { - - /** - * True if the field is cannot accept more player. - * */ - private boolean occupied; - - /** - * The amount of water in the field. - * */ - private int water; - - /** - * True if the field is broken. - * */ - private boolean broken; - - /** - * Players on the field. - * */ - private ArrayList players = new ArrayList<>(); - - /** - * Getter for the occupied variable. Only for child classes. - * @return occupied variable. - * */ - public boolean isOccupied() { - return occupied; - } - - /** - * Getter for the broken variable. Only for child classes. - * @return broken variable. - */ - public boolean isBroken() { - return broken; - } - - /** - * Getter for the players. Only for child classes. - * @return players. - */ - public ArrayList getPlayers() { //Basic getter if it is needed - return players; - } - - public ArrayList getNeighborFields(){ return new ArrayList<>();} - /** - * Setter for players list. - */ - public void setPlayers(Player p) { - players.add(p); - } - - /** - * Setter for the broken variable. - */ - public void setBroken(boolean broken) { - this.broken = broken; - } - - /** - * Setter for the occupied variable. Only for child classes. - * */ - public void setOccupied(boolean occupied) { - this.occupied = occupied; - } - - /** - * Setter for the water variable. Only for child classes. - * */ - public void setWater(int water) { - this.water = water; - } - - /** - * Methods for accepting players. - * - * @param p The player to be accepted. - * @return True if the player was accepted. - always false. - */ - public Field accept(Player p) { - return this; - } - - - /** - * Method for checking if the field is neighbour of the given field. - * @param f The field to be checked. - * @return True if the field is neighbour. - always false. - * */ - public boolean checkNeighbour(Field f) { //Not used in the skeleton. Probably it will be removed from Proto. - return false; - } - - /** - * Method for removing a player from the field. - * @param p The player to be removed. - * The player must be on the field. - * @return True if the player was removed. - always false. - * */ - public boolean removePlayer(Player p) { - setOccupied(false); - players.remove(p); - return true; - } - - /** - * Method for breaking the field. - * @return True if the field was broken. - always false. - * */ - public boolean breakField() { - return false; - } - - /** - * Method for setting the water flow in the pump. - * @param input Pipe - The input pipe of the pump. - * @param output Pipe - The output pipe of the pump. - * @return True if the water flow was set. - always false. - * */ - public boolean set(Pipe input, Pipe output) { - return false; - } - - /** - * Method for repairing the field. - * @return True if the field was repaired. - always false. - * */ - public boolean repair() { - return false; - } - - /** - * Method for placing a pump on the field. - * @param p The pump to be placed. - * @return True if the pump was placed. - always false. - * */ - public Pipe placePump(Pump p) { - return null; - } - - /** - * Method for creating a new pump. - * @param b True if the player get a new pump. - * @return The new pump. - always null. - * */ - public Pump createNewPump(boolean b) { - return null; - } - - /** - * Method for getting the water from the field. - * Prints the amount of water taken. - * @return The amount of water in the field. - always 0. - * */ - public int getWater() { - return water; - } - - /** - * Method for getting the amount of water in field without removing it. - * @return water in field. - */ - public int getWaterNoChange(){ - //It has different implementaion later - return water; - } - - /** - * Method for adding a pipe to the field. - * @param p The pipe to be added. - * @return True if the pipe was added. - always false. - * */ - public boolean addPipe(Pipe p) { - return false; - } - - /** - * Method for removing a pipe from the field. - * @param p The pipe to be removed. - * @return True if the pipe was removed. - always false. - * */ - public boolean removePipe(Pipe p) { - return false; - } - - /** - * Method for getting a new pipe from the field. - * @return The new pipe. - always null. - * */ - public Pipe pickUpPipe() { - return null; - } - - /** - * Method for filling the field with water. - * @param i The amount of water to be filled. - * @return The amount of water that was not filled. - always 0. - * */ - public int fillInWater(int i) { - return 0; - } - - /** - * Method for setting the end of the pipe at a pump. - * @param p The pump to be set on. - * @return True if the end was set. - always false. - * */ - public boolean setEnd(Pump p) { - return false; - } - - /** - * Method for connecting the field to the active fields. - * @param a The active fields to be connected. - * @return True if the field was connected. - always false. - * */ - public boolean connect(ActiveFields a) { - return false; - } - - /** - * Method for disconnecting the field from the active fields. - * @param a The active fields to be disconnected. - * @return True if the field was disconnected. - always false. - * */ - public boolean disconnect(ActiveFields a) { - return false; - } - /** - * Method for making the field slippery. - * @return True if the field became slippery. - always false. - * */ - public boolean makeSlippery(){ - return false; - } - /** - * Method for making the field sticky. - * @return True if the field became sticky. - always false. - * */ - public boolean makeSticky(){ - return false; - } -} diff --git a/src/main/java/Fields/Pipe.java b/src/main/java/Fields/Pipe.java deleted file mode 100644 index 2f05131..0000000 --- a/src/main/java/Fields/Pipe.java +++ /dev/null @@ -1,361 +0,0 @@ -package main.java.fields; - -import main.java.control.Controller; -import main.java.enums.Fluid; -import main.java.fields.activefields.ActiveFields; -import main.java.fields.activefields.Pump; -import main.java.players.Player; -import main.java.stringresource.StringResourceController; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -/** - * Class for Pipes - * */ -public class Pipe extends Field { - private final Random random = new Random(); - /** - * Capacity of the pipe - */ - private final int capacity; - /** - * Time left until the pipe can be broken - */ - private int breakable = 0; - /** - * Time left until the pipe is sticky or slippery - */ - private int remainingFluidTime = 0; - /** - * If true the player can leave the pipe. Is false they can't - */ - private boolean leave = true; - /** - * Fluid state of pipe - */ - private Fluid fluid = Fluid.DRY; - - /** - * The ends of the pipe. Default is empty. - */ - private List fields = new ArrayList<>(); - - /** - * Constructor for Pipe - * @param capacity Capacity of the pipe - */ - public Pipe(int capacity) { - this.capacity = capacity; - } - - /** - * Setter for capacity. Only for initialization. - */ - public void setFields(List fields) { - this.fields = fields; - } - /** - * Setter for field. - */ - public void setFields(ActiveFields a){fields.add(a);} - /** - * Setter for breakable. - */ - public void setBreakable(int breakable) { - this.breakable = breakable; - } - /** - * Setter for remainingFluidTime. - */ - public void setFluidTime(int remainingFluidTime) { - this.remainingFluidTime = remainingFluidTime; - } - /** - * Setter for leave. - */ - public void setLeave(boolean leave) { - this.leave = leave; - } - /** - * Setter for fluid. - */ - public void setFluid(Fluid fluid) { - this.fluid = fluid; - } - /** - * Getter for fields as ActiveFields. - */ - public List getFields() { return fields; } - /** - * Getter for fields as Field. - */ - @Override - public ArrayList getNeighborFields(){ return new ArrayList<>(fields);} - /** - * Getter for capacity. - */ - public int getCapacity() { return capacity; } - /** - * Getter for breakable. - */ - public int getBreakable() { return breakable; } - /** - * Getter for remainingFluidTime. - */ - public int getRemainingFluidTime() { return remainingFluidTime; } - /** - * Getter for leave. - */ - public boolean getLeave() { return leave; } - /** - * Getter for fluid. - */ - public Fluid getFluid() { return fluid; } - - /** - * Method for breaking the pipe. - * @return True if the pipe is broken - */ - @Override - public boolean breakField() { - if(this.breakable > 0) return false; - this.setBroken(true); - return true; - } - - /** - * Method for repairing the pipe. - * @return True if the pipe is repaired - */ - @Override - public boolean repair() { - super.setBroken(false); - if (Controller.isTest()) { - breakable = 5; - } - else { - breakable = 3+ random.nextInt(8); - } - return true; - } - - /** - * Method for placing a pump on the pipe. - * @param newPump The pump to be placed - * @return True if the pump was placed - */ - @Override - public Pipe placePump(Pump newPump) { - if(newPump == null) { return null; } - ActiveFields oldPump = fields.remove(0); - - disconnect(oldPump); - - connect(newPump); - - oldPump.removePipe(this); - Pipe newPipe; - if(Controller.isTest()) { - newPipe = new Pipe(50); - } - else newPipe = new Pipe(30+random.nextInt(41)); - newPipe.connect(newPump); - - newPipe.connect(oldPump); - - newPump.addPipe(this); - newPump.addPipe(newPipe); - - oldPump.addPipe(newPipe); - - newPump.set(newPipe, this); - - return newPipe; - } - - - /** - * Method for getting the water from the pipe. - * Prints the amount of water taken. - * @return The amount of water in the pipe - */ - @Override - public int getWater() { - int w = super.getWaterNoChange(); - super.setWater(0); - return ((super.isBroken()) || (this.fields.size() < 2)) ? -w : w; - } - - /** - * Method for filling the pipe with water. - * Prints the amount of water returned. - * @param i The amount of water to be filled in - * @return The amount of water that was not filled in - */ - @Override - public int fillInWater(int i) { - int waterRightNow = super.getWaterNoChange(); - if(waterRightNow == capacity) return i; - if (i - (capacity- waterRightNow) > 0) { - super.setWater(capacity - waterRightNow); - return i - (capacity-waterRightNow); - } - else { - super.setWater(i); - return 0; - } - } - - - /** - * Method for connecting the pipe to an ActiveField. - * @param a The ActiveField to be connected to the pipe - * @return True if the pipe was connected to the ActiveField - */ - @Override - public boolean connect(ActiveFields a) { - fields.add(a); - return true; - } - - /** - * Method for disconnecting the pipe to an ActiveField. - * @param a The ActiveField to be disconnected to the pipe - * @return True if the pipe was disconnected to the ActiveField - */ - @Override - public boolean disconnect(ActiveFields a) { - fields.remove(a); - return true; - } - - /** - * Methods for accepting players. - * - * @param p The player to be accepted. - * @return True if the player was accepted. - */ - @Override - public Field accept(Player p) { - if(this.isOccupied()) - return null; - if(fluid == Fluid.SLIPPERY){ - int index; - if (Controller.isTest()) { - index = 1; - } - else { - index = random.nextInt(2); - } - fields.get(index).accept(p); - return fields.get(index); - } - else { - this.setOccupied(true); - this.setPlayers(p); - } - return this; - } - /** - * Methods for removing players. - * - * @param p The player to be removed. - * @return True if the player was removed. - */ - @Override - public boolean removePlayer(Player p){ - if(fluid == Fluid.STICKY){ - if(leave){ - leave = false; - setOccupied(false); - getPlayers().remove(p); - return true; - } - return false; - } - setOccupied(false); - getPlayers().remove(p); - return true; - } - /** - * Methods for making the pipe slippery. - * @return True if the pipe successfully became slippery. - */ - @Override - public boolean makeSlippery(){ - if(fluid == Fluid.STICKY) return false; - if(remainingFluidTime == 0){ - if (Controller.isTest()) { - remainingFluidTime = 5; - } - else { - remainingFluidTime = 3+random.nextInt(3); - } - fluid = Fluid.SLIPPERY; - return true; - } - return false; - } - /** - * Methods for making the pipe sticky. - * @return True if the pipe successfully became sticky. - */ - @Override - public boolean makeSticky(){ - if(fluid == Fluid.SLIPPERY) return false; - if(remainingFluidTime == 0){ - if (Controller.isTest()) { - remainingFluidTime = 5; - } - else { - remainingFluidTime = 3+random.nextInt(3); - } - fluid = Fluid.STICKY; - return true; - } - return false; - } - /** - * Method for the game controlled events. - * Reduces the amount of time left until the pipe becomes dry. - * If the time is 0 makes the pipe dry. - */ - @Override - public void step(){ - if(breakable > 0){ - breakable--; - } - if(remainingFluidTime > 0){ - remainingFluidTime--; - if(remainingFluidTime == 0){ - fluid = Fluid.DRY; - leave = true; - } - } - } - /** - * Method for getting a string containing all the important information about the pipe. - * @return String - returns the important information. - */ - @Override - public String toString() { - ArrayList players = this.getPlayers(); - String playerBuilder = StringResourceController.stringBuilder(players); - - List localFields = this.getFields(); - String fieldBuilder = StringResourceController.stringBuilder(localFields); - return "name: " + Controller.objectReverseNames.get(this) - + "\noccupied: " + this.isOccupied() - + "\nwater: " + getWaterNoChange() - + "\nbroken: " + this.isBroken() - + "\nplayers: " + playerBuilder - + "\nfields: " + fieldBuilder - + "\ncapacity: " + this.getCapacity() - + "\nbreakable: " + this.getBreakable() - + "\nrfluidtime: " + this.getRemainingFluidTime() - + "\nleave: " + this.getLeave() - + "\nfluid: " + this.getFluid().toString().toLowerCase() + "\n"; - } -} \ No newline at end of file diff --git a/src/main/java/Interfaces/Steppable.java b/src/main/java/Interfaces/Steppable.java deleted file mode 100644 index d7b10b2..0000000 --- a/src/main/java/Interfaces/Steppable.java +++ /dev/null @@ -1,13 +0,0 @@ -package main.java.interfaces; - -/** - * Steppable interface. - * Provide a method for the game controlled events. - * */ -public interface Steppable { - - /** - * Method for the game controlled events. - * */ - void step(); -} \ No newline at end of file diff --git a/src/main/java/Players/Mechanic.java b/src/main/java/Players/Mechanic.java deleted file mode 100644 index 394e192..0000000 --- a/src/main/java/Players/Mechanic.java +++ /dev/null @@ -1,141 +0,0 @@ -package main.java.players; - -import main.java.control.Controller; -import main.java.fields.Pipe; -import main.java.fields.activefields.ActiveFields; -import main.java.fields.activefields.Pump; - - -/** - * Class for the mechanic player. - * */ -public class Mechanic extends Player { - - /** - *The pump that the mechanic is holding. Default is null. - */ - private Pump holdingPump; - /** - *The pipe that the mechanic is holding. Default is null. - */ - private Pipe holdingPipe; - - /** - * Constructor for the mechanic. - * holdingPipe = null; - * holdingPump = null; - */ - public Mechanic() { - this.holdingPipe = null; - this.holdingPump = null; - } - - /** - * Setter for the holdingPump. - * @param holdingPump The pump that the mechanic is holding. - */ - public void setHoldingPump(Pump holdingPump) { - this.holdingPump = holdingPump; - } - /** - * Getter for the holdingPump. - * @return holdingPump - */ - public Pump getHoldingPump() { return holdingPump; } - - /** - * Setter for the holdingPipe. - * @param holdingPipe The pipe that the mechanic is holding. - */ - public void setHoldingPipe(Pipe holdingPipe) { //Basic setter for the holdingPipe. - this.holdingPipe = holdingPipe; - } - /** - * Getter for the holdingPipe. - * @return holdingPipe - */ - public Pipe getHoldingPipe() { return holdingPipe; } - /** - *Method for repairing the field where the player is standing. - * @return boolean - returns true if the field is repaired. - */ - @Override - public boolean repair() { - return getStandingField().repair(); - } - - /** - *Method for placing a pump on the field where the player is standing. - * @return Pipe - The other (new) half of the pipe. - */ - @Override - public Pipe placePump() { - Pipe p = getStandingField().placePump(holdingPump); - if(p != null) holdingPump = null; - return p; - } - - /** - * Method for disconnecting a pipe from a pump. - * @param p Pipe - * The pipe that will be disconnected. - * @return boolean - returns true if the pipe is disconnected. - */ - @Override - public boolean disconnect(Pipe p) { - boolean result = super.getStandingField().removePipe(p); - boolean result2 = false; - if(result) { - result2 = p.disconnect((ActiveFields) super.getStandingField()); - if(result2) holdingPipe = p; - } - return result && result2; - } - - /** - * Method for connecting the holdingPipe to a pump. - * @return boolean - returns true if the pipe is connected. - */ - @Override - public boolean connect() { - if(holdingPipe == null) return false; - boolean result = super.getStandingField().addPipe(holdingPipe); - if(!result){ return false; } - boolean b = holdingPipe.connect((ActiveFields)super.getStandingField()); - if(b) holdingPipe = null; - return b; - } - - /** - * Method for getting a pump from the field where the player is standing. - * @return Pump - The new pump. - */ - @Override - public Pump getPump() { - boolean b = false; - if(holdingPump == null) b = true; - holdingPump = getStandingField().createNewPump(b); - return holdingPump; // mechanic can get a new pump - } - - /** - * Method for picking up a new pipe from the field where the player is standing. - * @return boolean - returns true if the pipe is picked up. - */ - @Override - public boolean pickUpPipe() { - holdingPipe = super.getStandingField().pickUpPipe(); - return holdingPipe != null; - } - /** - * Method for getting a string containing all the important information about the mechanic. - * @return String - returns the important information. - */ - @Override - public String toString() { - return "name: "+ Controller.objectReverseNames.get(this) - + "\nstandingField: " + Controller.objectReverseNames.get(this.getStandingField()) - + "\nholdingPipe: " + Controller.objectReverseNames.get(this.getHoldingPipe()) - + "\nholdingPump: " + Controller.objectReverseNames.get(this.getHoldingPump()) + "\n"; - } -} \ No newline at end of file diff --git a/src/main/java/Players/Player.java b/src/main/java/Players/Player.java deleted file mode 100644 index d890501..0000000 --- a/src/main/java/Players/Player.java +++ /dev/null @@ -1,148 +0,0 @@ -package main.java.players; - -import main.java.fields.Field; -import main.java.fields.Pipe; -import main.java.fields.activefields.Pump; - -/** - * Abstract class for the players. - * */ -public abstract class Player { - - /** - * The field where the player is standing. - * */ - private Field standingField; - - /** - * Getter for the standingField. Only for child classes. - * @return standingField - */ - public Field getStandingField() { - return standingField; - } - - /** - * Constructor for the player. - */ - protected Player() { - } - - /** - * Setter for the standingField. Only for child classes. - * @param standingField The field where the player is standing. - */ - public void setStandingField(Field standingField) { - this.standingField = standingField; - } - - /** - * Method for moving the player to a new field. - * @param f Field - The field where the player wants to move. - * @return boolean - always false. - * */ - public boolean move(Field f) { - Field result = f.accept(this); - if(result == null) { - return false; - } - else if(result != f ) { - if (result != standingField) { - boolean result2 = standingField.removePlayer(this); - if (result2) standingField = result; - return result2; - } - return standingField.removePlayer(this); - } - if(result == f){ - boolean result2 = standingField.removePlayer(this); - if(result2){ standingField = result;} - else{ - f.removePlayer(this); - } - return result2; - } - else{ return false;} - } - - /** - * Method for breaking the field where the player is standing. - * @return boolean - always false. - * */ - public boolean breakField() { - return getStandingField().breakField(); - } - - /** - * Method for repairing the field where the player is standing. - * @return boolean - always false. - * */ - public boolean repair() { - return false; - } - - /** - * Method for placing a pump on the field where the player is standing. - * @return Pipe - The other (new) half of the pipe. - always null. - * */ - public Pipe placePump() { - return null; - } - - /** - * Method for setting the water flow in the pump. - * @param input Pipe - The input pipe of the pump. - * @param output Pipe - The output pipe of the pump. - * @return boolean - always false. - * */ - public boolean set(Pipe input, Pipe output) { - return standingField.set(input, output); - } - - /** - * Method for disconnecting a pipe from a pump. - * @param p Pipe - The pipe to be disconnected. - * @return boolean - always false. - * */ - public boolean disconnect(Pipe p) { - return false; - } - - /** - * Method for connecting the holdingPipe to a pump. - * @return boolean - always false. - * */ - public boolean connect() { - return false; - } - - /** - * Method for getting a pump from the field where the player is standing. - * @return Pump - The new pump. - always null. - * */ - public Pump getPump() { - return null; - } - - /** - * Method for picking up a new pipe from the field where the player is standing. - * @return boolean - always false. - * */ - public boolean pickUpPipe() { - return false; - } - /** - * Method for making the field where the player is standing sticky. - * @return boolean - result of making the field sticky. True if successful. - * */ - public boolean makeSticky(){ - return standingField.makeSticky(); - } - /** - * Method for making the field where the player is standing slippery. - * @return boolean - always false. - * */ - public boolean makeSlippery(){ - return false; - } -} \ No newline at end of file diff --git a/src/main/java/Players/Saboteur.java b/src/main/java/Players/Saboteur.java deleted file mode 100644 index f91abd1..0000000 --- a/src/main/java/Players/Saboteur.java +++ /dev/null @@ -1,36 +0,0 @@ -package main.java.players; - -import main.java.control.Controller; - - -/** - * Class for the saboteur player. - * */ -public class Saboteur extends Player { - - /** - * Constructor for the saboteur. - */ - public Saboteur() { - //Nothing can be inicialized here - } - - /** - * Method for making standingField slippery - * @return boolean - returns true if action was successful. - */ - @Override - public boolean makeSlippery(){ - return this.getStandingField().makeSlippery(); - - } - /** - * Method for getting a string containing all the important information about the saboteur. - * @return String - returns the important information. - */ - @Override - public String toString() { - return "name: "+ Controller.objectReverseNames.get(this) - + "\nstandingField: " + Controller.objectReverseNames.get(this.getStandingField()) + "\n"; - } -} diff --git a/src/main/java/StringResource/StringResourceController.java b/src/main/java/StringResource/StringResourceController.java deleted file mode 100644 index a6608b5..0000000 --- a/src/main/java/StringResource/StringResourceController.java +++ /dev/null @@ -1,30 +0,0 @@ -package main.java.stringresource; - -import java.util.List; - -import main.java.control.Controller; - -public final class StringResourceController { - private StringResourceController(){} - public static final String FALSE = "false"; - public static final String FILE_NOT_FOUND = "File not found"; - public static final String WRONG_PLAYER = "Nem te vagy a soron következő játékos!"; - public static final String WRONG_ACTION = "Sikertelen művelet"; - public static final String INVALID_ACTION = "A műveletet nem lehet végrehajtani"; - public static final String GOOD_ACTION = "Sikeres művelet"; - public static final String WATER = "water"; - public static final String RANDOM_ON = "A véletlen események be lettek kapcsolva."; - public static String stringBuilder(List collection){ - StringBuilder builder = new StringBuilder("null"); - if(collection != null) { - for (int i = 0; i < collection.size(); i++) { - if (i == 0) builder.delete(0,4); - builder.append(Controller.objectReverseNames.get(collection.get(i))); - if (i != collection.size() - 1) { - builder.append(", "); - } - } - } - return builder.toString(); - } -} \ No newline at end of file