|
|
|
@ -36,7 +36,7 @@ class Client { |
|
|
|
|
public void keyPressed(GlobalKeyEvent event) { |
|
|
|
|
try { |
|
|
|
|
switch (event.getVirtualKeyCode()){ |
|
|
|
|
case GlobalKeyEvent.VK_RETURN:{ |
|
|
|
|
case GlobalKeyEvent.VK_NUMPAD0:{ |
|
|
|
|
out.writeUTF("FOLLOW"); |
|
|
|
|
}break; |
|
|
|
|
case GlobalKeyEvent.VK_NUMPAD8: |
|
|
|
@ -55,7 +55,6 @@ class Client { |
|
|
|
|
case GlobalKeyEvent.VK_RIGHT:{ |
|
|
|
|
out.writeUTF("RIGHT"); |
|
|
|
|
}break; |
|
|
|
|
case GlobalKeyEvent.VK_NUMPAD0: |
|
|
|
|
case GlobalKeyEvent.VK_NUMPAD1: |
|
|
|
|
case GlobalKeyEvent.VK_1: |
|
|
|
|
case GlobalKeyEvent.VK_2: |
|
|
|
@ -127,7 +126,7 @@ class Client { |
|
|
|
|
|
|
|
|
|
public static void main(String args[]) |
|
|
|
|
{ |
|
|
|
|
Client client = new Client("127.0.0.1", 5000); |
|
|
|
|
Client client = new Client("192.168.1.89", 5000); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -138,6 +137,7 @@ class Server |
|
|
|
|
private ServerSocket server = null; |
|
|
|
|
private DataInputStream in = null; |
|
|
|
|
Robot r; |
|
|
|
|
boolean fighting=false; |
|
|
|
|
|
|
|
|
|
private void PressKeyWithModifier(int modifier,int keycode) { |
|
|
|
|
r.keyPress(modifier); |
|
|
|
@ -177,27 +177,38 @@ class Server |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
line = in.readUTF(); |
|
|
|
|
System.out.println("Received: "+line); |
|
|
|
|
switch (line){ |
|
|
|
|
case "FOLLOW":{ |
|
|
|
|
PressKeyWithModifier(KeyEvent.VK_CONTROL,KeyEvent.VK_7); |
|
|
|
|
}break; |
|
|
|
|
case "FORWARD":{ |
|
|
|
|
|
|
|
|
|
r.keyPress(KeyEvent.VK_W); |
|
|
|
|
r.delay(1000); |
|
|
|
|
r.keyRelease(KeyEvent.VK_W); |
|
|
|
|
}break; |
|
|
|
|
case "BACKWARD":{ |
|
|
|
|
|
|
|
|
|
r.keyPress(KeyEvent.VK_S); |
|
|
|
|
r.delay(1000); |
|
|
|
|
r.keyRelease(KeyEvent.VK_S); |
|
|
|
|
}break; |
|
|
|
|
case "LEFT":{ |
|
|
|
|
|
|
|
|
|
r.keyPress(KeyEvent.VK_Q); |
|
|
|
|
r.delay(1000); |
|
|
|
|
r.keyRelease(KeyEvent.VK_Q); |
|
|
|
|
}break; |
|
|
|
|
case "RIGHT":{ |
|
|
|
|
|
|
|
|
|
r.keyPress(KeyEvent.VK_E); |
|
|
|
|
r.delay(1000); |
|
|
|
|
r.keyRelease(KeyEvent.VK_E); |
|
|
|
|
}break; |
|
|
|
|
case "FIGHT":{ |
|
|
|
|
|
|
|
|
|
fighting=true; |
|
|
|
|
System.out.println("Fight mode: "+fighting); |
|
|
|
|
}break; |
|
|
|
|
case "CHILL":{ |
|
|
|
|
|
|
|
|
|
fighting=false; |
|
|
|
|
System.out.println("Fight mode: "+fighting); |
|
|
|
|
}break; |
|
|
|
|
default:{ |
|
|
|
|
System.out.println("Unknown command: "+line); |
|
|
|
|