Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
uuzxs committed Mar 6, 2022
2 parents 2d6230f + adf5ab1 commit 6906450
Show file tree
Hide file tree
Showing 77 changed files with 443 additions and 679 deletions.
12 changes: 12 additions & 0 deletions Kryptojagd.iml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:win:11.0.1" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20211205" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter:5.8.2" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-params:5.8.2" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:11.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:mac:11.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:11.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:mac:11.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:11.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:mac:11.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:11.0.1" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:mac:11.0.1" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20211205" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/kryptojagd/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.kryptojagd.controls.MainController;
import org.kryptojagd.fileprocessing.ReadDirectory;
import org.kryptojagd.level.Level;
import org.kryptojagd.level.LevelHandler;
import org.kryptojagd.presentation.PresentationManager;

/**
Expand All @@ -20,9 +21,6 @@
*/
public class MainApp extends Application {

private PresentationManager fw;
private MainController hs;

private int playableLevels = 0;

/**
Expand Down Expand Up @@ -51,9 +49,10 @@ public void start(Stage stage) {
stage.getIcons().add(new Image("img/Icon.png"));
stage.setScene(scene);
stage.show();
fw = new PresentationManager(stage);
PresentationManager fw = new PresentationManager(stage);
assert allLevels != null;
hs = new MainController(fw, allLevels.get(0), allLevels, playableLevels);
LevelHandler levelHandler = new LevelHandler(allLevels);
MainController hs = new MainController(fw, allLevels.get(0), levelHandler, playableLevels);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/kryptojagd/controls/AbstractController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public abstract class AbstractController {

/**
* Updates the timer in the corresponding window.
*
* @param timer the timer
*/
protected void updateTimer(Label timer) {
timer.setText(setCountdownFormat(mainController.getCurrentLevel().getTimeInSec()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import org.kryptojagd.controls.resources.Messages;
import org.kryptojagd.level.tasks.Task;

/**
* @author Leah Schlimm, Bartosz Treyde
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/org/kryptojagd/controls/LevelFinished.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import org.kryptojagd.controls.cryptotool.CryptoToolController;
import org.kryptojagd.fileprocessing.ReadDirectory;
import org.kryptojagd.level.Level;
import org.kryptojagd.level.pointSystem.PointSystem;
import org.kryptojagd.level.tasks.Task;

import java.util.ArrayList;
import org.kryptojagd.level.PointSystem;

/**
* Controller for the level finished fxml file
Expand All @@ -18,12 +15,18 @@
*/
public class LevelFinished extends AbstractController {

/**
* The Text.
*/
@FXML
public Label text;
private Label text;

@FXML
private Label score;

/**
* Initialize.
*/
@FXML
public void initialize() {
if (!CryptoToolController.isSystemHacked()) {
Expand All @@ -41,8 +44,7 @@ public void initialize() {
*/
@FXML
void menuAction(ActionEvent e) throws Exception {
//mainController.getCurrentLevel().clearLevel();
mainController.cityTaskFinished = false;
mainController.addPlayable(mainController.getCurrentLevel());
mainController.setCurrentLevel(mainController.getLevelHandler().getLevelPos() + 1);
mainController.switchWindowWithCSS("Startfenster.fxml", ReadDirectory.CSS_FILE_START);
}
Expand All @@ -54,7 +56,7 @@ void menuAction(ActionEvent e) throws Exception {
@FXML
void nextLevelAction(ActionEvent e) throws Exception {
mainController.getCurrentLevel().clearLevel();
mainController.cityTaskFinished = false;
mainController.addPlayable(mainController.getCurrentLevel());
mainController.setCurrentLevel(mainController.getLevelHandler().getLevelPos() + 1);
mainController.startLevel();
}
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/org/kryptojagd/controls/LevelSelectorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import org.kryptojagd.controls.levels.LevelHandler;
import org.kryptojagd.fileprocessing.ReadDirectory;
import org.kryptojagd.level.Level;
import org.kryptojagd.level.LevelHandler;

import java.util.ArrayList;

/**
Expand All @@ -35,9 +36,8 @@ public void initialize() throws Exception {
System.out.println("Level neu initialisiert!");
ArrayList<Level> levels = ReadDirectory.initialize();
ArrayList<Level> playedLevels = mainController.getLevelHandler().getPlayedLevels();
LevelHandler levelHandler = mainController.getLevelHandler();
for (int i = 0; i < playedLevels.size(); i++) {
System.out.println(playedLevels.get(i).getId());
for (Level playedLevel : playedLevels) {
System.out.println(playedLevel.getId());
}
ArrayList<Button> buttons = new ArrayList<>();
for (int i = 0; i < levels.size(); i++) {
Expand All @@ -46,16 +46,26 @@ public void initialize() throws Exception {
button.setOnAction(event -> {
try {
int countClearedLevels = mainController.getClearedLevels();
LevelHandler levelHandler = new LevelHandler(levels);
setMainController(
new MainController(mainController.getPresentationManager(), levels.get(finalI), levels,
new MainController(mainController.getPresentationManager(), levels.get(finalI),
levelHandler,
countClearedLevels));
mainController.getLevelHandler().setPlayedLevels(playedLevels);
mainController.startLevelByPosition(finalI);
} catch (Exception e) {
e.printStackTrace();
}
});
if (playedLevels.size() > i || unlockAllLevels) {
boolean isPlayable = false;
for (Level playedLevel : playedLevels) {
if (playedLevel.getId() == levels.get(i).getId()) {
isPlayable = true;
}
}
if (unlockAllLevels) {
button.setDisable(false);
} else if (isPlayable) {
button.setDisable(false);
} else {
button.setDisable(true);
Expand All @@ -69,8 +79,8 @@ public void initialize() throws Exception {
}
VBox vbox = new VBox(10);
vbox.setAlignment(Pos.CENTER);
for (int i = 0; i < buttons.size(); i++) {
vbox.getChildren().add(buttons.get(i));
for (Button button : buttons) {
vbox.getChildren().add(button);
}

borderBox.setCenter(vbox);
Expand All @@ -84,7 +94,10 @@ public void initialize() throws Exception {
void clickBack(ActionEvent event) {
mainController.switchWindowWithCSS("Startfenster.fxml", ReadDirectory.CSS_FILE_START);
}


/**
* Unlock all levels.
*/
static void unlockAllLevels() {
unlockAllLevels = true;
}
Expand Down
107 changes: 35 additions & 72 deletions src/main/java/org/kryptojagd/controls/MainController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.kryptojagd.controls;

import org.kryptojagd.controls.levels.LevelHandler;
import org.kryptojagd.level.LevelHandler;
import org.kryptojagd.fileprocessing.ReadDirectory;
import org.kryptojagd.level.Level;
import org.kryptojagd.level.pointSystem.PointSystem;
import org.kryptojagd.level.PointSystem;
import org.kryptojagd.presentation.PresentationManager;
import java.util.ArrayList;

Expand All @@ -14,32 +14,28 @@
*/
public class MainController {

private PresentationManager fw;
private final PresentationManager fw;

private Level currentLevel;

private ArrayList<Level> allLevels;
private final ArrayList<Level> playedLevels = new ArrayList<>();

private ArrayList<Level> playedLevels = new ArrayList<>();
private final int clearedLevels;

private int clearedLevels;
private final int currentLevelPosition;

protected ArrayList<Integer> clearedLevelIndexes = new ArrayList();

protected boolean cityTaskFinished;

protected static boolean isBeaufortDecryption = false;
LevelHandler levelHandler;

private int currentLevelPosition;
/**
* The constant isBeaufortDecryption.
*/
public static boolean isBeaufortDecryption = false;

/**
* The constant TASK_FINISHED_FXML.
*/
public static final String TASK_FINISHED_FXML = "TaskFinished.fxml";

LevelHandler levelHandler;


/**
* Constructor of a MainController
*
Expand All @@ -48,29 +44,22 @@ public class MainController {
* @param allLevels the levels
* @param clearedLevels the cleared levels
*/
public MainController(PresentationManager fw, Level currentLevel, ArrayList<Level> allLevels, int clearedLevels)
public MainController(PresentationManager fw, Level currentLevel, LevelHandler allLevels, int clearedLevels)
throws Exception {
this.fw = fw;
//this.currentLevel = currentLevel;
this.currentLevelPosition = 0;
this.allLevels = allLevels;
this.clearedLevels = clearedLevels;
this.playedLevels.add(currentLevel);
AbstractController.setMainController(this);

this.levelHandler = new LevelHandler(allLevels);
this.levelHandler = allLevels;
this.currentLevel = this.levelHandler.getLevel(0);
}

public MainController(PresentationManager fw, Level currentLevel, ArrayList<Level> allLevels,
LevelHandler levelHandler) throws Exception {
this.fw = fw;
this.allLevels = allLevels;
AbstractController.setMainController(this);
this.levelHandler = levelHandler;
this.currentLevel = currentLevel;
}

/**
* Gets level handler.
*
* @return the level handler
*/
public LevelHandler getLevelHandler() {
return this.levelHandler;
}
Expand All @@ -79,13 +68,23 @@ public LevelHandler getLevelHandler() {
* Starts the current level
*/
public void startLevel() {
addPlayableLevel(this.currentLevel.getId());
PointSystem.setEncryptionTaskedFinished(false);
PointSystem.setMultipleChoiceTaskFinished(0);
PointSystem.setDecryptionTaskFinished(0);
switchWindowWithCSS(currentLevel.getCurrentTask().toString() + ".fxml", ReadDirectory.CSS_FILE_START);
}

/**
* Add playable.
*
* @param level the level
*/
public void addPlayable(Level level) {
if (!this.playedLevels.contains(level)) {
this.playedLevels.add(level);
}
}

/**
* Getter for current level
* @return the current level
Expand Down Expand Up @@ -119,15 +118,6 @@ public PresentationManager getPresentationManager() {
return fw;
}

/**
* Sets cleared levels plus one.
*/
public void setClearedLevels() {
this.clearedLevels++;
if (!clearedLevelIndexes.contains(getCurrentLevelPosition())) {
clearedLevelIndexes.add(getCurrentLevelPosition());
}
}
/**
* Sets beaufort decryption.
*
Expand Down Expand Up @@ -192,40 +182,13 @@ public void setCurrentLevel(int position) throws Exception {
public void setRestartLevel(Level level) {
this.currentLevel = level;
}

/**
* Add a new level to the already playable levels.
* @param id given level id
*/
public void addPlayableLevel(int id) {
for (int i = 0; i < this.playedLevels.size(); i++) {
if (this.playedLevels.get(i).getId() != id) {
this.playedLevels.add(this.currentLevel);
System.out.println("Erfolgreich");
}
}
}

/**
* Checks if the given level id already playable.
* @param id given id of an level
* @return if level is playable.
*/
public boolean checkPlayable(int id) {
for (int i = 0; i < this.playedLevels.size(); i++) {
if (this.playedLevels.get(i).getId() == id) {
System.out.println("Erfolgreich");
return true;
}
}
return false;
}


/**
* Resets all levels.
* @param alllevels resets level list.
* Sets the Beaufort encryption.
*
* @param beaufort true, if Beaufort encryption, else false
*/
public void setAllLevels(ArrayList<Level> alllevels) {
this.allLevels = alllevels;
public void beaufortEncryption(boolean beaufort) {
isBeaufortDecryption = beaufort;
}
}
Loading

0 comments on commit 6906450

Please sign in to comment.