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 {
MyInputInterpreter.setMoveXRight(true);break;
case DOWN_ARROW:
MyInputInterpreter.setMoveYBottom(true);break;
case SPELL:
case ABILITY_1:
if(spellReleased){
MyInputInterpreter.tryToCastAbility(1);
spellReleased=false;
}
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:
if(attackReleased){
MyInputInterpreter.tryToCastAbility(0);
......@@ -70,7 +82,11 @@ public class GamePanelAbstractionController {
MyInputInterpreter.setMoveYBottom(false);break;
case ATTACK:
attackReleased=true;break;
case SPELL:
case ABILITY_1:
spellReleased=true;break;
case ABILITY_2:
spellReleased=true;break;
case ABILITY_3:
spellReleased=true;break;
default:
break;
......
......@@ -17,6 +17,7 @@ public class Igniter_Main {
/** Initialise some packages to detect instantly uncorrect declarations **/
AbilityPackageInitialiser.initialisePackage();
EffectPackageInitialiser.initialisePackage();
System.out.println();
/** Launch the GUI (and thus the game) **/
GraphicsMaster.build();
......
......@@ -35,7 +35,7 @@ public class ConfigurationPanel extends MenuPanel {
private JLabel makeKeyLabel(Input input){
JLabel keyLabel = new JLabel();
keyLabel.setFont(GUIColorsAndFonts.buttonFont1);
keyLabel.setText(InputConfiguration.GetKey(input));
keyLabel.setText(InputConfiguration.GetFormalInputString(input));
keyLabel.setForeground(GUIColorsAndFonts.fontColor1);
return keyLabel;
}
......@@ -45,7 +45,7 @@ public class ConfigurationPanel extends MenuPanel {
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 right: ", configLeftListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move left: ", configRightListener),1,1);
......
......@@ -9,6 +9,5 @@ package graphics.ingame_input_listener;
* if "a" is supposed to give a move left, then this
* is linked to LEFT_ARROW */
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 {
// initial keys that may be changed in the game
private static int attack = KeyEvent.VK_A;
private static int spell = KeyEvent.VK_S;
private static int circle = KeyEvent.VK_L;
private static int ability1 = KeyEvent.VK_Z;
private static int ability2 = KeyEvent.VK_E;
private static int ability3 = KeyEvent.VK_R;
private static int escape = KeyEvent.VK_ESCAPE;
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 right = KeyEvent.VK_RIGHT;
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) {
switch(input){
case ATTACK:
attack=j;break;
case SPELL:
spell =j;break;
case CIRCLE:
circle=j;break;
case ABILITY_1:
ability1 =j;break;
case ABILITY_2:
ability2=j;break;
case ABILITY_3:
ability3=j;break;
case ESCAPE:
escape=j;break;
case UP_ARROW:
......@@ -53,8 +63,9 @@ public class InputConfiguration {
public static Input GetInput(KeyEvent e){
int event=e.getKeyCode();
if (event==attack){return Input.ATTACK;}
if (event==circle){return Input.CIRCLE;}
if (event== spell){return Input.SPELL;}
if (event== ability1){return Input.ABILITY_1;}
if (event==ability2){return Input.ABILITY_2;}
if (event== ability3){return Input.ABILITY_3;}
if (event==escape){return Input.ESCAPE;}
if (event==up){return Input.UP_ARROW;}
if (event==down){return Input.DOWN_ARROW;}
......@@ -69,7 +80,7 @@ public class InputConfiguration {
* @return the string of the character whose code is j
* 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) {
case KeyEvent.VK_A:
return "a";
......@@ -131,9 +142,72 @@ public class InputConfiguration {
return "left_arrow";
case KeyEvent.VK_RIGHT:
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:
throw new IllegalStateException("Unknown int" + j);
throw new IllegalStateException("int linked with no character : " + j);
}
}
......@@ -141,28 +215,62 @@ public class InputConfiguration {
* @param input : a formal Input
* @return the string of the character linked to input
*/
public static String GetKey(Input input){
public static String GetFormalInputString(Input input){
switch (input) {
case ATTACK:
return GetChar(attack);
case SPELL:
return GetChar(spell);
case CIRCLE:
return GetChar(circle);
return GetString(attack);
case ABILITY_1:
return GetString(ability1);
case ABILITY_2:
return GetString(ability2);
case ABILITY_3:
return GetString(ability3);
case ESCAPE:
return GetChar(escape);
return GetString(escape);
case UP_ARROW:
return GetChar(up);
return GetString(up);
case DOWN_ARROW:
return GetChar(down);
return GetString(down);
case RIGHT_ARROW:
return GetChar(right);
return GetString(right);
case LEFT_ARROW:
return GetChar(left);
return GetString(left);
case NONE:
return " ";
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 {
case ATTACK:
attack=e.getKeyCode();
break;
case SPELL:
spell =e.getKeyCode();
case ABILITY_1:
ability1 =e.getKeyCode();
break;
case CIRCLE:
circle=e.getKeyCode();
case ABILITY_2:
ability2=e.getKeyCode();
break;
case ABILITY_3:
ability3=e.getKeyCode();
break;
case ESCAPE:
escape=e.getKeyCode();
break;
......@@ -200,7 +311,7 @@ public class InputConfiguration {
case NONE:
return;
default:
throw new IllegalStateException("Unknown input"+ input);
throw new IllegalStateException("Unknown input: "+ input);
}
}
......
......@@ -2,6 +2,7 @@ package graphics.termSkeleton;
import graphics.graphical_abstraction.FrameKeyListenerAbstraction;
import graphics.ingame_input_listener.Input;
import graphics.ingame_input_listener.InputConfiguration;
import java.io.*;
import java.util.HashSet;
......@@ -83,39 +84,47 @@ public class TermFrameKeyListener implements FrameKeyListenerAbstraction{
}
in = new BufferedReader( new InputStreamReader(System.in) );
int line = 0;
int line;
try {
while (in.ready()) {
line = in.read();
//if(line == 27){
// //graphicsMaster.keyPressedHandler(Input.ESCAPE);
// inputs_current.add(Input.ESCAPE);
//}
if (line == 27) { // 27 -> Escape
if (line == InputConfiguration.GetFormalInputChar(Input.ESCAPE)) {
//graphicsMaster.keyPressedHandler(Input.ESCAPE);
inputs_current.add(Input.ESCAPE);
}
if (line == 'q') { //<-, left arrow
if (line == InputConfiguration.GetFormalInputChar(Input.LEFT_ARROW)) {
//graphicsMaster.keyPressedHandler(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);
inputs_current.add(Input.UP_ARROW);
}
if (line == 'd') { // ->, right arrow
if (line == InputConfiguration.GetFormalInputChar(Input.RIGHT_ARROW)) {
//graphicsMaster.keyPressedHandler(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);
inputs_current.add(Input.DOWN_ARROW);
}
if (line == 'e') { // \/, down arrow
if (line == InputConfiguration.GetFormalInputChar(Input.ATTACK)) {
//graphicsMaster.keyPressedHandler(Input.DOWN_ARROW);
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)
......
......@@ -7,13 +7,15 @@ import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runners.model.TestTimedOutException;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import static org.junit.Assert.assertEquals;
//import org.junit.runners.model.TestTimedOutException;
/**
* Class for JUnits test for the class ServerConnection.
* 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