From b388cce5f08eddc4b62c2e790fe7b6388790f0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Fri, 8 Jun 2012 00:58:08 +0200 Subject: [PATCH] changed game behaviour --- src/de/ctdo/crashtest/TestClass.java | 26 +++-- .../ctdo/crashtest/domotics/Relaisboard.java | 110 +++++++++--------- src/de/ctdo/crashtest/game/IStatemachine.java | 1 + src/de/ctdo/crashtest/game/Statemachine.java | 16 ++- src/de/ctdo/crashtest/game/TheGame.java | 75 +++++++++--- src/de/ctdo/crashtest/gui/MainGui.java | 9 +- 6 files changed, 138 insertions(+), 99 deletions(-) diff --git a/src/de/ctdo/crashtest/TestClass.java b/src/de/ctdo/crashtest/TestClass.java index 9a74739..c9c6fc6 100644 --- a/src/de/ctdo/crashtest/TestClass.java +++ b/src/de/ctdo/crashtest/TestClass.java @@ -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(); } diff --git a/src/de/ctdo/crashtest/domotics/Relaisboard.java b/src/de/ctdo/crashtest/domotics/Relaisboard.java index 5b482da..9b4d405 100644 --- a/src/de/ctdo/crashtest/domotics/Relaisboard.java +++ b/src/de/ctdo/crashtest/domotics/Relaisboard.java @@ -18,20 +18,22 @@ public class Relaisboard implements IRelaisboard { } private void sendData(final int relais, final boolean state) { - 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' }; + 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' }; - try { - if(state) { - outputStream.write(charsOn[relais]); - } else { - outputStream.write(charsOff[relais]); + try { + if(state) { + outputStream.write(charsOn[relais]); + } else { + outputStream.write(charsOff[relais]); + } + + outputStream.flush(); + } catch (IOException e) { + Logger.sLog("Fehler beim Senden"); } - - outputStream.flush(); - } catch (IOException e) { - Logger.sLog("Fehler beim Senden"); } } } @@ -96,73 +98,67 @@ 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() { - sendData(relais, state); - } - }; + Runnable r = new Runnable() { + @Override + public void run() { + sendData(relais, state); + } + }; - new Thread(r).start(); - } + 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() { - sendData(relais, true); + Runnable r = new Runnable() { + @Override + public void run() { + sendData(relais, true); - try { - Thread.sleep(milliseconds); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - sendData(relais, false); + try { + Thread.sleep(milliseconds); + } catch (InterruptedException e) { + e.printStackTrace(); } - }; - new Thread(r).start(); - } + sendData(relais, false); + } + }; + + 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() { - int i; + Runnable r = new Runnable() { + @Override + public void run() { + int i; - for(i = 0; i< count; i++) { - sendData(relais, true); + for(i = 0; i< count; i++) { + sendData(relais, true); - try { - Thread.sleep(pause); - } catch (InterruptedException e) { - e.printStackTrace(); - } + try { + Thread.sleep(pause); + } catch (InterruptedException e) { + e.printStackTrace(); + } - sendData(relais, false); + sendData(relais, false); - try { - Thread.sleep(pause); - } catch (InterruptedException e) { - e.printStackTrace(); - } + try { + Thread.sleep(pause); + } catch (InterruptedException e) { + e.printStackTrace(); } } - }; + } + }; - new Thread(r).start(); - } + new Thread(r).start(); } } diff --git a/src/de/ctdo/crashtest/game/IStatemachine.java b/src/de/ctdo/crashtest/game/IStatemachine.java index ceb5f3d..745eb5c 100644 --- a/src/de/ctdo/crashtest/game/IStatemachine.java +++ b/src/de/ctdo/crashtest/game/IStatemachine.java @@ -8,6 +8,7 @@ public interface IStatemachine { int getStateChangeCounter(); void handleInput(char input); int getTimerSecondsLast(); + int getTimerSeconds(); void startTimer(int seconds); diff --git a/src/de/ctdo/crashtest/game/Statemachine.java b/src/de/ctdo/crashtest/game/Statemachine.java index d2d72a8..a46f7ed 100644 --- a/src/de/ctdo/crashtest/game/Statemachine.java +++ b/src/de/ctdo/crashtest/game/Statemachine.java @@ -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 { diff --git a/src/de/ctdo/crashtest/game/TheGame.java b/src/de/ctdo/crashtest/game/TheGame.java index 2a4b938..9217477 100644 --- a/src/de/ctdo/crashtest/game/TheGame.java +++ b/src/de/ctdo/crashtest/game/TheGame.java @@ -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); } diff --git a/src/de/ctdo/crashtest/gui/MainGui.java b/src/de/ctdo/crashtest/gui/MainGui.java index 389f000..cb41549 100644 --- a/src/de/ctdo/crashtest/gui/MainGui.java +++ b/src/de/ctdo/crashtest/gui/MainGui.java @@ -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);