cleanup
This commit is contained in:
parent
dc6a1f318c
commit
58a8028bd5
|
@ -1,29 +1,10 @@
|
||||||
package de.ctdo.crashtest;
|
package de.ctdo.crashtest;
|
||||||
|
|
||||||
|
|
||||||
import de.ctdo.crashtest.game.TheGame;
|
import de.ctdo.crashtest.game.TheGame;
|
||||||
import de.ctdo.crashtest.gui.IGuiControl;
|
|
||||||
import de.ctdo.crashtest.gui.MainGui;
|
import de.ctdo.crashtest.gui.MainGui;
|
||||||
|
|
||||||
public class Steuerung {
|
public class Steuerung {
|
||||||
|
|
||||||
private TheGame game;
|
|
||||||
private IGuiControl gui;
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
|
new TheGame(new MainGui());
|
||||||
new Steuerung();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Steuerung() {
|
|
||||||
gui = new MainGui();
|
|
||||||
|
|
||||||
game = new TheGame(gui);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,49 +1,28 @@
|
||||||
package de.ctdo.crashtest;
|
package de.ctdo.crashtest;
|
||||||
|
|
||||||
import de.ctdo.crashtest.domotics.BuntiClient;
|
import de.ctdo.crashtest.gui.GuiEventListener;
|
||||||
import de.ctdo.crashtest.domotics.IBuntiClient;
|
import de.ctdo.crashtest.gui.MainGui;
|
||||||
import de.ctdo.crashtest.domotics.IRelaisboard;
|
|
||||||
import de.ctdo.crashtest.domotics.Relaisboard;
|
|
||||||
import de.ctdo.crashtest.mpd.IMPDController;
|
|
||||||
import de.ctdo.crashtest.mpd.MPDController;
|
|
||||||
|
|
||||||
|
public class TestClass implements GuiEventListener {
|
||||||
|
|
||||||
|
public TestClass() {
|
||||||
public class TestClass {
|
MainGui mg = new MainGui();
|
||||||
|
mg.addListener(this);
|
||||||
|
mg.setCountDown(121411);
|
||||||
|
|
||||||
public static void main(String args[]) throws InterruptedException {
|
|
||||||
|
|
||||||
//IRelaisboard relaisboard = new Relaisboard("/dev/ttyUSB0");
|
|
||||||
//relaisboard.open();
|
|
||||||
//relaisboard.close();
|
|
||||||
|
|
||||||
IBuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080);
|
|
||||||
|
|
||||||
for(int i = 0; i < 10; i++) {
|
|
||||||
bunti.setPar56(0, 255, 0, 0);
|
|
||||||
bunti.setPar56(1, 0, 255, 0);
|
|
||||||
bunti.setPar56(2, 0, 255, 0);
|
|
||||||
bunti.setPar56(3, 255, 0, 0);
|
|
||||||
Thread.sleep(500);
|
|
||||||
bunti.setPar56(0, 0, 0, 255);
|
|
||||||
bunti.setPar56(1, 255, 255, 0);
|
|
||||||
bunti.setPar56(2, 255, 255, 0);
|
|
||||||
bunti.setPar56(3, 0, 0, 255);
|
|
||||||
Thread.sleep(500);
|
|
||||||
bunti.setPar56(0, 255, 128, 0);
|
|
||||||
bunti.setPar56(1, 0, 255, 255);
|
|
||||||
bunti.setPar56(2, 0, 255, 255);
|
|
||||||
bunti.setPar56(3, 255, 128, 0);
|
|
||||||
Thread.sleep(500);
|
|
||||||
bunti.setPar56(0, 0, 255, 255);
|
|
||||||
bunti.setPar56(1, 0, 255, 0);
|
|
||||||
bunti.setPar56(2, 0, 255, 0);
|
|
||||||
bunti.setPar56(3, 0, 255, 255);
|
|
||||||
Thread.sleep(500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
new TestClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPress(char key) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowClosing() {
|
||||||
|
System.out.println("closing");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.io.*;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
public class BuntiClient implements IBuntiClient {
|
public class BuntiClient implements IBuntiClient {
|
||||||
private String baseAddress;
|
private final String baseAddress;
|
||||||
//private final HttpClient client = new DefaultHttpClient();
|
//private final HttpClient client = new DefaultHttpClient();
|
||||||
|
|
||||||
public BuntiClient(String server, int port) {
|
public BuntiClient(String server, int port) {
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package de.ctdo.crashtest.domotics;
|
package de.ctdo.crashtest.domotics;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: lucas
|
|
||||||
* @date: 01.06.12 14:25
|
|
||||||
*/
|
|
||||||
public interface IBuntiClient {
|
public interface IBuntiClient {
|
||||||
void setPar56(final int red, final int green, final int blue);
|
void setPar56(final int red, final int green, final int blue);
|
||||||
void setPar56(final int par, final int red, final int green, final int blue);
|
void setPar56(final int par, final int red, final int green, final int blue);
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package de.ctdo.crashtest.domotics;
|
package de.ctdo.crashtest.domotics;
|
||||||
|
|
||||||
public interface IRelaisboard {
|
public interface IRelaisboard {
|
||||||
|
|
||||||
void setRelais(final int relais, final boolean state);
|
void setRelais(final int relais, final boolean state);
|
||||||
void toggleRelais(final int relais, final int milliseconds);
|
void toggleRelais(final int relais, final int milliseconds);
|
||||||
void blinkRelais(final int relais, final int pause, final int count);
|
|
||||||
void blinkRelais(final int relais, final int pause);
|
void blinkRelais(final int relais, final int pause);
|
||||||
void blinkRelaisStop(final int relais);
|
void blinkRelaisStop(final int relais);
|
||||||
boolean open();
|
boolean open();
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class Relaisboard implements IRelaisboard {
|
||||||
private OutputStream outputStream;
|
private OutputStream outputStream;
|
||||||
private Boolean serialPortGeoeffnet = false;
|
private Boolean serialPortGeoeffnet = false;
|
||||||
private String portName = "/dev/ttyUSB0";
|
private String portName = "/dev/ttyUSB0";
|
||||||
private Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
private final Map<Integer,Thread> threadMap = new ConcurrentHashMap<Integer, Thread>();
|
private final Map<Integer,Thread> threadMap = new ConcurrentHashMap<Integer, Thread>();
|
||||||
private final Map<Integer,Boolean> stopMap = new ConcurrentHashMap<Integer, Boolean>();
|
private final Map<Integer,Boolean> stopMap = new ConcurrentHashMap<Integer, Boolean>();
|
||||||
|
|
||||||
|
@ -21,7 +21,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) {
|
synchronized (mLock) {
|
||||||
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' };
|
||||||
|
@ -49,7 +49,7 @@ public class Relaisboard implements IRelaisboard {
|
||||||
serialPortGeoeffnet = false;
|
serialPortGeoeffnet = false;
|
||||||
Boolean foundPort = false;
|
Boolean foundPort = false;
|
||||||
|
|
||||||
if (serialPortGeoeffnet != false) {
|
if (serialPortGeoeffnet) {
|
||||||
Logger.sLog("Serialport bereits geöffnet");
|
Logger.sLog("Serialport bereits geöffnet");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public class Relaisboard implements IRelaisboard {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (foundPort != true) {
|
if (!foundPort) {
|
||||||
Logger.sLog("Serialport nicht gefunden: " + portName);
|
Logger.sLog("Serialport nicht gefunden: " + portName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public class Relaisboard implements IRelaisboard {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(milliseconds);
|
Thread.sleep(milliseconds);
|
||||||
} catch (InterruptedException e) { }
|
} catch (InterruptedException ignored) { }
|
||||||
|
|
||||||
sendData(relais, false);
|
sendData(relais, false);
|
||||||
}
|
}
|
||||||
|
@ -137,45 +137,6 @@ public class Relaisboard implements IRelaisboard {
|
||||||
new Thread(r).start();
|
new Thread(r).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void blinkRelais(final int relais, final int pause, final int count) {
|
|
||||||
if(!serialPortGeoeffnet) return;
|
|
||||||
|
|
||||||
stopRelaisThread(relais);
|
|
||||||
|
|
||||||
Runnable r = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i = 0; i< count; i++) {
|
|
||||||
sendData(relais, true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(pause);
|
|
||||||
} catch (InterruptedException e) { }
|
|
||||||
|
|
||||||
if(stopMap.get(relais)) return;
|
|
||||||
|
|
||||||
sendData(relais, false);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(pause);
|
|
||||||
} catch (InterruptedException e) { }
|
|
||||||
|
|
||||||
if(stopMap.get(relais)) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(stopMap.get(relais)) sendData(relais,false); // switch off afterwards
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
stopMap.put(relais, false);
|
|
||||||
Thread thread = new Thread(r);
|
|
||||||
threadMap.put(relais,thread);
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void blinkRelais(final int relais, final int pause) {
|
public void blinkRelais(final int relais, final int pause) {
|
||||||
if(!serialPortGeoeffnet) return;
|
if(!serialPortGeoeffnet) return;
|
||||||
|
@ -190,7 +151,7 @@ public class Relaisboard implements IRelaisboard {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(pause);
|
Thread.sleep(pause);
|
||||||
} catch (InterruptedException e) { }
|
} catch (InterruptedException ignored) { }
|
||||||
|
|
||||||
if(stopMap.get(relais)) return;
|
if(stopMap.get(relais)) return;
|
||||||
|
|
||||||
|
@ -198,7 +159,7 @@ public class Relaisboard implements IRelaisboard {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(pause);
|
Thread.sleep(pause);
|
||||||
} catch (InterruptedException e) { }
|
} catch (InterruptedException ignored) { }
|
||||||
|
|
||||||
if(stopMap.get(relais)) return;
|
if(stopMap.get(relais)) return;
|
||||||
}
|
}
|
||||||
|
@ -217,7 +178,7 @@ public class Relaisboard implements IRelaisboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopRelaisThread(final int relais) {
|
private void stopRelaisThread(final int relais) {
|
||||||
Thread thread = (Thread)threadMap.get(relais);
|
Thread thread = threadMap.get(relais);
|
||||||
|
|
||||||
if(thread != null) {
|
if(thread != null) {
|
||||||
stopMap.put(relais, true);
|
stopMap.put(relais, true);
|
||||||
|
|
|
@ -9,8 +9,6 @@ public interface IStatemachine {
|
||||||
void handleInput(char input);
|
void handleInput(char input);
|
||||||
int getTimerSecondsLast();
|
int getTimerSecondsLast();
|
||||||
int getTimerSeconds();
|
int getTimerSeconds();
|
||||||
|
|
||||||
|
|
||||||
void startTimer(int seconds);
|
void startTimer(int seconds);
|
||||||
void stopTimer();
|
void stopTimer();
|
||||||
void pauseTimer(boolean pause);
|
void pauseTimer(boolean pause);
|
||||||
|
|
|
@ -40,7 +40,6 @@ public class Statemachine implements IStatemachine {
|
||||||
private int timertSecondsLast;
|
private int timertSecondsLast;
|
||||||
private int timertSeconds;
|
private int timertSeconds;
|
||||||
|
|
||||||
|
|
||||||
public Statemachine() {
|
public Statemachine() {
|
||||||
currentState = state.IDLE;
|
currentState = state.IDLE;
|
||||||
statemachineListenerList = new ArrayList<StatemachineListener>();
|
statemachineListenerList = new ArrayList<StatemachineListener>();
|
||||||
|
@ -218,7 +217,6 @@ public class Statemachine implements IStatemachine {
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void scheduleTimer() {
|
private void scheduleTimer() {
|
||||||
if(timer != null) timer.cancel();
|
if(timer != null) timer.cancel();
|
||||||
|
|
||||||
|
@ -238,7 +236,4 @@ public class Statemachine implements IStatemachine {
|
||||||
};
|
};
|
||||||
timer.scheduleAtFixedRate(timerTask, 100, 100);
|
timer.scheduleAtFixedRate(timerTask, 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,26 +7,24 @@ import de.ctdo.crashtest.mpd.IMPDController;
|
||||||
import de.ctdo.crashtest.mpd.MPDController;
|
import de.ctdo.crashtest.mpd.MPDController;
|
||||||
|
|
||||||
public class TheGame implements StatemachineListener, GuiEventListener, IRCEventListener {
|
public class TheGame implements StatemachineListener, GuiEventListener, IRCEventListener {
|
||||||
private IGuiControl guiControl;
|
private final IGuiControl guiControl;
|
||||||
private IIrcClient ircClient;
|
private final IIrcClient ircClient;
|
||||||
private IStatemachine machine;
|
private final IStatemachine machine;
|
||||||
private IBuntiClient bunti;
|
private final IBuntiClient bunti;
|
||||||
private IMPDController mpdController;
|
private final IMPDController mpdController;
|
||||||
private IRelaisboard relaisboard;
|
private final IRelaisboard relaisboard;
|
||||||
private int gamerRating = 3;
|
private int gamerRating = 3;
|
||||||
private Thread discoThread;
|
private Thread discoThread;
|
||||||
private boolean shouldStopDisco;
|
private boolean shouldStopDisco;
|
||||||
private boolean gemActivated = false;
|
private boolean gemActivated = false;
|
||||||
|
|
||||||
public TheGame(IGuiControl guiControl) {
|
public TheGame(IGuiControl guiControl1) {
|
||||||
this.guiControl = guiControl;
|
guiControl = guiControl1;
|
||||||
|
ircClient = new IrcClient("crashtest", "#crashtest","irc.ctdo.de");
|
||||||
this.ircClient = new IrcClient("crashtest", "#crashtest","irc.ctdo.de");
|
bunti = new BuntiClient("bunti.ctdo.de", 8080);
|
||||||
this.bunti = new BuntiClient("bunti.ctdo.de", 8080);
|
mpdController = new MPDController("dampfradio.raum.ctdo.de");
|
||||||
this.mpdController = new MPDController("dampfradio.raum.ctdo.de");
|
relaisboard = new Relaisboard("/dev/ttyUSB0");
|
||||||
this.relaisboard = new Relaisboard("/dev/ttyUSB0");
|
machine = new Statemachine();
|
||||||
this.machine = new Statemachine();
|
|
||||||
|
|
||||||
initGame();
|
initGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +200,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
sayScore();
|
sayScore();
|
||||||
disco();
|
discoStart();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +232,6 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
@Override
|
@Override
|
||||||
public void keyPress(char key) {
|
public void keyPress(char key) {
|
||||||
machine.handleInput(key);
|
machine.handleInput(key);
|
||||||
//guiControl.setExtra("btn: " + key);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -243,10 +239,12 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing() {
|
public void windowClosing() {
|
||||||
machine.reset();
|
discoStop();
|
||||||
|
resetDomotics();
|
||||||
bunti.setPar56(0xff,0xff,0xff);
|
bunti.setPar56(0xff,0xff,0xff);
|
||||||
ircClient.say("bye");
|
ircClient.say("bye");
|
||||||
relaisboard.close();
|
relaisboard.close();
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -272,11 +270,11 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
} else if(message.startsWith("relais")) {
|
} else if(message.startsWith("relais")) {
|
||||||
handleRelaisCommand(message);
|
handleRelaisCommand(message);
|
||||||
} else if(message.startsWith("disco start")) {
|
} else if(message.startsWith("disco start")) {
|
||||||
disco();
|
discoStart();
|
||||||
} else if(message.startsWith("disco stop")) {
|
} else if(message.startsWith("disco stop")) {
|
||||||
discoStop();
|
discoStop();
|
||||||
} else if(message.startsWith("gem")) {
|
} else if(message.startsWith("gem")) {
|
||||||
handleGem();
|
handleGemCommand();
|
||||||
} else {
|
} else {
|
||||||
ircClient.say("y u no use valid command?");
|
ircClient.say("y u no use valid command?");
|
||||||
}
|
}
|
||||||
|
@ -305,7 +303,6 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
} else if(params.startsWith("stop")) {
|
} else if(params.startsWith("stop")) {
|
||||||
machine.stopTimer();
|
machine.stopTimer();
|
||||||
guiControl.showCountDown(false);
|
guiControl.showCountDown(false);
|
||||||
ircClient.say("timer stopped");
|
|
||||||
} else if(params.startsWith("pause")) {
|
} else if(params.startsWith("pause")) {
|
||||||
machine.pauseTimer(true);
|
machine.pauseTimer(true);
|
||||||
} else if(params.startsWith("resume")) {
|
} else if(params.startsWith("resume")) {
|
||||||
|
@ -314,15 +311,14 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleStateCommand(final String message) {
|
private void handleStateCommand(final String message) {
|
||||||
if(message.equals("state")) {
|
if(message.trim().equals("state")) {
|
||||||
ircClient.say(machine.getCurrentState().name());
|
ircClient.say(machine.getCurrentState().name());
|
||||||
} else {
|
} else {
|
||||||
String params = message.substring("state".length()).trim().toLowerCase();
|
String params = message.substring("state".length()).trim().toLowerCase();
|
||||||
|
|
||||||
Boolean ok = false;
|
Boolean ok = false;
|
||||||
for(Statemachine.state st: Statemachine.state.values()) {
|
for(Statemachine.state st: Statemachine.state.values()) {
|
||||||
String stateName = st.name().toLowerCase();
|
if(st.name().toLowerCase().equals(params)) {
|
||||||
if(stateName.equals(params)) {
|
|
||||||
ok = true;
|
ok = true;
|
||||||
machine.setNewState(st);
|
machine.setNewState(st);
|
||||||
break;
|
break;
|
||||||
|
@ -334,7 +330,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yes, it makes no sense, but I want have it anyway. For more Spass am Geraet!
|
// Yes, it makes no sense, but I want have it anyway. For more Spass am Geraet!
|
||||||
private void handleGem() {
|
private void handleGemCommand() {
|
||||||
if (!gemActivated) {
|
if (!gemActivated) {
|
||||||
java.util.Random random = new java.util.Random();
|
java.util.Random random = new java.util.Random();
|
||||||
int scry = random.nextInt(100);
|
int scry = random.nextInt(100);
|
||||||
|
@ -352,7 +348,6 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleRelaisCommand(final String message) {
|
private void handleRelaisCommand(final String message) {
|
||||||
|
|
||||||
String params = message.substring("relais".length()).trim().toLowerCase();
|
String params = message.substring("relais".length()).trim().toLowerCase();
|
||||||
|
|
||||||
if(params.startsWith("lamp on")) {
|
if(params.startsWith("lamp on")) {
|
||||||
|
@ -370,13 +365,11 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
} else if(params.startsWith("lamp stop")) {
|
} else if(params.startsWith("lamp stop")) {
|
||||||
relaisboard.blinkRelaisStop(2);
|
relaisboard.blinkRelaisStop(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleHelpCommand(final String message) {
|
private void handleHelpCommand(final String message) {
|
||||||
if(message.equals("help")) {
|
if(message.equals("help")) {
|
||||||
ircClient.say("commands: help, reset, state, timer, wall, extra, score");
|
ircClient.say("commands: help, reset, state, timer, wall, extra, score, relais, disco");
|
||||||
} else if(message.contains("reset")) {
|
} else if(message.contains("reset")) {
|
||||||
ircClient.say("resets the game to IDLE");
|
ircClient.say("resets the game to IDLE");
|
||||||
} else if(message.contains("state")) {
|
} else if(message.contains("state")) {
|
||||||
|
@ -413,7 +406,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
ircClient.say("control the relais board");
|
ircClient.say("control the relais board");
|
||||||
ircClient.say("valid commands: lamp on, lamp off, lamp blink, lamp stop, oven on, oven off, rokets");
|
ircClient.say("valid commands: lamp on, lamp off, lamp blink, lamp stop, oven on, oven off, rokets");
|
||||||
} else if(message.contains("disco")) {
|
} else if(message.contains("disco")) {
|
||||||
ircClient.say("party! use: disco {on,off}");
|
ircClient.say("party! use: disco {start,stop}");
|
||||||
} else if(message.contains("gem")) {
|
} else if(message.contains("gem")) {
|
||||||
ircClient.say("you don't say?");
|
ircClient.say("you don't say?");
|
||||||
} else {
|
} else {
|
||||||
|
@ -424,38 +417,39 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
private void sayScore() {
|
private void sayScore() {
|
||||||
ircClient.say("stateChangeCounter: " + machine.getStateChangeCounter());
|
ircClient.say("stateChangeCounter: " + machine.getStateChangeCounter());
|
||||||
|
|
||||||
int seconds = machine.getTimerSecondsLast();
|
int secondsLast = machine.getTimerSecondsLast();
|
||||||
int seconds1 = machine.getTimerSeconds();
|
int seconds = machine.getTimerSeconds();
|
||||||
int seconds2 = seconds-seconds1;
|
int secondsLeft = seconds - secondsLast;
|
||||||
|
|
||||||
int mins = seconds / 60;
|
int mins = seconds / 60;
|
||||||
int secs = seconds % 60;
|
int minsLast = secondsLast / 60;
|
||||||
int mins1 = seconds1 / 60;
|
int minsLeft = secondsLeft / 60;
|
||||||
int secs1 = seconds1 % 60;
|
|
||||||
int mins2 = seconds2 / 60;
|
ircClient.say(String.format("time: %d:%02d last: %d:%02d left: %d:%02d",
|
||||||
int secs2 = seconds2 % 60;
|
mins, seconds % 60, minsLast, secondsLast % 60, minsLeft, secondsLeft % 60));
|
||||||
ircClient.say("time " + mins1 + ":" + secs1 + " last: " + mins + ":" + secs + " left: " + mins2 + ":" + secs2);
|
|
||||||
ircClient.say("gamerRating: " + gamerRating);
|
ircClient.say("gamerRating: " + gamerRating);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetDomotics() {
|
private void resetDomotics() {
|
||||||
relaisboard.toggleRelais(2, 2000);
|
|
||||||
relaisboard.setRelais(7, true); // enable light barrier over relais
|
relaisboard.setRelais(7, true); // enable light barrier over relais
|
||||||
relaisboard.setRelais(6, true); // enable third green circle
|
relaisboard.setRelais(6, true); // enable third green circle
|
||||||
|
relaisboard.setRelais(2, false); // disable the lamp
|
||||||
|
relaisboard.setRelais(3, false); // disable the oven
|
||||||
mpdController.clearPlaylist();
|
mpdController.clearPlaylist();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void discoStop() {
|
private void discoStop() {
|
||||||
if(discoThread != null) {
|
if(discoThread != null) {
|
||||||
shouldStopDisco = true;
|
shouldStopDisco = true;
|
||||||
discoThread.interrupt();
|
discoThread.interrupt();
|
||||||
try {
|
try {
|
||||||
discoThread.join(500);
|
discoThread.join(500);
|
||||||
} catch (InterruptedException e) { }
|
} catch (InterruptedException ignored) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disco() {
|
private void discoStart() {
|
||||||
discoStop();
|
discoStop();
|
||||||
|
|
||||||
Runnable r = new Runnable() {
|
Runnable r = new Runnable() {
|
||||||
|
@ -489,14 +483,13 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
if(shouldStopDisco) return;
|
if(shouldStopDisco) return;
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) { }
|
} catch (InterruptedException ignored) { }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
discoThread = new Thread(r);
|
discoThread = new Thread(r);
|
||||||
shouldStopDisco = false;
|
shouldStopDisco = false;
|
||||||
discoThread.start();
|
discoThread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
package de.ctdo.crashtest.gui;
|
package de.ctdo.crashtest.gui;
|
||||||
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: lucas
|
|
||||||
* @date: 01.06.12 10:29
|
|
||||||
*/
|
|
||||||
public interface GuiEventListener {
|
public interface GuiEventListener {
|
||||||
|
|
||||||
void keyPress(final char key);
|
void keyPress(final char key);
|
||||||
void windowClosing();
|
void windowClosing();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,9 @@
|
||||||
package de.ctdo.crashtest.gui;
|
package de.ctdo.crashtest.gui;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: lucas
|
|
||||||
* @date: 01.06.12 10:13
|
|
||||||
*/
|
|
||||||
public interface IGuiControl {
|
public interface IGuiControl {
|
||||||
|
|
||||||
void setWall(final String message);
|
void setWall(final String message);
|
||||||
void setExtra(final String text);
|
void setExtra(final String text);
|
||||||
void setCountDown(final int tseconds);
|
void setCountDown(final int tseconds);
|
||||||
void showCountDown(final Boolean show);
|
void showCountDown(final Boolean show);
|
||||||
|
|
||||||
void addListener(final GuiEventListener listener);
|
void addListener(final GuiEventListener listener);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,11 @@ public class MainGui extends JFrame implements IGuiControl {
|
||||||
private final JLabel countDown = new JLabel();
|
private final JLabel countDown = new JLabel();
|
||||||
private final JLabel extraField = new JLabel();
|
private final JLabel extraField = new JLabel();
|
||||||
private final JPanel lowerPanel = new JPanel();
|
private final JPanel lowerPanel = new JPanel();
|
||||||
|
|
||||||
private final List<GuiEventListener> listenerList = new ArrayList<GuiEventListener>();
|
private final List<GuiEventListener> listenerList = new ArrayList<GuiEventListener>();
|
||||||
|
|
||||||
public MainGui() {
|
public MainGui() {
|
||||||
initGui();
|
initGui();
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
|
||||||
setBounds(0,0, 1280, 1024);
|
|
||||||
setExtendedState(Frame.MAXIMIZED_BOTH);
|
setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||||
setUndecorated(true);
|
setUndecorated(true);
|
||||||
|
|
||||||
|
@ -33,7 +30,7 @@ public class MainGui extends JFrame implements IGuiControl {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addWindowStateListener(new WindowAdapter() {
|
addWindowListener(new WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
for(GuiEventListener listener: listenerList) {
|
for(GuiEventListener listener: listenerList) {
|
||||||
|
@ -46,18 +43,14 @@ public class MainGui extends JFrame implements IGuiControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCountDownText(final int tseconds) {
|
private void setCountDownText(final int tseconds) {
|
||||||
int mins = tseconds / 600;
|
|
||||||
int secs = tseconds % 600 / 10 ;
|
countDown.setText(String.format(" %d:%02d.%1d", tseconds / 600, tseconds % 600 / 10, tseconds % 9));
|
||||||
int tsecs = tseconds % 9;
|
|
||||||
countDown.setText(" " + mins + ":" + secs + "." + tsecs);
|
|
||||||
|
|
||||||
if(tseconds < 400) {
|
if(tseconds < 400) {
|
||||||
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;
|
||||||
|
|
||||||
// System.out.println("red= " + red + " green=" + green + " blue="+blue);
|
|
||||||
|
|
||||||
if(red > 255) red = 255;
|
if(red > 255) red = 255;
|
||||||
if(red < 0) red = 0;
|
if(red < 0) red = 0;
|
||||||
if(green > 255) green = 255;
|
if(green > 255) green = 255;
|
||||||
|
@ -69,7 +62,6 @@ public class MainGui extends JFrame implements IGuiControl {
|
||||||
else {
|
else {
|
||||||
countDown.setForeground(new Color(42, 190, 0));
|
countDown.setForeground(new Color(42, 190, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initGui() {
|
private void initGui() {
|
||||||
|
@ -161,6 +153,4 @@ public class MainGui extends JFrame implements IGuiControl {
|
||||||
listenerList.add(listener);
|
listenerList.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package de.ctdo.crashtest.irc;
|
package de.ctdo.crashtest.irc;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: lucas
|
|
||||||
* @date: 01.06.12 10:05
|
|
||||||
*/
|
|
||||||
public interface IIrcClient {
|
public interface IIrcClient {
|
||||||
void say(String message);
|
void say(String message);
|
||||||
void addListener(IRCEventListener listenerIRC);
|
void addListener(IRCEventListener listenerIRC);
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package de.ctdo.crashtest.irc;
|
package de.ctdo.crashtest.irc;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: lucas
|
|
||||||
* @date: 01.06.12 11:49
|
|
||||||
*/
|
|
||||||
public interface IRCEventListener {
|
public interface IRCEventListener {
|
||||||
|
|
||||||
void handleMessage(final String message);
|
void handleMessage(final String message);
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class IrcClient implements IIrcClient, jerklib.events.listeners.IRCEventListener, ILogger {
|
public class IrcClient implements IIrcClient, jerklib.events.listeners.IRCEventListener, ILogger {
|
||||||
private final List<IRCEventListener> listenerListIRC = new ArrayList<IRCEventListener>();
|
private final List<IRCEventListener> listenerListIRC = new ArrayList<IRCEventListener>();
|
||||||
private Session ircsession;
|
private final Session ircsession;
|
||||||
private final String channel;
|
private final String channel;
|
||||||
|
|
||||||
public IrcClient(String nick, String channel, String server) {
|
public IrcClient(String nick, String channel, String server) {
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package de.ctdo.crashtest.log;
|
package de.ctdo.crashtest.log;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: lucas
|
|
||||||
* @date: 01.06.12 16:46
|
|
||||||
*/
|
|
||||||
public interface ILogger {
|
public interface ILogger {
|
||||||
|
|
||||||
void log(String message);
|
void log(String message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class Logger {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(String message) {
|
private void log(String message) {
|
||||||
|
|
||||||
System.out.println("LOG: " + message);
|
System.out.println("LOG: " + message);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package de.ctdo.crashtest.mpd;
|
package de.ctdo.crashtest.mpd;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: lucas
|
|
||||||
* @date: 01.06.12 10:36
|
|
||||||
*/
|
|
||||||
public interface IMPDController {
|
public interface IMPDController {
|
||||||
void playSong(final String artist, final String title);
|
void playSong(final String artist, final String title);
|
||||||
void setVolume(final int volume);
|
void setVolume(final int volume);
|
||||||
|
|
Loading…
Reference in New Issue