diff --git a/controller/pom.xml b/controller/pom.xml new file mode 100644 index 00000000..38099bbf --- /dev/null +++ b/controller/pom.xml @@ -0,0 +1,15 @@ + + + + team-7 + seng302 + 1.0-SNAPSHOT + + 4.0.0 + + 1 + + + \ No newline at end of file diff --git a/controller/src/main/java/seng302/Controllers/MainWindowController.java b/controller/src/main/java/seng302/Controllers/MainWindowController.java new file mode 100644 index 00000000..f5fdbcf2 --- /dev/null +++ b/controller/src/main/java/seng302/Controllers/MainWindowController.java @@ -0,0 +1,7 @@ +package seng302.Controllers; + +/** + * Controller for the main window fxml of the Game Controller + */ +public class MainWindowController { +} diff --git a/controller/src/main/java/seng302/Main.java b/controller/src/main/java/seng302/Main.java new file mode 100644 index 00000000..c2b7720b --- /dev/null +++ b/controller/src/main/java/seng302/Main.java @@ -0,0 +1,101 @@ +package seng302; + +import javafx.animation.AnimationTimer; +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.io.IOException; +import java.util.HashMap; + +/** + * Entry point for the controller side of the application + */ +public class Main extends Application { + //holds a boolean state for each important key to show if pressed down or not + private HashMap currentlyActiveKeys = new HashMap<>(); + + /** + * Entry point for running the programme + * + * @param args for starting the programme + */ + public static void main(String[] args) { + launch(args); + } + + @Override + public void start(Stage stage) { + try { + FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("mainWindow.fxml")); + Parent root = loader.load(); + + Scene scene = new Scene(root, 200, 100); + stage.setScene(scene); + stage.setTitle("Controller"); + + scene.setOnKeyPressed(event -> { + String codeString = event.getCode().toString(); + if (!currentlyActiveKeys.containsKey(codeString)) { + currentlyActiveKeys.put(codeString, true); + } + }); + + scene.setOnKeyReleased(event -> + currentlyActiveKeys.remove(event.getCode().toString()) + ); + + new AnimationTimer() { + @Override + public void handle(long now) { + if (removeActiveKey("Z")) { + System.out.println("zoom in"); + } + + if (removeActiveKey("X")) { + System.out.println("zoom out"); + } + + if (removeActiveKey("SPACE")) { + System.out.println("VMG"); + } + + if (removeActiveKey("SHIFT")) { + System.out.println("sails in/out"); + } + + if (removeActiveKey("Enter")) { + System.out.println("tack/gybe"); + } + + if (removeActiveKey("PAGE_UP")) { + System.out.println("up wind"); + } + + if (removeActiveKey("PAGE_DOWN")) { + System.out.println("down wind"); + } + } + }.start(); + + stage.show(); + } catch (IOException e) { + //Catch all exceptions, print, and exit. + e.printStackTrace(); + System.exit(1); + } + } + + private boolean removeActiveKey(String codeString) { + Boolean isActive = currentlyActiveKeys.get(codeString); + + if (isActive != null && isActive) { + currentlyActiveKeys.put(codeString, false); + return true; + } else { + return false; + } + } +} diff --git a/controller/src/main/resources/mainWindow.fxml b/controller/src/main/resources/mainWindow.fxml new file mode 100644 index 00000000..f7eeebd1 --- /dev/null +++ b/controller/src/main/resources/mainWindow.fxml @@ -0,0 +1,10 @@ + + + + + + +
+ +
+