changed game behaviour

This commit is contained in:
Lucas Pleß 2012-06-08 00:58:08 +02:00
parent 6e81052e38
commit b388cce5f0
6 changed files with 138 additions and 99 deletions

View File

@ -13,29 +13,33 @@ public class TestClass {
public static void main(String args[]) throws InterruptedException { public static void main(String args[]) throws InterruptedException {
IRelaisboard board = new Relaisboard("/dev/ttyUSB0"); IRelaisboard relaisboard = new Relaisboard("/dev/ttyUSB0");
board.open(); relaisboard.open();
/* /*
board.setRelais(1,false); relaisboard.setRelais(1,false);
//board.setRelais(1, true); //relaisboard.setRelais(1, true);
board.toggleRelais(1, 500); relaisboard.toggleRelais(1, 500);
Thread.sleep(1000); Thread.sleep(1000);
board.toggleRelais(1, 500); relaisboard.toggleRelais(1, 500);
Thread.sleep(1000); Thread.sleep(1000);
board.toggleRelais(1, 500); relaisboard.toggleRelais(1, 500);
//board.setRelais(1, false); //relaisboard.setRelais(1, false);
Thread.sleep(4000); */ Thread.sleep(4000); */
board.blinkRelais(2, 500, 6); // hint Button //relaisboard.blinkRelais(2, 500, 6);
relaisboard.toggleRelais(0, 300);
relaisboard.toggleRelais(1, 600);
relaisboard.toggleRelais(2, 1000);
relaisboard.toggleRelais(3, 10000);
Thread.sleep(6000); Thread.sleep(11000);
board.close(); relaisboard.close();
} }

View File

@ -18,6 +18,7 @@ public class Relaisboard implements IRelaisboard {
} }
private void sendData(final int relais, final boolean state) { private void sendData(final int relais, final boolean state) {
synchronized (outputStream) {
if(relais >= 0 && relais < 8 && outputStream != null) { if(relais >= 0 && relais < 8 && outputStream != null) {
char charsOff[] = { 'a','b','c','d','e','f','g','h' }; char charsOff[] = { 'a','b','c','d','e','f','g','h' };
char charsOn[] = { 'A','B','C','D','E','F','G','H' }; char charsOn[] = { 'A','B','C','D','E','F','G','H' };
@ -35,6 +36,7 @@ public class Relaisboard implements IRelaisboard {
} }
} }
} }
}
@Override @Override
@ -96,7 +98,6 @@ public class Relaisboard implements IRelaisboard {
public void setRelais(final int relais, final boolean state) { public void setRelais(final int relais, final boolean state) {
if(!serialPortGeoeffnet) return; if(!serialPortGeoeffnet) return;
synchronized (mLock) {
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -106,13 +107,11 @@ public class Relaisboard implements IRelaisboard {
new Thread(r).start(); new Thread(r).start();
} }
}
@Override @Override
public void toggleRelais(final int relais, final int milliseconds) { public void toggleRelais(final int relais, final int milliseconds) {
if(!serialPortGeoeffnet) return; if(!serialPortGeoeffnet) return;
synchronized (mLock) {
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -130,13 +129,11 @@ public class Relaisboard implements IRelaisboard {
new Thread(r).start(); new Thread(r).start();
} }
}
@Override @Override
public void blinkRelais(final int relais, final int pause, final int count) { public void blinkRelais(final int relais, final int pause, final int count) {
if(!serialPortGeoeffnet) return; if(!serialPortGeoeffnet) return;
synchronized (mLock) {
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -164,5 +161,4 @@ public class Relaisboard implements IRelaisboard {
new Thread(r).start(); new Thread(r).start();
} }
}
} }

View File

@ -8,6 +8,7 @@ public interface IStatemachine {
int getStateChangeCounter(); int getStateChangeCounter();
void handleInput(char input); void handleInput(char input);
int getTimerSecondsLast(); int getTimerSecondsLast();
int getTimerSeconds();
void startTimer(int seconds); void startTimer(int seconds);

View File

@ -19,7 +19,8 @@ public class Statemachine implements IStatemachine {
TABLE_GAME_SIX, TABLE_GAME_SIX,
TABLE_GAME_DONE, TABLE_GAME_DONE,
ROKET_STARTED, ROKET_STARTED,
ROKET_DONE ROKET_DONE,
LOOSED
} }
private final char RESET = '1'; private final char RESET = '1';
@ -37,6 +38,7 @@ public class Statemachine implements IStatemachine {
private int stateChangeCounter; private int stateChangeCounter;
private state currentState; private state currentState;
private int timertSecondsLast; private int timertSecondsLast;
private int timertSeconds;
public Statemachine() { public Statemachine() {
@ -82,8 +84,6 @@ public class Statemachine implements IStatemachine {
if( newState != currentState ) { if( newState != currentState ) {
stateChangeCounter++; stateChangeCounter++;
Logger.sLog("newState = " + newState);
currentState = newState; currentState = newState;
onStateChanged(); onStateChanged();
} }
@ -96,23 +96,27 @@ public class Statemachine implements IStatemachine {
return timertSecondsLast / 10; return timertSecondsLast / 10;
} }
@Override
public int getTimerSeconds() {
return timertSeconds / 10;
}
@Override @Override
public void startTimer(int seconds) { public void startTimer(int seconds) {
Logger.sLog("starting timer");
timertSecondsLast = seconds*10; timertSecondsLast = seconds*10;
timertSeconds = seconds*10;
scheduleTimer(); scheduleTimer();
} }
@Override @Override
public void stopTimer() { public void stopTimer() {
Logger.sLog("stopping timer");
if(timer != null) timer.cancel(); if(timer != null) timer.cancel();
timertSecondsLast = 0; timertSecondsLast = 0;
timertSeconds = 0;
} }
@Override @Override
public void pauseTimer(boolean pause) { public void pauseTimer(boolean pause) {
Logger.sLog("pausing timer: " + pause);
if(pause) { if(pause) {
if(timer != null) timer.cancel(); if(timer != null) timer.cancel();
} else { } else {

View File

@ -13,6 +13,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
private IBuntiClient bunti; private IBuntiClient bunti;
private IMPDController mpdController; private IMPDController mpdController;
private IRelaisboard relaisboard; private IRelaisboard relaisboard;
private int gamerRating = 3;
public TheGame(IGuiControl guiControl) { public TheGame(IGuiControl guiControl) {
this.guiControl = guiControl; this.guiControl = guiControl;
@ -36,6 +37,12 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
relaisboard.toggleRelais(2, 2000); relaisboard.toggleRelais(2, 2000);
} }
private void rate(int rating) {
gamerRating += rating;
if(gamerRating > 5) gamerRating = 5;
if(gamerRating < 1) gamerRating = 1;
}
/** /**
* Event listener for state change events from statemachine * Event listener for state change events from statemachine
@ -48,6 +55,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
switch (newState) { switch (newState) {
case IDLE: case IDLE:
gamerRating = 3;
machine.stopTimer(); machine.stopTimer();
guiControl.setExtra(""); guiControl.setExtra("");
guiControl.setWall(""); guiControl.setWall("");
@ -79,12 +87,12 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
mpdController.playSong("K2", "Der Berg Ruft"); mpdController.playSong("K2", "Der Berg Ruft");
bunti.setLampel(true,false,false); bunti.setLampel(true,false,false);
bunti.setPar56(255,0,100); bunti.setPar56(20,0,100);
guiControl.showCountDown(true); guiControl.showCountDown(true);
break; break;
case TABLE_GAME_TWO: case TABLE_GAME_TWO:
bunti.setLampel(false,true,false); bunti.setLampel(false,true,false);
bunti.setPar56(255,0,100); bunti.setPar56(100,0,100);
guiControl.showCountDown(true); guiControl.showCountDown(true);
break; break;
@ -100,48 +108,58 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
bunti.setLampel(false,true,false); bunti.setLampel(false,true,false);
bunti.setPar56(255,55,0); bunti.setPar56(200,100,0);
guiControl.showCountDown(true); guiControl.showCountDown(true);
break; break;
case TABLE_GAME_FIVE: case TABLE_GAME_FIVE:
bunti.setLampel(false,true,false); bunti.setLampel(false,true,false);
bunti.setPar56(255,75,0); bunti.setPar56(150,150,0);
guiControl.showCountDown(true); guiControl.showCountDown(true);
break; break;
case TABLE_GAME_SIX: case TABLE_GAME_SIX:
mpdController.setVolume(60); //mpdController.setVolume(60);
mpdController.playSong("Zlatko & Jürgen","Großer Bruder"); //mpdController.playSong("Zlatko & Jürgen","Großer Bruder");
bunti.setLampel(false,true,false); bunti.setLampel(false,true,false);
bunti.setPar56(255,100,0); bunti.setPar56(100,200,0);
guiControl.showCountDown(true); guiControl.showCountDown(true);
break; break;
case TABLE_GAME_DONE: case TABLE_GAME_DONE:
bunti.setLampel(false,false,true); bunti.setLampel(false,false,true);
bunti.setPar56(255,100,0); bunti.setPar56(100,255,0);
guiControl.showCountDown(true); guiControl.showCountDown(true);
machine.pauseTimer(true); machine.pauseTimer(true);
// spieler haben 8 Minuten, wenn sie es in weniger als 4 minuten schaffen
// gibts +1, in weniger als 2 minuten gibts +2
if(machine.getTimerSecondsLast() >= 6*60 ) {
rate(2);
} else if(machine.getTimerSecondsLast() > 4*60) {
rate(1);
}
if(machine.getStateChangeCounter() > 100) {
rate(-1);
}
sayScore(); sayScore();
relaisboard.blinkRelais(2, 500, 6); // hint Button relaisboard.blinkRelais(2, 700, 6); // hint Button
break; break;
case ROKET_STARTED: case ROKET_STARTED:
mpdController.setVolume(50); mpdController.setVolume(50);
mpdController.playSong("The Underdog Project", "Summer Jam"); mpdController.playSong("The Underdog Project", "Summer Jam");
bunti.setLampel(false,false,true); bunti.setLampel(false,false,true);
bunti.setPar56(0, 255, 0); bunti.setPar56(0, 255, 0);
ircClient.say("table game complete, r0kets now"); ircClient.say("table game complete, r0kets now");
relaisboard.toggleRelais(0, 300); relaisboard.toggleRelais(0, 300);
relaisboard.toggleRelais(3, 10000);
guiControl.showCountDown(true); guiControl.showCountDown(true);
machine.startTimer(7*60); machine.startTimer(7*60);
@ -150,12 +168,22 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
mpdController.setVolume(50); mpdController.setVolume(50);
mpdController.playSong("Coldplay", "Amsterdam"); mpdController.playSong("Coldplay", "Amsterdam");
bunti.setLampel(true,true,true); bunti.setLampel(true,true,true);
bunti.setPar56(255, 196, 0); bunti.setPar56(255, 196, 0);
guiControl.showCountDown(true); guiControl.showCountDown(true);
machine.pauseTimer(true); machine.pauseTimer(true);
// spieler haben 7 Minuten, wenn sie es in weniger als 4 minuten schaffen
// gibts +1, in weniger als 2 minuten gibts +2
if(machine.getTimerSecondsLast() >= 5*60 ) {
rate(2);
} else if(machine.getTimerSecondsLast() > 3*60) {
rate(1);
}
sayScore();
break; break;
} }
@ -164,7 +192,16 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
@Override @Override
public void timerTick(int tsecondsLeft) { public void timerTick(int tsecondsLeft) {
guiControl.setCountDown(tsecondsLeft); guiControl.setCountDown(tsecondsLeft);
if(tsecondsLeft == 0) ircClient.say("timer expired"); if(tsecondsLeft == 0) {
ircClient.say("timer expired");
Statemachine.state bla = machine.getCurrentState();
if( bla != Statemachine.state.TABLE_GAME_DONE &&
bla != Statemachine.state.ROKET_DONE ) {
rate(-2);
sayScore();
}
}
} }
@ -305,19 +342,19 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
} else { } else {
ircClient.say("dafuq?"); ircClient.say("dafuq?");
} }
} }
private void sayScore() { private void sayScore() {
ircClient.say("stateChangeCounter: " + machine.getStateChangeCounter()); ircClient.say("stateChangeCounter: " + machine.getStateChangeCounter());
// ircClient.say("timerlast: " + machine.getTimerSecondsLast());
int seconds = machine.getTimerSecondsLast(); int seconds = machine.getTimerSecondsLast();
int seconds1 = machine.getTimerSeconds();
int mins = seconds / 60; int mins = seconds / 60;
int secs = seconds % 60; int secs = seconds % 60;
ircClient.say(" " + mins + ":" + secs + ""); int mins1 = seconds1 / 60;
int secs1 = seconds1 % 60;
ircClient.say("time " + mins1 + ":" + secs1 + " last: " + mins + ":" + secs + "");
ircClient.say("gamerRating: " + gamerRating);
} }

View File

@ -55,7 +55,6 @@ public class MainGui extends JFrame implements IGuiControl {
double percentile = ((tseconds-100.0)/300.0); double percentile = ((tseconds-100.0)/300.0);
double red = 255.0 - percentile * 255.0; double red = 255.0 - percentile * 255.0;
double green = 255.0 - red; double green = 255.0 - red;
double blue = percentile * 100.0;
// System.out.println("red= " + red + " green=" + green + " blue="+blue); // System.out.println("red= " + red + " green=" + green + " blue="+blue);
@ -63,14 +62,12 @@ public class MainGui extends JFrame implements IGuiControl {
if(red < 0) red = 0; if(red < 0) red = 0;
if(green > 255) green = 255; if(green > 255) green = 255;
if(green < 0) green = 0; if(green < 0) green = 0;
if(blue > 255) blue = 255;
if(blue < 0) blue = 0;
Color fColor = new Color((int)red,(int)green, (int)blue); Color fColor = new Color((int)red,(int)green, 0);
countDown.setForeground(fColor); countDown.setForeground(fColor);
} }
else { else {
countDown.setForeground(new Color(0x00, 190, 100)); countDown.setForeground(new Color(42, 190, 0));
} }
} }
@ -87,7 +84,7 @@ public class MainGui extends JFrame implements IGuiControl {
Font wallFont = new Font("Arcade Interlaced", Font.PLAIN, 66); Font wallFont = new Font("Arcade Interlaced", Font.PLAIN, 66);
Font lowerFont = new Font("Arcade Interlaced", Font.PLAIN, 80); Font lowerFont = new Font("Arcade Interlaced", Font.PLAIN, 80);
Color fontColor = new Color(0x00, 190, 100); Color fontColor = new Color(42, 190, 0);
textWall.setFont(wallFont); textWall.setFont(wallFont);
textWall.setForeground(fontColor); textWall.setForeground(fontColor);