Skip to content

Commit

Permalink
Duplicate fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Takibalu committed May 20, 2024
1 parent 877e6b4 commit f55f7a2
Show file tree
Hide file tree
Showing 27 changed files with 274 additions and 327 deletions.
33 changes: 33 additions & 0 deletions src/main/java/Assets/Strings.java
Original file line number Diff line number Diff line change
@@ -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";
}
194 changes: 84 additions & 110 deletions src/main/java/Controller/Controller.java

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/main/java/Model/Cistern.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class Cistern extends WaterNode implements Serializable {
/**
* Ciszternáról felvehető elemek, amik generálódtak rajta
*/
private LinkedList<PickupAble> createdPickupables = new LinkedList<>();
private final LinkedList<PickupAble> createdPickupables = new LinkedList<>();
/**
* Ciszternán keletkezett csövek listája
*/
private LinkedList<Pipe> generatedPipes = new LinkedList<>();
private final LinkedList<Pipe> generatedPipes = new LinkedList<>();
/**
* Ciszternán keletkezett pumpák listája
*/
private LinkedList<Pump> generatedPumps = new LinkedList<>();
private final LinkedList<Pump> generatedPumps = new LinkedList<>();

/**
* Pontszámításhoz használt singleton
Expand Down Expand Up @@ -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;
}
Expand Down
33 changes: 15 additions & 18 deletions src/main/java/Model/Pipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/Model/Pump.java
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Model/Spring.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/Model/WaterNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -101,8 +101,10 @@ public LinkedList<Pipe> 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;
}
Expand All @@ -114,6 +116,6 @@ public boolean canMoveFromHere() {
*/
@Override
public boolean canMoveToHere(Player p){
return pipes.contains(p.getStandingOn());
return pipes.contains((Pipe) p.getStandingOn());
}
}
7 changes: 0 additions & 7 deletions src/main/java/View/AddPlayerButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {

}
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/View/CharacterCreation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/View/CisternView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/View/Clickable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
5 changes: 2 additions & 3 deletions src/main/java/View/ColorPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
* <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/colorchooser.html">Java Color Picker</a>
*/
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
Expand All @@ -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:"));
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/View/CreatePopUpBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ 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);
gameView.addPopupBar(p);

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();
Expand All @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/View/Drawable.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -47,4 +50,26 @@ public void paintOnPlayer(int x, int y, Graphics2D graphics2D){

}

public double getPlayerAngle(Player p, LinkedList<Player> 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;
}
}
2 changes: 1 addition & 1 deletion src/main/java/View/ImageUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/View/MechanicView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/View/MenuView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit f55f7a2

Please sign in to comment.