Added Modularity to Input Checker.
- Added onHold - Added onRelease - Added ManualTesting Class in the tests - Added Unimplemented new methods to classes #story[1006]
This commit is contained in:
Generated
-7
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="KotlinCommonCompilerArguments">
|
|
||||||
<option name="languageVersion" value="1.1" />
|
|
||||||
<option name="apiVersion" value="1.1" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -33,9 +33,6 @@ public class App extends Application {
|
|||||||
Parent root = loader.load();
|
Parent root = loader.load();
|
||||||
Scene scene = new Scene(root, 1200, 800);
|
Scene scene = new Scene(root, 1200, 800);
|
||||||
|
|
||||||
InputChecker inputChecker = new InputChecker();
|
|
||||||
inputChecker.runWithScene(scene);
|
|
||||||
|
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.setTitle("RaceVision - Team 7");
|
stage.setTitle("RaceVision - Team 7");
|
||||||
stage.show();
|
stage.show();
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import seng302.gameController.Keys.KeyFactory;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import static javafx.application.Application.launch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for checking what keys are currently being used
|
* Class for checking what keys are currently being used
|
||||||
*/
|
*/
|
||||||
@@ -21,12 +23,18 @@ public class InputChecker {
|
|||||||
scene.setOnKeyPressed(event -> {
|
scene.setOnKeyPressed(event -> {
|
||||||
String codeString = event.getCode().toString();
|
String codeString = event.getCode().toString();
|
||||||
if (!currentlyActiveKeys.containsKey(codeString)) {
|
if (!currentlyActiveKeys.containsKey(codeString)) {
|
||||||
|
ControlKey controlKey = KeyFactory.getKey(codeString);
|
||||||
|
controlKey.onAction();
|
||||||
currentlyActiveKeys.put(codeString, true);
|
currentlyActiveKeys.put(codeString, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
scene.setOnKeyReleased(event ->
|
scene.setOnKeyReleased(event -> {
|
||||||
currentlyActiveKeys.remove(event.getCode().toString())
|
String codeString = event.getCode().toString();
|
||||||
|
ControlKey controlKey = KeyFactory.getKey(codeString);
|
||||||
|
controlKey.onRelease();
|
||||||
|
currentlyActiveKeys.remove(event.getCode().toString());
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
new AnimationTimer() {
|
new AnimationTimer() {
|
||||||
@@ -35,7 +43,8 @@ public class InputChecker {
|
|||||||
for (String key: currentlyActiveKeys.keySet()){
|
for (String key: currentlyActiveKeys.keySet()){
|
||||||
ControlKey controlKey = KeyFactory.getKey(key);
|
ControlKey controlKey = KeyFactory.getKey(key);
|
||||||
if (controlKey != null){
|
if (controlKey != null){
|
||||||
controlKey.onAction();
|
controlKey.onHold();
|
||||||
|
System.out.println(controlKey.toString() + " is Pressed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for (String key : InputKeys.stringKeysMap.keySet()){
|
// for (String key : InputKeys.stringKeysMap.keySet()){
|
||||||
@@ -63,4 +72,5 @@ public class InputChecker {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,26 @@ public abstract class ControlKey {
|
|||||||
this.keyCode = keyCode;
|
this.keyCode = keyCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To String method
|
||||||
|
* @return returns the name of the key
|
||||||
|
*/
|
||||||
|
public String toString(){
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What this key should do when the command is issued for it to do its job.
|
* What this key should do when the command is issued for it to do its job.
|
||||||
*/
|
*/
|
||||||
public abstract void onAction();//may want to make it take in a visualiser and stuff in the future.
|
public abstract void onAction();//may want to make it take in a visualiser and stuff in the future.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What to do when the key is held
|
||||||
|
*/
|
||||||
|
public abstract void onHold();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What to do when the key is released.
|
||||||
|
*/
|
||||||
|
public abstract void onRelease();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,14 @@ public class DownWindKey extends ControlKey {
|
|||||||
public void onAction() {
|
public void onAction() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,14 @@ public class SailsToggleKey extends ControlKey {
|
|||||||
public void onAction() {
|
public void onAction() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,14 @@ public class TackGybeKey extends ControlKey {
|
|||||||
public void onAction() {
|
public void onAction() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,14 @@ public class UpWindKey extends ControlKey {
|
|||||||
public void onAction() {
|
public void onAction() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,14 @@ public class VMGKey extends ControlKey{
|
|||||||
public void onAction() {
|
public void onAction() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,14 @@ public class ZoomInKey extends ControlKey {
|
|||||||
public void onAction() {
|
public void onAction() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,14 @@ public class ZoomOutKey extends ControlKey{
|
|||||||
public void onAction() {
|
public void onAction() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHold() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRelease() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package seng302;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.WindowEvent;
|
||||||
|
import seng302.gameController.InputChecker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start to manually test the game controller
|
||||||
|
*/
|
||||||
|
public class GameControllerManualTest extends Application {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) throws Exception {
|
||||||
|
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(WindowEvent event) {
|
||||||
|
Platform.exit();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
GridPane root = new GridPane();
|
||||||
|
Scene scene = new Scene(root, 1200, 800);
|
||||||
|
|
||||||
|
InputChecker inputChecker = new InputChecker();
|
||||||
|
inputChecker.runWithScene(scene);
|
||||||
|
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.setTitle("RaceVision - Team 7 - Input Tester Manual Test");
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user