Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonar fixes #13

Merged
merged 13 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- main
- Manuális-és-statikus-ellenőrzés
- Sonar-Fixes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rendben, jól látható, hogy itt folytatódott a munka.

pull_request:
types: [opened, synchronize, reopened]
jobs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
*.out
*.OUT
/bin/
.idea/*
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

515 changes: 287 additions & 228 deletions src/main/java/Controll/Controller.java

Large diffs are not rendered by default.

25 changes: 8 additions & 17 deletions src/main/java/Controll/Menu.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package Controll;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;

import java.io.FileNotFoundException;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;


public class Menu extends JFrame implements ActionListener {
Expand All @@ -30,7 +24,7 @@ public class Menu extends JFrame implements ActionListener {
public Menu(String name, String t) {
currentTheme = t;
setTitle(name);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
setLayout(null);
setBounds(700, 250, 500, 500);
Expand All @@ -52,11 +46,11 @@ public Menu(String name, String t) {
add(theme);

Integer[] numOfMechanics = {2, 3, 4, 5, 6, 7, 8, 9};
mechanics = new JComboBox<Integer>(numOfMechanics);
mechanics = new JComboBox<>(numOfMechanics);
mechanics.setBounds(300, 165, 40, 20);

Integer[] numOfSaboteurs = {2, 3, 4, 5, 6, 7, 8, 9};
saboteurs = new JComboBox<Integer>(numOfSaboteurs);
saboteurs = new JComboBox<>(numOfSaboteurs);
saboteurs.setBounds(300, 195, 40, 20);

add(mechanics);
Expand Down Expand Up @@ -133,13 +127,10 @@ public void actionPerformed(ActionEvent e) {
Controller.commandList.add("addplayer D Sab" + i);
}
}
try {
Controller.Run(); // egyszer fut le, felépíti a pályát, utána a függvényeit kell majd hívni
} catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}
Controller.Run(); // egyszer fut le, felépíti a pályát, utána a függvényeit kell majd hívni

Controller.create();
Controller.SetActivePlayer(Controller.getAllPlayers().get(0));
Controller.setActivePlayer(Controller.getAllPlayers().get(0));
this.dispose();
ViewGame vg = new ViewGame();
vg.setBackgroundColor(currentTheme);
Expand Down
31 changes: 12 additions & 19 deletions src/main/java/Controll/ViewGame.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package Controll;

import Drawing.*;
import Drawing.Drawable;
import Drawing.PipeDraw;
import Enums.Fluid;
import Fields.*;

import Fields.ActiveFields.*;
import Fields.Pipe;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ViewGame extends JFrame implements ActionListener {

private Controller controller;
private static boolean isChosen = false;
private JPanel gameBackground;

/**
* HashMap for the Drawables
*/
public static HashMap<Drawable, Object> objectDrawNames = new HashMap<>();
public static final Map<Drawable, Object> objectDrawNames = new HashMap<>();
/**
* HashMap for the Drawables
*/
public static HashMap<Object, Drawable> objectDrawReverseNames = new HashMap<>();
public static final Map<Object, Drawable> objectDrawReverseNames = new HashMap<>();


public static ViewGame vg;
Expand Down Expand Up @@ -58,11 +58,11 @@ public class ViewGame extends JFrame implements ActionListener {
/**
* ArrayList for the selected elements
*/
static ArrayList<Object> selectSequence = new ArrayList<Object>(); //kiválasztott elemek, kiválasztásuk sorrendjében
static final List<Object> selectSequence = new ArrayList<>(); //kiválasztott elemek, kiválasztásuk sorrendjében
/**
* HashMap for the buttons
*/
public static HashMap<JButton, Drawable> buttonToElement = new HashMap<JButton, Drawable>(); //kiválasztó gomb -> kiválasztott rajz
public static final Map<JButton, Drawable> buttonToElement = new HashMap<>(); //kiválasztó gomb -> kiválasztott rajz

/**
* Max number of rounds
Expand Down Expand Up @@ -153,16 +153,16 @@ public static boolean getChosen(){
*/
public ViewGame() {
setTitle("Sivatagi vízhálózatok üzemeltetése a gyakorlatban 2");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setResizable(true);
setBounds(400, 150, 1000, 700);
setLayout(new BorderLayout());
gameBackground = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.black);
super.paintComponent(g2d);
int i = 0;
for (Drawable draw : objectDrawReverseNames.values()){
if (draw instanceof PipeDraw) {
Pipe p = (Pipe)ViewGame.objectDrawNames.get(draw);
Expand Down Expand Up @@ -233,18 +233,11 @@ protected void paintComponent(Graphics g) {
vg = this;
}

/**
* Sets the controller
* @param c
*/
public void setController(Controller c){
controller = c;
}

/**
* Paints the objects
* @param g
*/
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/Drawing/CisternDraw.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Drawing;

import Controll.ViewGame;

import javax.swing.*;
import java.awt.*;

Expand Down Expand Up @@ -31,6 +32,7 @@ public CisternDraw(int tmpX, int tmpY) {
* @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));
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/Drawing/PipeDraw.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Drawing/PumpDraw.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public PumpDraw(int tmpX, int tmpY) {
* @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);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Drawing/SaboteurDraw.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Fields.Pipe;
import Players.Player;
import Players.Saboteur;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Drawing/SpringDraw.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Drawing;

import Controll.ViewGame;

import javax.swing.*;
import java.awt.*;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Fields/ActiveFields/ActiveFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public abstract class ActiveFields extends Field {
*/
private ArrayList<Pipe> pipes = new ArrayList<>();
@Override
public ArrayList<Field> getNeighborFields(){ return new ArrayList<Field>(pipes);}
public ArrayList<Field> getNeighborFields(){ return new ArrayList<>(pipes);}
/**
* Getter for pipes. Only for child classes.
* @return The pipes connected to the active field
*/
public ArrayList<Pipe> getPipes() {
if (pipes.size() == 0) return null;
if (pipes.isEmpty()) return new ArrayList<>();
return pipes;
}

Expand Down
49 changes: 10 additions & 39 deletions src/main/java/Fields/ActiveFields/Cistern.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import Controll.Controller;
import Fields.Pipe;
import Players.Player;
import 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.
*/
Expand All @@ -30,17 +32,16 @@ public Cistern() {
*/
@Override
public void step() {
if (getPipes() != null) {
if (!getPipes().isEmpty()) {
for (Pipe pipe : getPipes()) {
super.setWater(super.getWater() + pipe.getWater());
}
}
if(createdPipe == null){
Random r = new Random();
if(Controller.isTest()){
createdPipe = new Pipe(65);
}
else createdPipe = new Pipe(30+r.nextInt(41));
else createdPipe = new Pipe(30+random.nextInt(41));
}
}

Expand All @@ -51,26 +52,15 @@ public void step() {
* */
@Override
public Pump createNewPump(boolean b) {
Random r = new Random();
if(b){
if(Controller.isTest()){
return new Pump(100);
}
else return new Pump(80+r.nextInt(41));
else return new Pump(80+random.nextInt(41));
}
else return null;
}

/**
* Method for getting the water from the field.
* Prints the amount of water taken.
* @return The amount of water in the field.
*/
@Override
public int getWater() {
return super.getWater();
}

/**
* Method for picking up a (new) pipe from the field.
* @return The new pipe.
Expand All @@ -94,35 +84,16 @@ public Pipe pickUpPipe() {
@Override
public String toString() {
ArrayList<Player> players = this.getPlayers();
String playersNames = "null";

for (int i = 0; i < players.size(); i++) {
if(i == 0) playersNames = "";
playersNames += Controller.objectReverseNames.get(players.get(i));
if (i != players.size() - 1) {
playersNames += ", ";
}
}


String playerBuilder = StringResourceController.stingBuilder(players);

ArrayList<Pipe> pipes = this.getPipes();
String pipesNames ="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 != pipes.size() - 1) {
pipesNames += ", ";
}
}
}
String pipeBuilder = StringResourceController.stingBuilder(pipes);

return "name: "+ Controller.objectReverseNames.get(this)
+ "\noccupied: " + this.isOccupied()
+ "\nwater: " + getWaterNoChange()
+ "\nbroken: " + this.isBroken()
+ "\nplayers: " + playersNames
+ "\npipes: " + pipesNames + "\n";
+ "\nplayers: " + playerBuilder
+ "\npipes: " + pipeBuilder + "\n";
}
}
Loading
Loading