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 {
IRelaisboard board = new Relaisboard("/dev/ttyUSB0");
board.open();
IRelaisboard relaisboard = new Relaisboard("/dev/ttyUSB0");
relaisboard.open();
/*
board.setRelais(1,false);
//board.setRelais(1, true);
relaisboard.setRelais(1,false);
//relaisboard.setRelais(1, true);
board.toggleRelais(1, 500);
relaisboard.toggleRelais(1, 500);
Thread.sleep(1000);
board.toggleRelais(1, 500);
relaisboard.toggleRelais(1, 500);
Thread.sleep(1000);
board.toggleRelais(1, 500);
relaisboard.toggleRelais(1, 500);
//board.setRelais(1, false);
//relaisboard.setRelais(1, false);
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) {
synchronized (outputStream) {
if(relais >= 0 && relais < 8 && outputStream != null) {
char charsOff[] = { '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
@ -96,7 +98,6 @@ public class Relaisboard implements IRelaisboard {
public void setRelais(final int relais, final boolean state) {
if(!serialPortGeoeffnet) return;
synchronized (mLock) {
Runnable r = new Runnable() {
@Override
public void run() {
@ -106,13 +107,11 @@ public class Relaisboard implements IRelaisboard {
new Thread(r).start();
}
}
@Override
public void toggleRelais(final int relais, final int milliseconds) {
if(!serialPortGeoeffnet) return;
synchronized (mLock) {
Runnable r = new Runnable() {
@Override
public void run() {
@ -130,13 +129,11 @@ public class Relaisboard implements IRelaisboard {
new Thread(r).start();
}
}
@Override
public void blinkRelais(final int relais, final int pause, final int count) {
if(!serialPortGeoeffnet) return;
synchronized (mLock) {
Runnable r = new Runnable() {
@Override
public void run() {
@ -164,5 +161,4 @@ public class Relaisboard implements IRelaisboard {
new Thread(r).start();
}
}
}

View File

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

View File

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

View File

@ -13,6 +13,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
private IBuntiClient bunti;
private IMPDController mpdController;
private IRelaisboard relaisboard;
private int gamerRating = 3;
public TheGame(IGuiControl guiControl) {
this.guiControl = guiControl;
@ -36,6 +37,12 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
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
@ -48,6 +55,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
switch (newState) {
case IDLE:
gamerRating = 3;
machine.stopTimer();
guiControl.setExtra("");
guiControl.setWall("");
@ -79,12 +87,12 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
mpdController.playSong("K2", "Der Berg Ruft");
bunti.setLampel(true,false,false);
bunti.setPar56(255,0,100);
bunti.setPar56(20,0,100);
guiControl.showCountDown(true);
break;
case TABLE_GAME_TWO:
bunti.setLampel(false,true,false);
bunti.setPar56(255,0,100);
bunti.setPar56(100,0,100);
guiControl.showCountDown(true);
break;
@ -100,48 +108,58 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
bunti.setLampel(false,true,false);
bunti.setPar56(255,55,0);
bunti.setPar56(200,100,0);
guiControl.showCountDown(true);
break;
case TABLE_GAME_FIVE:
bunti.setLampel(false,true,false);
bunti.setPar56(255,75,0);
bunti.setPar56(150,150,0);
guiControl.showCountDown(true);
break;
case TABLE_GAME_SIX:
mpdController.setVolume(60);
mpdController.playSong("Zlatko & Jürgen","Großer Bruder");
//mpdController.setVolume(60);
//mpdController.playSong("Zlatko & Jürgen","Großer Bruder");
bunti.setLampel(false,true,false);
bunti.setPar56(255,100,0);
bunti.setPar56(100,200,0);
guiControl.showCountDown(true);
break;
case TABLE_GAME_DONE:
bunti.setLampel(false,false,true);
bunti.setPar56(255,100,0);
bunti.setPar56(100,255,0);
guiControl.showCountDown(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();
relaisboard.blinkRelais(2, 500, 6); // hint Button
relaisboard.blinkRelais(2, 700, 6); // hint Button
break;
case ROKET_STARTED:
mpdController.setVolume(50);
mpdController.playSong("The Underdog Project", "Summer Jam");
bunti.setLampel(false,false,true);
bunti.setPar56(0, 255, 0);
ircClient.say("table game complete, r0kets now");
relaisboard.toggleRelais(0, 300);
relaisboard.toggleRelais(3, 10000);
guiControl.showCountDown(true);
machine.startTimer(7*60);
@ -150,12 +168,22 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
mpdController.setVolume(50);
mpdController.playSong("Coldplay", "Amsterdam");
bunti.setLampel(true,true,true);
bunti.setPar56(255, 196, 0);
guiControl.showCountDown(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;
}
@ -164,7 +192,16 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
@Override
public void timerTick(int 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 {
ircClient.say("dafuq?");
}
}
private void sayScore() {
ircClient.say("stateChangeCounter: " + machine.getStateChangeCounter());
// ircClient.say("timerlast: " + machine.getTimerSecondsLast());
int seconds = machine.getTimerSecondsLast();
int seconds1 = machine.getTimerSeconds();
int mins = 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 red = 255.0 - percentile * 255.0;
double green = 255.0 - red;
double blue = percentile * 100.0;
// 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(green > 255) green = 255;
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);
}
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 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.setForeground(fontColor);