mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Key presses now assigned to enum and empty packet class is constructed.
#pair[kre39,zyt10] #story[988]
This commit is contained in:
@@ -1,18 +1,17 @@
|
|||||||
package seng302.controllers;
|
package seng302.controllers;
|
||||||
|
|
||||||
import com.sun.org.apache.bcel.internal.generic.BREAKPOINT;
|
import java.io.IOException;
|
||||||
import javafx.event.EventHandler;
|
import java.net.URL;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
import seng302.models.stream.StreamParser;
|
import seng302.models.stream.StreamParser;
|
||||||
|
import seng302.models.stream.packets.BoatActionPacket;
|
||||||
|
import seng302.models.stream.packets.BoatActionType;
|
||||||
|
|
||||||
public class Controller implements Initializable {
|
public class Controller implements Initializable {
|
||||||
|
|
||||||
@@ -44,32 +43,40 @@ public class Controller implements Initializable {
|
|||||||
|
|
||||||
/** Handle the key-pressed event from the text field. */
|
/** Handle the key-pressed event from the text field. */
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
|
BoatActionPacket boatActionPacket;
|
||||||
switch (e.getCode()){
|
switch (e.getCode()){
|
||||||
case SPACE: // align with vmg
|
case SPACE: // align with vmg
|
||||||
System.out.println("Key pressed = space");
|
boatActionPacket = new BoatActionPacket(BoatActionType.VMG);
|
||||||
|
boatActionPacket.sendPacket();
|
||||||
break;
|
break;
|
||||||
case PAGE_UP: // upwind
|
case PAGE_UP: // upwind
|
||||||
System.out.println("Key pressed = page up");
|
boatActionPacket = new BoatActionPacket(BoatActionType.UPWIND);
|
||||||
|
boatActionPacket.sendPacket();
|
||||||
break;
|
break;
|
||||||
case PAGE_DOWN: // downwind
|
case PAGE_DOWN: // downwind
|
||||||
System.out.println("Key pressed = page down");
|
boatActionPacket = new BoatActionPacket(BoatActionType.DOWNWIND);
|
||||||
|
boatActionPacket.sendPacket();
|
||||||
break;
|
break;
|
||||||
case ENTER: // tack/gybe
|
case ENTER: // tack/gybe
|
||||||
System.out.println("Key pressed = enter");
|
boatActionPacket = new BoatActionPacket(BoatActionType.TACK_GYBE);
|
||||||
|
boatActionPacket.sendPacket();
|
||||||
break;
|
break;
|
||||||
|
//TODO Allow a zoom in and zoom out methods
|
||||||
case Z: // zoom in
|
case Z: // zoom in
|
||||||
System.out.println("Key pressed = z");
|
System.out.println("Zoom in");
|
||||||
break;
|
break;
|
||||||
case X: // zoom out
|
case X: // zoom out
|
||||||
System.out.println("Key pressed = x");
|
System.out.println("Zoom out");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
switch (e.getCode()) {
|
switch (e.getCode()) {
|
||||||
|
//TODO 12/07/17 Determine the sail state and send the appropriate packet (eg. if sails are in, send a sail out packet)
|
||||||
case SHIFT: // sails in/sails out
|
case SHIFT: // sails in/sails out
|
||||||
System.out.println("Key pressed = shift");
|
BoatActionPacket boatActionPacket = new BoatActionPacket(BoatActionType.SAILS_IN);
|
||||||
|
boatActionPacket.sendPacket();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package seng302.models.stream.packets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by kre39 on 12/07/17.
|
||||||
|
*/
|
||||||
|
public class BoatActionPacket {
|
||||||
|
|
||||||
|
BoatActionType actionType;
|
||||||
|
|
||||||
|
public BoatActionPacket(BoatActionType actionType) {
|
||||||
|
this.actionType = actionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sends the packet to the server
|
||||||
|
public void sendPacket(){
|
||||||
|
System.out.println(BoatActionType.getBoatPacketType(actionType));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package seng302.models.stream.packets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by kre39 on 12/07/17.
|
||||||
|
*/
|
||||||
|
public enum BoatActionType {
|
||||||
|
|
||||||
|
VMG,
|
||||||
|
SAILS_IN,
|
||||||
|
SAILS_OUT,
|
||||||
|
TACK_GYBE,
|
||||||
|
UPWIND,
|
||||||
|
DOWNWIND;
|
||||||
|
|
||||||
|
public static Short getBoatPacketType(BoatActionType type){
|
||||||
|
switch (type){
|
||||||
|
case VMG:
|
||||||
|
return 1;
|
||||||
|
case SAILS_IN:
|
||||||
|
return 2;
|
||||||
|
case SAILS_OUT:
|
||||||
|
return 3;
|
||||||
|
case TACK_GYBE:
|
||||||
|
return 4;
|
||||||
|
case UPWIND:
|
||||||
|
return 5;
|
||||||
|
case DOWNWIND:
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user