updated the game controller to use the visualiser as the scene

#story[1006]
This commit is contained in:
hba56
2017-07-12 11:59:59 +12:00
parent 6ae23f039b
commit 83ac3e4e33
6 changed files with 69 additions and 118 deletions
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>team-7</artifactId>
<groupId>seng302</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>1</artifactId>
</project>
@@ -0,0 +1,49 @@
package seng302;
import javafx.animation.AnimationTimer;
import javafx.scene.Scene;
import java.util.HashMap;
/**
* Class for checking what keys are currently being used
*/
public class InputChecker {
private HashMap<String, Boolean> currentlyActiveKeys = new HashMap<>();
public void runWithScene(Scene scene){
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) {
for (String key : InputKeys.listOfKeys){
if (removeActiveKey(key)) {
System.out.println(key);
}
}
}
}.start();
}
private boolean removeActiveKey(String codeString) {
Boolean isActive = currentlyActiveKeys.get(codeString);
if (isActive != null && isActive) {
currentlyActiveKeys.put(codeString, false);
return true;
} else {
return false;
}
}
}
@@ -0,0 +1,20 @@
package seng302;
import java.util.Arrays;
import java.util.List;
/**
* Class to store the basic keys used by this controller
*/
public class InputKeys {
protected static String zoomIn = "Z";
protected static String zoomOut = "X";
protected static String vmg = "SPACE";
protected static String sailsToggle = "SHIFT";
protected static String tackGybe = "Enter";
protected static String upWind = "PAGE_UP";
protected static String downWind = "Page_Down";
protected static List<String> listOfKeys = Arrays.asList(zoomIn, zoomOut, vmg,
sailsToggle, tackGybe, upWind, downWind);
}