- Each key is now registered in an Abstract Factory which takes in an action to perform. - Comments are added behind each function in to give some indication of how it could be extended/modified in the future. #story[1006]main
parent
054816c15a
commit
f9b2a62f8d
@ -1,20 +0,0 @@
|
||||
package seng302.gameController;
|
||||
|
||||
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);
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package seng302.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* Key for the controller, part of the abstract factory KeyFactory
|
||||
*/
|
||||
public abstract class ControlKey {
|
||||
|
||||
private String name;
|
||||
private KeyCode keyCode;
|
||||
|
||||
/**
|
||||
* Constructor for Control
|
||||
* @param name name of the key
|
||||
* @param keyCode key code for the key
|
||||
*/
|
||||
public ControlKey(String name, KeyCode keyCode){
|
||||
this.name = name;
|
||||
this.keyCode = keyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package seng302.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* Key to send downwind packet to server
|
||||
*/
|
||||
public class DownWindKey extends ControlKey {
|
||||
|
||||
/**
|
||||
* Constructor for Control
|
||||
*
|
||||
* @param name name of the key
|
||||
* @param keyCode key code for the key
|
||||
*/
|
||||
public DownWindKey(String name, KeyCode keyCode) {
|
||||
super(name, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package seng302.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* Factory for creating Keys, these could be predefined in the future.
|
||||
*/
|
||||
public class KeyFactory {
|
||||
|
||||
/**
|
||||
* Get the Control Key incharge of a key press
|
||||
* @param key key pressed (String value of KeyCode)
|
||||
* @return the Control Key behaviour of the key pressed.
|
||||
*/
|
||||
public static ControlKey getKey(String key){
|
||||
switch(key){
|
||||
case "Z":
|
||||
return new ZoomInKey("Z", KeyCode.Z);
|
||||
case "X":
|
||||
return new ZoomOutKey("X", KeyCode.X);
|
||||
case "SPACE":
|
||||
return new VMGKey("SPACE", KeyCode.SPACE);
|
||||
case "SHIFT":
|
||||
return new SailsToggleKey("SHIFT", KeyCode.SHIFT);
|
||||
case "ENTER":
|
||||
return new TackGybeKey("ENTER", KeyCode.ENTER);
|
||||
case "PAGE_UP":
|
||||
return new UpWindKey("PAGE_UP", KeyCode.PAGE_UP);
|
||||
case "PAGE_DOWN":
|
||||
return new DownWindKey("PAGE_DOWN", KeyCode.PAGE_DOWN);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package seng302.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* Key to toggle the sails
|
||||
*/
|
||||
public class SailsToggleKey extends ControlKey {
|
||||
|
||||
/**
|
||||
* Constructor for Control
|
||||
*
|
||||
* @param name name of the key
|
||||
* @param keyCode key code for the key
|
||||
*/
|
||||
public SailsToggleKey(String name, KeyCode keyCode) {
|
||||
super(name, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package seng302.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* key to toggle between tacking and gybing
|
||||
*/
|
||||
public class TackGybeKey extends ControlKey {
|
||||
|
||||
/**
|
||||
* Constructor for Control
|
||||
*
|
||||
* @param name name of the key
|
||||
* @param keyCode key code for the key
|
||||
*/
|
||||
public TackGybeKey(String name, KeyCode keyCode) {
|
||||
super(name, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package seng302.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* Key to go upwind
|
||||
*/
|
||||
public class UpWindKey extends ControlKey {
|
||||
|
||||
/**
|
||||
* Constructor for Control
|
||||
*
|
||||
* @param name name of the key
|
||||
* @param keyCode key code for the key
|
||||
*/
|
||||
public UpWindKey(String name, KeyCode keyCode) {
|
||||
super(name, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package seng302.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* Key to trigger auto VMG
|
||||
*/
|
||||
public class VMGKey extends ControlKey{
|
||||
|
||||
/**
|
||||
* Constructor for Control
|
||||
*
|
||||
* @param name name of the key
|
||||
* @param keyCode key code for the key
|
||||
*/
|
||||
public VMGKey(String name, KeyCode keyCode) {
|
||||
super(name, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package seng302.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* key to zoom into the game
|
||||
*/
|
||||
public class ZoomInKey extends ControlKey {
|
||||
|
||||
public ZoomInKey(String name, KeyCode keyCode) {
|
||||
super(name, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package seng302.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* Key to zoom out of the game.
|
||||
*/
|
||||
public class ZoomOutKey extends ControlKey{
|
||||
|
||||
/**
|
||||
* Constructor for Control
|
||||
*
|
||||
* @param name name of the key
|
||||
* @param keyCode key code for the key
|
||||
*/
|
||||
public ZoomOutKey(String name, KeyCode keyCode) {
|
||||
super(name, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction() {
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue