erste rudimentaer funktionierende version mit tisch und button und lichtschranke

This commit is contained in:
Lucas Pleß 2012-05-17 01:13:06 +02:00
parent 7f2b98a554
commit 418bdf2801
3 changed files with 50 additions and 105 deletions

View File

@ -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<StateChangeListener> stateChangeListenerList = new ArrayList<StateChangeListener>();
private int stateChangeCounter = 0;
@ -122,6 +122,8 @@ public class Statemachine {
case TABLE_GAME_TWO:
if(input == TABLE_THREE) {
retVal = state.TABLE_GAME_THREE;
} else if (input == TABLE_TWO) {
} else {
retVal = state.TABLE_GAME_ONE;
}
@ -129,6 +131,8 @@ public class Statemachine {
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;
}

View File

@ -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;
}
}
}

View File

@ -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());
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());
//bunti.setPar56(1, 0xff, 0xff, 0xff);
}
updateGui();
}
@ -78,41 +87,56 @@ 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();