diff --git a/src/de/ctdo/crashtest/Statemachine.java b/src/de/ctdo/crashtest/Statemachine.java index 9028ee3..602fcf3 100644 --- a/src/de/ctdo/crashtest/Statemachine.java +++ b/src/de/ctdo/crashtest/Statemachine.java @@ -1,7 +1,13 @@ package de.ctdo.crashtest; public class Statemachine { - public enum STATES { + 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'; + + public enum state { IDLE, ENTERED_ROOM, TABLE_GAME_ONE, @@ -11,20 +17,93 @@ public class Statemachine { TABLE_GAME_FIVE, TABLE_GAME_SIX, TABLE_GAME_SEVEN, - TABLE_GAME_EIGHT, FINISH, } - private STATES currentState = STATES.IDLE; + private state currentState = state.IDLE; - public STATES getCurrentState() { + public state getCurrentState() { return currentState; } public void handleInput(char input) { + state newState = getNewState(input); + + System.out.println("newState = " + newState); + + currentState = newState; + } + + private state getNewState(char input) { + state retVal = currentState; + + switch (currentState) { + case IDLE: + if(input == LIGHT_BARRIER) { + retVal = state.ENTERED_ROOM; + } + break; + case ENTERED_ROOM: + if(input == TABLE_ONE) { + retVal = state.TABLE_GAME_ONE; + } + break; + case TABLE_GAME_ONE: + if(input == TABLE_TWO) { + retVal = state.TABLE_GAME_TWO; + } else { + retVal = state.TABLE_GAME_ONE; + } + break; + case TABLE_GAME_TWO: + if(input == TABLE_THREE) { + retVal = state.TABLE_GAME_THREE; + } else { + retVal = state.TABLE_GAME_ONE; + } + break; + case TABLE_GAME_THREE: + if(input == TABLE_TWO) { + retVal = state.TABLE_GAME_FOUR; + } else { + retVal = state.TABLE_GAME_ONE; + } + break; + case TABLE_GAME_FOUR: + if(input == TABLE_THREE) { + retVal = state.TABLE_GAME_FIVE; + } else { + retVal = state.TABLE_GAME_ONE; + } + break; + case TABLE_GAME_FIVE: + if(input == TABLE_ONE) { + retVal = state.TABLE_GAME_SIX; + } else { + retVal = state.TABLE_GAME_ONE; + } + break; + case TABLE_GAME_SIX: + if(input == TABLE_THREE) { + retVal = state.TABLE_GAME_SEVEN; + } else { + retVal = state.TABLE_GAME_ONE; + } + break; + case TABLE_GAME_SEVEN: + if(input == BLUE_BUTTON) { + retVal = state.FINISH; + } else { + retVal = state.TABLE_GAME_ONE; + } + break; + } + + + return retVal; } } diff --git a/src/de/ctdo/crashtest/SteuerungFrame.java b/src/de/ctdo/crashtest/SteuerungFrame.java index 13f0a6d..f7faa93 100644 --- a/src/de/ctdo/crashtest/SteuerungFrame.java +++ b/src/de/ctdo/crashtest/SteuerungFrame.java @@ -9,7 +9,7 @@ public class SteuerungFrame extends JFrame { Statemachine machine = new Statemachine(); public SteuerungFrame() { - setType(Type.UTILITY); + //setType(Type.UTILITY); setBackground(Color.black); setBounds(200,200, 200, 200); @@ -17,7 +17,8 @@ public class SteuerungFrame extends JFrame { addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { - System.out.println(e.getKeyChar()); + //System.out.println(e.getKeyChar()); + machine.handleInput(e.getKeyChar()); } });