Commit 21e07198 authored by Huot Mathieu's avatar Huot Mathieu

improved input for both graphical and terminal version

parent f76122d8
...@@ -38,12 +38,24 @@ public class GamePanelAbstractionController { ...@@ -38,12 +38,24 @@ public class GamePanelAbstractionController {
MyInputInterpreter.setMoveXRight(true);break; MyInputInterpreter.setMoveXRight(true);break;
case DOWN_ARROW: case DOWN_ARROW:
MyInputInterpreter.setMoveYBottom(true);break; MyInputInterpreter.setMoveYBottom(true);break;
case SPELL: case ABILITY_1:
if(spellReleased){ if(spellReleased){
MyInputInterpreter.tryToCastAbility(1); MyInputInterpreter.tryToCastAbility(1);
spellReleased=false; spellReleased=false;
} }
break; break;
case ABILITY_2:
if(spellReleased){
MyInputInterpreter.tryToCastAbility(2);
spellReleased=false;
}
break;
case ABILITY_3:
if(spellReleased){
MyInputInterpreter.tryToCastAbility(3);
spellReleased=false;
}
break;
case ATTACK: case ATTACK:
if(attackReleased){ if(attackReleased){
MyInputInterpreter.tryToCastAbility(0); MyInputInterpreter.tryToCastAbility(0);
...@@ -70,7 +82,11 @@ public class GamePanelAbstractionController { ...@@ -70,7 +82,11 @@ public class GamePanelAbstractionController {
MyInputInterpreter.setMoveYBottom(false);break; MyInputInterpreter.setMoveYBottom(false);break;
case ATTACK: case ATTACK:
attackReleased=true;break; attackReleased=true;break;
case SPELL: case ABILITY_1:
spellReleased=true;break;
case ABILITY_2:
spellReleased=true;break;
case ABILITY_3:
spellReleased=true;break; spellReleased=true;break;
default: default:
break; break;
......
...@@ -17,6 +17,7 @@ public class Igniter_Main { ...@@ -17,6 +17,7 @@ public class Igniter_Main {
/** Initialise some packages to detect instantly uncorrect declarations **/ /** Initialise some packages to detect instantly uncorrect declarations **/
AbilityPackageInitialiser.initialisePackage(); AbilityPackageInitialiser.initialisePackage();
EffectPackageInitialiser.initialisePackage(); EffectPackageInitialiser.initialisePackage();
System.out.println();
/** Launch the GUI (and thus the game) **/ /** Launch the GUI (and thus the game) **/
GraphicsMaster.build(); GraphicsMaster.build();
......
...@@ -35,7 +35,7 @@ public class ConfigurationPanel extends MenuPanel { ...@@ -35,7 +35,7 @@ public class ConfigurationPanel extends MenuPanel {
private JLabel makeKeyLabel(Input input){ private JLabel makeKeyLabel(Input input){
JLabel keyLabel = new JLabel(); JLabel keyLabel = new JLabel();
keyLabel.setFont(GUIColorsAndFonts.buttonFont1); keyLabel.setFont(GUIColorsAndFonts.buttonFont1);
keyLabel.setText(InputConfiguration.GetKey(input)); keyLabel.setText(InputConfiguration.GetFormalInputString(input));
keyLabel.setForeground(GUIColorsAndFonts.fontColor1); keyLabel.setForeground(GUIColorsAndFonts.fontColor1);
return keyLabel; return keyLabel;
} }
...@@ -45,7 +45,7 @@ public class ConfigurationPanel extends MenuPanel { ...@@ -45,7 +45,7 @@ public class ConfigurationPanel extends MenuPanel {
setTitlePanel("Configuration"); setTitlePanel("Configuration");
addToCentralColumn(ButtonMaker.makeButton("move up: " + (InputConfiguration.GetKey(Input.UP_ARROW)), configUpListener),1,1); addToCentralColumn(ButtonMaker.makeButton("move up: " + (InputConfiguration.GetFormalInputString(Input.UP_ARROW)), configUpListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move down: ", configDownListener),1,1); addToCentralColumn(ButtonMaker.makeButton("move down: ", configDownListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move right: ", configLeftListener),1,1); addToCentralColumn(ButtonMaker.makeButton("move right: ", configLeftListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move left: ", configRightListener),1,1); addToCentralColumn(ButtonMaker.makeButton("move left: ", configRightListener),1,1);
......
...@@ -9,6 +9,5 @@ package graphics.ingame_input_listener; ...@@ -9,6 +9,5 @@ package graphics.ingame_input_listener;
* if "a" is supposed to give a move left, then this * if "a" is supposed to give a move left, then this
* is linked to LEFT_ARROW */ * is linked to LEFT_ARROW */
public enum Input { public enum Input {
ATTACK, SPELL, CIRCLE, LEFT_ARROW ,RIGHT_ARROW ,UP_ARROW , DOWN_ARROW, ESCAPE, SPACE, NONE ATTACK, ABILITY_1, ABILITY_2, ABILITY_3, LEFT_ARROW ,RIGHT_ARROW ,UP_ARROW , DOWN_ARROW, ESCAPE, SPACE, NONE
} }
...@@ -12,25 +12,35 @@ public class InputConfiguration { ...@@ -12,25 +12,35 @@ public class InputConfiguration {
// initial keys that may be changed in the game // initial keys that may be changed in the game
private static int attack = KeyEvent.VK_A; private static int attack = KeyEvent.VK_A;
private static int spell = KeyEvent.VK_S; private static int ability1 = KeyEvent.VK_Z;
private static int circle = KeyEvent.VK_L; private static int ability2 = KeyEvent.VK_E;
private static int ability3 = KeyEvent.VK_R;
private static int escape = KeyEvent.VK_ESCAPE; private static int escape = KeyEvent.VK_ESCAPE;
private static int space = KeyEvent.VK_SPACE; private static int space = KeyEvent.VK_SPACE;
public static int up = KeyEvent.VK_UP; private static int up = KeyEvent.VK_UP;
private static int down = KeyEvent.VK_DOWN; private static int down = KeyEvent.VK_DOWN;
private static int right = KeyEvent.VK_RIGHT; private static int right = KeyEvent.VK_RIGHT;
private static int left = KeyEvent.VK_LEFT; private static int left = KeyEvent.VK_LEFT;
//keys special for terminal version
private static char left_arrow='4';
private static char right_arrow='6';
private static char up_arrow='8';
private static char down_arrow='2';
private static char escape_terminal='p';
public static void ChangeKey(Input input, int j) { public static void ChangeKey(Input input, int j) {
switch(input){ switch(input){
case ATTACK: case ATTACK:
attack=j;break; attack=j;break;
case SPELL: case ABILITY_1:
spell =j;break; ability1 =j;break;
case CIRCLE: case ABILITY_2:
circle=j;break; ability2=j;break;
case ABILITY_3:
ability3=j;break;
case ESCAPE: case ESCAPE:
escape=j;break; escape=j;break;
case UP_ARROW: case UP_ARROW:
...@@ -53,8 +63,9 @@ public class InputConfiguration { ...@@ -53,8 +63,9 @@ public class InputConfiguration {
public static Input GetInput(KeyEvent e){ public static Input GetInput(KeyEvent e){
int event=e.getKeyCode(); int event=e.getKeyCode();
if (event==attack){return Input.ATTACK;} if (event==attack){return Input.ATTACK;}
if (event==circle){return Input.CIRCLE;} if (event== ability1){return Input.ABILITY_1;}
if (event== spell){return Input.SPELL;} if (event==ability2){return Input.ABILITY_2;}
if (event== ability3){return Input.ABILITY_3;}
if (event==escape){return Input.ESCAPE;} if (event==escape){return Input.ESCAPE;}
if (event==up){return Input.UP_ARROW;} if (event==up){return Input.UP_ARROW;}
if (event==down){return Input.DOWN_ARROW;} if (event==down){return Input.DOWN_ARROW;}
...@@ -69,7 +80,7 @@ public class InputConfiguration { ...@@ -69,7 +80,7 @@ public class InputConfiguration {
* @return the string of the character whose code is j * @return the string of the character whose code is j
* and a blank if j is not the code of a usual keyboard character * and a blank if j is not the code of a usual keyboard character
*/ */
private static String GetChar(int j){ private static String GetString(int j){
switch (j) { switch (j) {
case KeyEvent.VK_A: case KeyEvent.VK_A:
return "a"; return "a";
...@@ -131,9 +142,72 @@ public class InputConfiguration { ...@@ -131,9 +142,72 @@ public class InputConfiguration {
return "left_arrow"; return "left_arrow";
case KeyEvent.VK_RIGHT: case KeyEvent.VK_RIGHT:
return "right_arrow"; return "right_arrow";
default:
throw new IllegalStateException("Unknown int : " + j);
}
}
/**
* @param j : a keyEvent code
* @return the character whose code is j
* and a blank if j is not the code of a usual keyboard character
*/
private static char GetChar(int j){
switch (j) {
case KeyEvent.VK_A:
return 'a';
case KeyEvent.VK_B:
return 'b';
case KeyEvent.VK_C:
return 'c';
case KeyEvent.VK_D:
return 'd';
case KeyEvent.VK_E:
return 'e';
case KeyEvent.VK_F:
return 'f';
case KeyEvent.VK_G:
return 'g';
case KeyEvent.VK_H:
return 'h';
case KeyEvent.VK_I:
return 'i';
case KeyEvent.VK_J:
return 'j';
case KeyEvent.VK_K:
return 'k';
case KeyEvent.VK_L:
return 'l';
case KeyEvent.VK_M:
return 'm';
case KeyEvent.VK_N:
return 'n';
case KeyEvent.VK_O:
return 'o';
case KeyEvent.VK_P:
return 'p';
case KeyEvent.VK_Q:
return 'q';
case KeyEvent.VK_R:
return 'r';
case KeyEvent.VK_S:
return 's';
case KeyEvent.VK_T:
return 't';
case KeyEvent.VK_U:
return 'u';
case KeyEvent.VK_V:
return 'v';
case KeyEvent.VK_W:
return 'w';
case KeyEvent.VK_X:
return 'x';
case KeyEvent.VK_Y:
return 'y';
case KeyEvent.VK_Z:
return 'z';
default: default:
throw new IllegalStateException("Unknown int" + j); throw new IllegalStateException("int linked with no character : " + j);
} }
} }
...@@ -141,28 +215,62 @@ public class InputConfiguration { ...@@ -141,28 +215,62 @@ public class InputConfiguration {
* @param input : a formal Input * @param input : a formal Input
* @return the string of the character linked to input * @return the string of the character linked to input
*/ */
public static String GetKey(Input input){ public static String GetFormalInputString(Input input){
switch (input) { switch (input) {
case ATTACK: case ATTACK:
return GetChar(attack); return GetString(attack);
case SPELL: case ABILITY_1:
return GetChar(spell); return GetString(ability1);
case CIRCLE: case ABILITY_2:
return GetChar(circle); return GetString(ability2);
case ABILITY_3:
return GetString(ability3);
case ESCAPE: case ESCAPE:
return GetChar(escape); return GetString(escape);
case UP_ARROW: case UP_ARROW:
return GetChar(up); return GetString(up);
case DOWN_ARROW: case DOWN_ARROW:
return GetChar(down); return GetString(down);
case RIGHT_ARROW: case RIGHT_ARROW:
return GetChar(right); return GetString(right);
case LEFT_ARROW: case LEFT_ARROW:
return GetChar(left); return GetString(left);
case NONE: case NONE:
return " "; return " ";
default: default:
throw new IllegalStateException("Unknown input"+ input); throw new IllegalStateException("Unknown input : "+input);
}
}
/**
* @param input : a formal Input
* @return the string of the character linked to input
*/
//Will only be used for the terminal version
public static char GetFormalInputChar(Input input){
switch (input) {
case ATTACK:
return GetChar(attack);
case ABILITY_1:
return GetChar(ability1);
case ABILITY_2:
return GetChar(ability2);
case ABILITY_3:
return GetChar(ability3);
case ESCAPE:
return escape_terminal;
case LEFT_ARROW:
return left_arrow;
case RIGHT_ARROW:
return right_arrow;
case UP_ARROW:
return up_arrow;
case DOWN_ARROW:
return down_arrow;
case NONE:
return ' ';
default:
throw new IllegalStateException("Unknown input : "+input);
} }
} }
...@@ -176,12 +284,15 @@ public class InputConfiguration { ...@@ -176,12 +284,15 @@ public class InputConfiguration {
case ATTACK: case ATTACK:
attack=e.getKeyCode(); attack=e.getKeyCode();
break; break;
case SPELL: case ABILITY_1:
spell =e.getKeyCode(); ability1 =e.getKeyCode();
break; break;
case CIRCLE: case ABILITY_2:
circle=e.getKeyCode(); ability2=e.getKeyCode();
break; break;
case ABILITY_3:
ability3=e.getKeyCode();
break;
case ESCAPE: case ESCAPE:
escape=e.getKeyCode(); escape=e.getKeyCode();
break; break;
...@@ -200,7 +311,7 @@ public class InputConfiguration { ...@@ -200,7 +311,7 @@ public class InputConfiguration {
case NONE: case NONE:
return; return;
default: default:
throw new IllegalStateException("Unknown input"+ input); throw new IllegalStateException("Unknown input: "+ input);
} }
} }
......
...@@ -2,6 +2,7 @@ package graphics.termSkeleton; ...@@ -2,6 +2,7 @@ package graphics.termSkeleton;
import graphics.graphical_abstraction.FrameKeyListenerAbstraction; import graphics.graphical_abstraction.FrameKeyListenerAbstraction;
import graphics.ingame_input_listener.Input; import graphics.ingame_input_listener.Input;
import graphics.ingame_input_listener.InputConfiguration;
import java.io.*; import java.io.*;
import java.util.HashSet; import java.util.HashSet;
...@@ -83,39 +84,47 @@ public class TermFrameKeyListener implements FrameKeyListenerAbstraction{ ...@@ -83,39 +84,47 @@ public class TermFrameKeyListener implements FrameKeyListenerAbstraction{
} }
in = new BufferedReader( new InputStreamReader(System.in) ); in = new BufferedReader( new InputStreamReader(System.in) );
int line = 0; int line;
try { try {
while (in.ready()) { while (in.ready()) {
line = in.read(); line = in.read();
//if(line == 27){ if (line == InputConfiguration.GetFormalInputChar(Input.ESCAPE)) {
// //graphicsMaster.keyPressedHandler(Input.ESCAPE);
// inputs_current.add(Input.ESCAPE);
//}
if (line == 27) { // 27 -> Escape
//graphicsMaster.keyPressedHandler(Input.ESCAPE); //graphicsMaster.keyPressedHandler(Input.ESCAPE);
inputs_current.add(Input.ESCAPE); inputs_current.add(Input.ESCAPE);
} }
if (line == 'q') { //<-, left arrow if (line == InputConfiguration.GetFormalInputChar(Input.LEFT_ARROW)) {
//graphicsMaster.keyPressedHandler(Input.LEFT_ARROW); //graphicsMaster.keyPressedHandler(Input.LEFT_ARROW);
inputs_current.add(Input.LEFT_ARROW); inputs_current.add(Input.LEFT_ARROW);
} }
if (line == 'z') { // /\, up arrow if (line == InputConfiguration.GetFormalInputChar(Input.UP_ARROW)) {
//graphicsMaster.keyPressedHandler(Input.UP_ARROW); //graphicsMaster.keyPressedHandler(Input.UP_ARROW);
inputs_current.add(Input.UP_ARROW); inputs_current.add(Input.UP_ARROW);
} }
if (line == 'd') { // ->, right arrow if (line == InputConfiguration.GetFormalInputChar(Input.RIGHT_ARROW)) {
//graphicsMaster.keyPressedHandler(Input.RIGHT_ARROW); //graphicsMaster.keyPressedHandler(Input.RIGHT_ARROW);
inputs_current.add(Input.RIGHT_ARROW); inputs_current.add(Input.RIGHT_ARROW);
} }
if (line == 's') { // \/, down arrow if (line == InputConfiguration.GetFormalInputChar(Input.DOWN_ARROW)) {
//graphicsMaster.keyPressedHandler(Input.DOWN_ARROW); //graphicsMaster.keyPressedHandler(Input.DOWN_ARROW);
inputs_current.add(Input.DOWN_ARROW); inputs_current.add(Input.DOWN_ARROW);
} }
if (line == 'e') { // \/, down arrow if (line == InputConfiguration.GetFormalInputChar(Input.ATTACK)) {
//graphicsMaster.keyPressedHandler(Input.DOWN_ARROW); //graphicsMaster.keyPressedHandler(Input.DOWN_ARROW);
inputs_current.add(Input.ATTACK); inputs_current.add(Input.ATTACK);
} }
if (line == InputConfiguration.GetFormalInputChar(Input.ABILITY_1)) {
//graphicsMaster.keyPressedHandler(Input.DOWN_ARROW);
inputs_current.add(Input.ABILITY_1);
}
if (line == InputConfiguration.GetFormalInputChar(Input.ABILITY_2)) {
//graphicsMaster.keyPressedHandler(Input.DOWN_ARROW);
inputs_current.add(Input.ABILITY_2);
}
if (line == InputConfiguration.GetFormalInputChar(Input.ABILITY_3)) {
//graphicsMaster.keyPressedHandler(Input.DOWN_ARROW);
inputs_current.add(Input.ABILITY_3);
}
} }
} }
catch(IOException e) catch(IOException e)
......
...@@ -7,13 +7,15 @@ import org.junit.BeforeClass; ...@@ -7,13 +7,15 @@ import org.junit.BeforeClass;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.runners.model.TestTimedOutException;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.net.Socket; import java.net.Socket;
import static org.junit.Assert.assertEquals;
//import org.junit.runners.model.TestTimedOutException;
/** /**
* Class for JUnits test for the class ServerConnection. * Class for JUnits test for the class ServerConnection.
* Created by mymi on 20/12/15. * Created by mymi on 20/12/15.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment