diff --git a/src/de/ctdo/crashtest/Statemachine.java b/src/de/ctdo/crashtest/Statemachine.java index 14cf633..9997d31 100644 --- a/src/de/ctdo/crashtest/Statemachine.java +++ b/src/de/ctdo/crashtest/Statemachine.java @@ -4,11 +4,11 @@ import java.util.ArrayList; import java.util.List; public class Statemachine { - private final char BLUE_BUTTON = 'd'; - private final char LIGHT_BARRIER = 'k'; - private final char TABLE_ONE = 'c'; - private final char TABLE_TWO = 'v'; - private final char TABLE_THREE = 'b'; + private final char BLUE_BUTTON = 'E'; + private final char LIGHT_BARRIER = 'F'; + private final char TABLE_ONE = 'G'; + private final char TABLE_TWO = 'H'; + private final char TABLE_THREE = 'I'; private long lastHandleInput = 0; private final List stateChangeListenerList = new ArrayList(); private int stateChangeCounter = 0; @@ -122,13 +122,17 @@ public class Statemachine { case TABLE_GAME_TWO: if(input == TABLE_THREE) { retVal = state.TABLE_GAME_THREE; - } else { + } else if (input == TABLE_TWO) { + + } else { retVal = state.TABLE_GAME_ONE; } break; case TABLE_GAME_THREE: if(input == TABLE_TWO) { retVal = state.TABLE_GAME_FOUR; + } else if (input == TABLE_THREE) { + } else { retVal = state.TABLE_GAME_ONE; } @@ -136,6 +140,8 @@ public class Statemachine { case TABLE_GAME_FOUR: if(input == TABLE_THREE) { retVal = state.TABLE_GAME_FIVE; + } else if (input == TABLE_TWO) { + } else { retVal = state.TABLE_GAME_ONE; } @@ -143,6 +149,8 @@ public class Statemachine { case TABLE_GAME_FIVE: if(input == TABLE_ONE) { retVal = state.TABLE_GAME_SIX; + } else if (input == TABLE_THREE) { + } else { retVal = state.TABLE_GAME_ONE; } @@ -150,6 +158,8 @@ public class Statemachine { case TABLE_GAME_SIX: if(input == TABLE_THREE) { retVal = state.TABLE_GAME_SEVEN; + } else if (input == TABLE_ONE) { + } else { retVal = state.TABLE_GAME_ONE; } @@ -157,6 +167,8 @@ public class Statemachine { case TABLE_GAME_SEVEN: if(input == BLUE_BUTTON) { retVal = state.FINISH; + } else if (input == TABLE_THREE) { + } else { retVal = state.TABLE_GAME_ONE; } diff --git a/src/de/ctdo/crashtest/Steuerung.java b/src/de/ctdo/crashtest/Steuerung.java index 19c99c9..b2c3aa3 100644 --- a/src/de/ctdo/crashtest/Steuerung.java +++ b/src/de/ctdo/crashtest/Steuerung.java @@ -7,104 +7,13 @@ import java.nio.CharBuffer; public class Steuerung { - private static enum STATE { - IDLE, - ROOM_ENTERED, - TABLE_GAME, - } - private STATE current_state = STATE.IDLE; - public static void main(String args[]) { - //new Steuerung().run(); - new SteuerungFrame(); } - public void FlushInputBuffer() { - int TempValue = 0; - - do { - try { - TempValue = System.in.read(); - } - catch (java.io.IOException e) { - } - } while (TempValue != 10); - } - - public char GetChar() { - int ReadValue = 0; - - try { - ReadValue = System.in.read(); - } - catch (java.io.IOException e) { - } - - this.FlushInputBuffer(); - - return (char) ReadValue; - } - - public void run() { - boolean doRun = true; - //BufferedReader in = new BufferedReader(new InputStreamReader( System.in ) ); - InputStreamReader in = new InputStreamReader(System.in); - - while(doRun) { - char[] buffer = new char[100]; - - try { - - char c = GetChar(); - - System.out.println("char = " + c); - - //if(command.equals("exit") || command.equals("quit")) doRun = false; - - //handleCommand(command); - - - - Thread.sleep(200); - -// } catch (IOException e) { -// e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - - System.out.println("Current state after: " + current_state); - } - } - - private void handleCommand(String command) { - System.out.println("Current state before: " + current_state); - - switch (current_state) { - case IDLE: - - if(command.equals("c")) { - current_state = STATE.ROOM_ENTERED; - } - - break; - case ROOM_ENTERED: - - break; - case TABLE_GAME: - - - break; - } - - - - } } diff --git a/src/de/ctdo/crashtest/SteuerungFrame.java b/src/de/ctdo/crashtest/SteuerungFrame.java index 5f642c7..22c8b2e 100644 --- a/src/de/ctdo/crashtest/SteuerungFrame.java +++ b/src/de/ctdo/crashtest/SteuerungFrame.java @@ -9,6 +9,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.net.UnknownHostException; +import java.util.Random; public class SteuerungFrame extends JFrame implements StateChangeListener { private JPanel pnlRoot; @@ -50,9 +51,17 @@ public class SteuerungFrame extends JFrame implements StateChangeListener { @Override public void keyTyped(KeyEvent e) { lastKey = e.getKeyChar(); - //System.out.println(e.getKeyChar()); - machine.handleInput(e.getKeyChar()); - //bunti.setPar56(1, 0xff, 0xff, 0xff); + + if (lastKey == KeyEvent.VK_F) { + Random r = new Random(); + setLEDs(r.nextInt(255), r.nextInt(255),r.nextInt(255)); + } + + if (lastKey == KeyEvent.VK_1) { + machine.reset(); + } else { + machine.handleInput(e.getKeyChar()); + } updateGui(); } @@ -78,40 +87,55 @@ public class SteuerungFrame extends JFrame implements StateChangeListener { switch (newState) { case IDLE: - bunti.setPar56(0,0,0,0); - bunti.setPar56(1,0,0,0); - bunti.setPar56(2,0,0,0); - bunti.setPar56(3,0,0,0); + setLEDs(0,0,0); bunti.setLampel(false,false,false); break; case ENTERED_ROOM: bunti.setLampel(true,false,false); - + setLEDs(255,0,0); break; case TABLE_GAME_ONE: bunti.setLampel(false,true,false); + setLEDs(255,255,0); break; case TABLE_GAME_TWO: bunti.setLampel(false,true,false); + setLEDs(0,255,0); break; case TABLE_GAME_THREE: bunti.setLampel(false,true,false); + setLEDs(0,255,255); break; case TABLE_GAME_FOUR: bunti.setLampel(false,true,false); + setLEDs(0,0,255); break; case TABLE_GAME_FIVE: bunti.setLampel(false,true,false); + setLEDs(255,255,255); break; case TABLE_GAME_SIX: bunti.setLampel(false,true,false); + setLEDs(30,30,30); break; case TABLE_GAME_SEVEN: bunti.setLampel(false,false,true); + setLEDs(30,0,255); + break; + case FINISH: + setLEDs(0, 255, 0); break; } } + + + private void setLEDs(int red, int green, int blue) { + bunti.setPar56(0,red,green,blue); + bunti.setPar56(1,red,green,blue); + bunti.setPar56(2,red,green,blue); + bunti.setPar56(3,red,green,blue); + } private void initGui() { Container pane = getContentPane();