Skip to content

Commit

Permalink
Resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
voroscsoki committed May 21, 2024
2 parents d42894b + 9462c97 commit d5df628
Show file tree
Hide file tree
Showing 51 changed files with 4,058 additions and 257 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- Manuális-és-statikus-ellenőrzés
pull_request:
types: [opened, synchronize, reopened]
jobs:
Expand Down
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import javax.swing.WindowConstants;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JTextField;
Expand All @@ -13,7 +16,7 @@


public class Menu extends JFrame implements ActionListener {
private String currentTheme;
public String currentTheme;
private JButton newGame;
private JButton exitGame;
private JButton theme;
Expand All @@ -22,6 +25,8 @@ public class Menu extends JFrame implements ActionListener {
private JTextField mechanic;
private JTextField saboteur;

public static ViewGame vg;

/**
* konstruktor
* @param name az ablak neve
Expand All @@ -30,7 +35,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 +57,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 @@ -112,6 +117,27 @@ public void changeTheme(String s) {
}
}

public JButton getThemeButton() {
return theme;
}

public JButton getPlayButton() {
return newGame;
}

public ArrayList<JButton> getActionButtons() {
ArrayList<JButton> actionButtons = new ArrayList<JButton>();
if (vg == null) return actionButtons;

actionButtons.add(vg.repairButton);
actionButtons.add(vg.breakButton);
actionButtons.add(vg.makeSlipperyButton);
actionButtons.add(vg.makeStickyButton);
actionButtons.add(vg.putDownButton);

return actionButtons;
}

@Override
public void actionPerformed(ActionEvent e) {

Expand All @@ -133,15 +159,12 @@ 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 = new ViewGame();
vg.setBackgroundColor(currentTheme);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import javax.swing.WindowConstants;

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 All @@ -42,14 +44,14 @@ public class ViewGame extends JFrame implements ActionListener {
/**
* Controll buttons
*/
JButton moveButton;
JButton repairButton;
JButton breakButton;
JButton makeSlipperyButton;
JButton makeStickyButton;
JButton pickUpButton;
JButton putDownButton;
JButton setPumpButton;
static JButton moveButton;
static JButton repairButton;
static JButton breakButton;
static JButton makeSlipperyButton;
static JButton makeStickyButton;
static JButton pickUpButton;
static JButton putDownButton;
static JButton setPumpButton;

/**
* Last action
Expand All @@ -58,11 +60,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 @@ -119,13 +121,27 @@ public void actionPerformed(ActionEvent e) {
}
};

public static Menu menu;

/**
* Main method
* @param args
*/
public static void main(String[] args){
Menu menu = new Menu("Menu", "White");
// measure startup time
long startTime = System.currentTimeMillis();

menu = new Menu("Menu", "White");
menu.showMenu();

// measure startup time
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
System.out.println("Startup time: " + duration + "ms");
}

public static Menu getMenuInstance() {
return menu;
}

/**
Expand Down Expand Up @@ -153,16 +169,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 +249,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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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 @@ -36,11 +36,10 @@ public void step() {
}
}
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,12 +50,11 @@ 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* */
@SuppressWarnings("UnusedAssignment")
public class Pump extends ActiveFields {

private Random random = new Random();
/**
* The amount of water in the tank. Default value is 0.
*/
Expand Down Expand Up @@ -73,23 +73,21 @@ public void setWaterTo(int waterTo) {
@Override
public void step() {
super.step();
if(!(super.isBroken())) {
if(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);
}
}
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 = new Random().nextInt(31);
r = random.nextInt(31);

if(r < 3) {
super.setBroken(true);
Expand Down Expand Up @@ -126,29 +124,13 @@ public boolean repair() {
*/
@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 playersNames = getPlayerNames();

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 pipesNames = getPipeNames();


String SWaterFrom="";
Expand All @@ -172,4 +154,33 @@ public String toString() {
+ "\nwaterFrom: " +SWaterFrom
+ "\nwaterTo: " +SWaterTo + "\n";
}

private String getPlayerNames() {
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 += ", ";
}
}
return playersNames;
}


private String getPipeNames(){
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 += ", ";
}
}
}
return pipesNames;
}
}
Loading

0 comments on commit d5df628

Please sign in to comment.