Skip to content

Commit

Permalink
Merge pull request #8 from BME-MIT-IET/bugfix/sonarcloud-issues
Browse files Browse the repository at this point in the history
Fix issues found by SonarCloud
  • Loading branch information
Duhi95 authored May 19, 2024
2 parents f973609 + 6005f03 commit 5bfcb9d
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 129 deletions.
3 changes: 2 additions & 1 deletion src/main/java/ActionButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void actionPerformed(ActionEvent e) {
case "EndMove":
instance.EndMove();
break;

default:
break;
}

}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/Actions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Actions {
private Actions() {}

public static final String MOVE = "Move";
public static final String STAB = "Stab";
public static final String PLACE_PUMP = "PlacePump";
public static final String PLACE_PIPE = "PlacePipe";
public static final String PICKUP_PUMP = "PickupPump";
public static final String PICKUP_PIPE = "PickUpPipe";
public static final String REPAIR = "Repair";
public static final String STICK = "Stick";
public static final String SLIME = "Slime";
public static final String ADJUST = "Adjust";
public static final String END_MOVE = "EndMove";
}
20 changes: 14 additions & 6 deletions src/main/java/Character.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Character osztaly, mely a jatekosok által irányított karaktereket reprezentálja.
* @author Bodnar Mark*/
public abstract class Character {
private String Name;
private int remainingSteps = 3;
private Logger logger;

String getName() {return Name;}
void setName(String name) {this.Name=name;}
public void move(int dir) {}/** Csorendszeren mozgas.*/
Expand All @@ -24,16 +29,19 @@ public int decreaseRemainingSteps() {
}
public synchronized void step() {
resetRemainingSteps();
try{
try {
wait();
}catch(Exception e)
{
e.printStackTrace();
}
catch (ThreadDeath e) {
throw e;
}
catch (Exception e) {
logger.log(Level.FINER, e.toString());
}
}
public void makeSticky(){}/** Ragadossa teszi az adott csovet amin all*/

public synchronized void WakeUp() {
this.notify();
public synchronized void wakeUp() {
this.notifyAll();
}
}
2 changes: 1 addition & 1 deletion src/main/java/Control.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void Adjust(int src, int dest){
*/
public void EndMove(){
updateFrame();
Game.getInstance().getCurrentCharacter().WakeUp();
Game.getInstance().getCurrentCharacter().wakeUp();
}

/**
Expand Down
133 changes: 66 additions & 67 deletions src/main/java/ElementButton.java

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions src/main/java/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static Game getInstance()
* @param pumps A pumpákat tartalmazó lista
*/

public void load(ArrayList<Element> gameE,ArrayList<SaboteurPointSource> SabPointSources,ArrayList<Cistern> cis,
public synchronized void load(ArrayList<Element> gameE,ArrayList<SaboteurPointSource> SabPointSources,ArrayList<Cistern> cis,
ArrayList<Repairman> repairmanG,ArrayList<Saboteur> saboteurG, int repPoints, int sabPoints, int rounds, int _slimey, int _sticky, ArrayList<Pump> pumps)
{
repairmanGroup=repairmanG;
Expand All @@ -89,7 +89,6 @@ public void load(ArrayList<Element> gameE,ArrayList<SaboteurPointSource> SabPoin
remainingRounds=rounds;
slimey = _slimey;
sticky = _sticky;
this.initialize();

timer.resetPumps();
for(Pump p : pumps)
Expand Down Expand Up @@ -146,14 +145,6 @@ public ArrayList<Saboteur> getSaboteurGroup()
{
return saboteurGroup;
}

/**
* Létrehozza a pályát.
*/
public void initialize()
{

}

/**
* Elindítja a játékot, és menedzseli melyik karaknernek van a köre.
Expand Down
41 changes: 18 additions & 23 deletions src/main/java/Gui.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
Expand Down Expand Up @@ -40,6 +33,8 @@ public class Gui {
ArrayList<ElementButton> elementButtons;
private Pipe pi6;

private static final String FONT_FAMILY = "Arial";

// Az egyetlen Gui objektum
private static Gui instance = new Gui();;

Expand All @@ -55,7 +50,7 @@ public static Gui getInstance() {
private Gui(){
// ---------------FRAME INIT-----------------
frame = new JFrame("codeX");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(1280, 720);
frame.setLayout(null); //Lehet jobb lenne, ha csak a gamePanel lenne null layouttal
//frame.setLayout(new BorderLayout()); -- Ezzel megjelenik, de nullal nem
Expand All @@ -69,17 +64,17 @@ private Gui(){

JLabel lRoundSettings = new JLabel("Körök száma");
lRoundSettings.setBounds(450, 100, 300, 30);
lRoundSettings.setFont(new Font("Arial", Font.PLAIN, 30)); // Creating an Arial Font Style with size 30
lRoundSettings.setFont(new Font(FONT_FAMILY, Font.PLAIN, 30)); // Creating an Arial Font Style with size 30
menuPanel.add(lRoundSettings);

JLabel lPlayerCount = new JLabel("Játékosok száma");
lPlayerCount.setBounds(450, 300, 300, 30);
lPlayerCount.setFont(new Font("Arial", Font.PLAIN, 30)); // Creating an Arial Font Style with size 30
lPlayerCount.setFont(new Font(FONT_FAMILY, Font.PLAIN, 30)); // Creating an Arial Font Style with size 30
menuPanel.add(lPlayerCount);

sRoundSettings = new JSpinner(new SpinnerNumberModel(1, 1, 100, 1));
sRoundSettings.setBounds(700, 90, 50, 50);
sRoundSettings.setFont(new Font("Arial", Font.PLAIN, 30));
sRoundSettings.setFont(new Font(FONT_FAMILY, Font.PLAIN, 30));
menuPanel.add(sRoundSettings);
sRoundSettings.addChangeListener(new ChangeListener()
{
Expand All @@ -94,12 +89,12 @@ public void stateChanged(ChangeEvent e) {

sPlayerCount = new JSpinner(new SpinnerNumberModel(4, 4, 8, 2));
sPlayerCount.setBounds(700, 290, 50, 50);
sPlayerCount.setFont(new Font("Arial", Font.PLAIN, 30));
sPlayerCount.setFont(new Font(FONT_FAMILY, Font.PLAIN, 30));
menuPanel.add(sPlayerCount);

JButton bStart = new JButton("Start");
bStart.setBounds(500, 600, 200, 50);
bStart.setFont(new Font("Arial", Font.PLAIN, 30));
bStart.setFont(new Font(FONT_FAMILY, Font.PLAIN, 30));
bStart.setBackground(Color.GRAY);
bStart.setForeground(Color.BLACK);
bStart.addActionListener(e -> nextPanel());
Expand Down Expand Up @@ -151,45 +146,45 @@ public void paintComponent(Graphics g) {

//Scoreboard label
JLabel lScoreBoard = new JLabel("Scoreboard");
lScoreBoard.setFont(new Font("Arial", Font.BOLD, 20));
lScoreBoard.setFont(new Font(FONT_FAMILY, Font.BOLD, 20));
lScoreBoard.setBounds(5, 0, 200, 20);
jPanelScoreBoard.add(lScoreBoard);

//Saboteurs label
JLabel lSaboteurs = new JLabel("Saboteurs");
lSaboteurs.setFont(new Font("Arial", Font.BOLD, 15));
lSaboteurs.setFont(new Font(FONT_FAMILY, Font.BOLD, 15));
lSaboteurs.setBounds(5, 25, 200, 20);
jPanelScoreBoard.add(lSaboteurs);

//Saboteurs points label
lgSaboteurPoints = new JLabel("0");
lgSaboteurPoints.setFont(new Font("Arial", Font.PLAIN, 15));
lgSaboteurPoints.setFont(new Font(FONT_FAMILY, Font.PLAIN, 15));
lgSaboteurPoints.setBounds(100, 25, 200, 20);
jPanelScoreBoard.add(lgSaboteurPoints);

//Repairmen label
JLabel lRepairmen = new JLabel("Repairmen");
lRepairmen.setFont(new Font("Arial", Font.BOLD, 15));
lRepairmen.setFont(new Font(FONT_FAMILY, Font.BOLD, 15));
lRepairmen.setBounds(5, 45, 200, 20);
jPanelScoreBoard.add(lRepairmen);


//Repairmen points label
lgRepairmenPoints = new JLabel("0");
lgRepairmenPoints.setFont(new Font("Arial", Font.PLAIN, 15));
lgRepairmenPoints.setFont(new Font(FONT_FAMILY, Font.PLAIN, 15));
lgRepairmenPoints.setBounds(100, 45, 200, 20);
jPanelScoreBoard.add(lgRepairmenPoints);


//Turn label
JLabel lTurn = new JLabel("Turns: ");
lTurn.setFont(new Font("Arial", Font.BOLD, 15));
lTurn.setFont(new Font(FONT_FAMILY, Font.BOLD, 15));
lTurn.setBounds(5, 65, 200, 20);
jPanelScoreBoard.add(lTurn);

//Turn points label
lTurnPoints = new JLabel("0");
lTurnPoints.setFont(new Font("Arial", Font.PLAIN, 15));
lTurnPoints.setFont(new Font(FONT_FAMILY, Font.PLAIN, 15));
lTurnPoints.setBounds(100, 65, 200, 20);
jPanelScoreBoard.add(lTurnPoints);

Expand All @@ -199,21 +194,21 @@ public void paintComponent(Graphics g) {

//Who`s turn label
lWhosTurn = new JLabel("...-s turn");
lWhosTurn.setFont(new Font("Arial", Font.BOLD, 25));
lWhosTurn.setFont(new Font(FONT_FAMILY, Font.BOLD, 25));
lWhosTurn.setBounds(980, 20, 300, 20);
gamePanel.add(lWhosTurn);

//End Move button
JButton bEndMove = new JButton("End Move");
bEndMove.setBounds(980, 550, 300, 50);
bEndMove.setFont(new Font("Arial", Font.PLAIN, 20));
bEndMove.setFont(new Font(FONT_FAMILY, Font.PLAIN, 20));
bEndMove.setBackground(Color.WHITE);
bEndMove.setForeground(Color.BLACK);
bEndMove.addActionListener(e -> Control.getInstance().EndMove());
gamePanel.add(bEndMove);

JButton bEnd = new JButton("End Game");
bEnd.setFont(new Font("Arial", Font.PLAIN, 20));
bEnd.setFont(new Font(FONT_FAMILY, Font.PLAIN, 20));
bEnd.setBounds(980, 600, 300, 50);
bEnd.addActionListener(e -> nextPanel());
gamePanel.add(bEnd);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/Pipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Pipe extends Element implements SaboteurPointSource {
private int sticky;
private int slimey;
private List<NonPipe> neighbors;
private Random random = new Random();

/**
* @author Szikszai Levente
Expand Down Expand Up @@ -60,7 +61,6 @@ public boolean accept(Character c) {
if (slimey > 0) {
success = false;
if (neighbors.size() > 1) {
Random random = new Random();
if (random.nextBoolean()) {
success = getNeighbors().get(0).accept(c);
Control.getInstance().appendToLog("Slipped to " + getNeighbors().get(0).getName());
Expand Down Expand Up @@ -167,6 +167,10 @@ public Pipe placePump(Pump holdingPump) {
// System.out.println("No placable pump");
}
n = (NonPipe) getNeighbors().get(0);
if (holdingPump == null) {
Control.getInstance().appendToLog("HoldingPump is null, can't place it.");
return null;
}
if (n != null) {
removeNeighbor(n);
n.removeNeighbor(this);
Expand Down Expand Up @@ -199,7 +203,7 @@ public Pipe placePump(Pump holdingPump) {
@Override
public Pipe lift(int dir) {
try {
if (neighbors.size() == 1 && neighbors.get(0).getClass().getName().equals("Cistern")) {
if (neighbors.size() == 1 && neighbors.get(0) instanceof Cistern) {
return this;
}
} catch (IndexOutOfBoundsException e) {
Expand Down
38 changes: 21 additions & 17 deletions src/main/java/Prototype.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Prototípus osztály. Csak tesztelésre (Prototype, nogui Version)
Expand All @@ -25,6 +27,7 @@ public class Prototype {
int ac = 0; //* ActionCounter */

private String selectedMenuItem; /** A kivalasztott parancs */
private Logger logger;

/**
* Inicializálja a Prototype-ot
Expand Down Expand Up @@ -107,10 +110,9 @@ public void load(String file)
pumps.clear();

File f = new File("mapdeclarations/"+file+".txt");
try
try (Scanner sc = new Scanner(f))
{
int readPhase = 0;
Scanner sc = new Scanner(f);
sc.nextLine(); //kidobjuk az első sort
while(sc.hasNext())
{
Expand Down Expand Up @@ -288,16 +290,13 @@ else if(nonpipeN!=null)
int repPoints = 0;
int _slimey = 3;
int _sticky = 3;
try{
File fPoints = new File(file+"Points.txt");
Scanner scPoints = new Scanner(fPoints);

File fPoints = new File(file+"Points.txt");
try (Scanner scPoints = new Scanner(fPoints)){
round = sc.nextInt();
repPoints = sc.nextInt();
sabPoints = sc.nextInt();
_slimey = sc.nextInt();
_sticky = sc.nextInt();
scPoints.close();
}
catch(Exception e)
{
Expand Down Expand Up @@ -428,12 +427,15 @@ public void showMenu() {
*/
public void togglerandom(String param)
{
if(param.equals("I"))
Game.getInstance().setRandomEnabled(true);
else if(param.equals("N"))
Game.getInstance().setRandomEnabled(false);
else
System.out.println("Invalid input");
if (param.equals("I")) {
Game.getInstance().setRandomEnabled(true);
}
else if (param.equals("N")) {
Game.getInstance().setRandomEnabled(false);
}
else {
System.out.println("Invalid input");
}
}

/**
Expand All @@ -459,11 +461,13 @@ private boolean isCurrentRepairman()
*/
public void help()
{
if(isCurrentRepairman())
if(isCurrentRepairman()) {
System.out.println("adjust int int\nmove int\nstab\nrepair\npickuppump\npickuppipe int\nplacepump\nplacepipe\nstick\nendturn\nsave fileName\nload fileName\nhelp\ninfo string\ntogglerandom I/N\nq");
else
System.out.println("adjust int int\nmove int\nstab\nstick\nslime\nendturn\nsave fileName\nload fileName\nhelp\ninfo string\ntogglerandom I/N\nq");
}
else {
System.out.println("adjust int int\nmove int\nstab\nstick\nslime\nendturn\nsave fileName\nload fileName\nhelp\ninfo string\ntogglerandom I/N\nq");
}
}

public void info(String name){
boolean found = false;
Expand Down Expand Up @@ -491,7 +495,7 @@ public void endTurn(){
try{
Game.getInstance().endTurn();
}catch(Exception e){
e.printStackTrace();
logger.log(Level.FINER, e.toString());
}
String prevname = currentCharacter.getName();
if(++currentCharacterInt>=characters.size()){
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/Pump.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ public void step(){
public void breakPump(){
broken=true;
}
public void stick() {};/** Ragadossa teszi az adott poziciot. */
public void slime(){};/** Csuszossa tesz egy csovet. */

/**
* Visszadja a kifolyott viz mennyiseget, majd nullara allitja
Expand Down

0 comments on commit 5bfcb9d

Please sign in to comment.