made disco loop forever and controlable via irc

This commit is contained in:
Lucas Pleß 2012-06-13 23:31:12 +02:00
parent e97ae350ad
commit 9b8791a468
1 changed files with 34 additions and 8 deletions

View File

@ -14,6 +14,8 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
private IMPDController mpdController; private IMPDController mpdController;
private IRelaisboard relaisboard; private IRelaisboard relaisboard;
private int gamerRating = 3; private int gamerRating = 3;
private Thread discoThread;
private boolean shouldStopDisco;
public TheGame(IGuiControl guiControl) { public TheGame(IGuiControl guiControl) {
this.guiControl = guiControl; this.guiControl = guiControl;
@ -39,7 +41,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
private void rate(int rating, String text) { private void rate(int rating, String text) {
gamerRating += rating; gamerRating += rating;
ircClient.say("rated: " + rating + " (" + gamerRating + ") " + text ); ircClient.say("rated: " + rating + " (" + gamerRating + ") " + text);
if(gamerRating > 5) gamerRating = 5; if(gamerRating > 5) gamerRating = 5;
if(gamerRating < 1) gamerRating = 1; if(gamerRating < 1) gamerRating = 1;
} }
@ -51,10 +53,11 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
@Override @Override
public void stateChanged(Statemachine.state newState) { public void stateChanged(Statemachine.state newState) {
ircClient.say("New State: " + newState); ircClient.say("New State: " + newState);
switch (newState) { switch (newState) {
case NEUTRAL: case NEUTRAL:
discoStop();
bunti.setPar56(255,255,255); bunti.setPar56(255,255,255);
bunti.setLampel(false,false,false); bunti.setLampel(false,false,false);
machine.stopTimer(); machine.stopTimer();
@ -64,6 +67,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
gamerRating = 3; gamerRating = 3;
machine.stopTimer(); machine.stopTimer();
resetDomotics(); resetDomotics();
discoStop();
guiControl.setExtra(""); guiControl.setExtra("");
guiControl.setWall(""); guiControl.setWall("");
@ -266,6 +270,10 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
guiControl.setExtra(message.substring("extra".length()).trim()); guiControl.setExtra(message.substring("extra".length()).trim());
} else if(message.startsWith("relais")) { } else if(message.startsWith("relais")) {
handleRelaisCommand(message); handleRelaisCommand(message);
} else if(message.startsWith("disco start")) {
disco();
} else if(message.startsWith("disco stop")) {
discoStop();
} else { } else {
ircClient.say("y u no use valid command?"); ircClient.say("y u no use valid command?");
} }
@ -383,6 +391,8 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
} else if(message.contains("relais")) { } else if(message.contains("relais")) {
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")) {
ircClient.say("party! use: disco {on,off}");
} else { } else {
ircClient.say("dafuq?"); ircClient.say("dafuq?");
} }
@ -411,42 +421,58 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
mpdController.clearPlaylist(); mpdController.clearPlaylist();
} }
private void discoStop() {
if(discoThread != null) {
shouldStopDisco = true;
discoThread.interrupt();
try {
discoThread.join(500);
} catch (InterruptedException e) { }
}
}
private void disco() { private void disco() {
discoStop();
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
for(int i = 0; i < 10; i++) { while(true) {
if(shouldStopDisco) return;
bunti.setPar56(0, 255, 0, 0); bunti.setPar56(0, 255, 0, 0);
bunti.setPar56(1, 0, 255, 0); bunti.setPar56(1, 0, 255, 0);
bunti.setPar56(2, 0, 255, 0); bunti.setPar56(2, 0, 255, 0);
bunti.setPar56(3, 255, 0, 0); bunti.setPar56(3, 255, 0, 0);
if(shouldStopDisco) return;
Thread.sleep(500); Thread.sleep(500);
bunti.setPar56(0, 0, 0, 255); bunti.setPar56(0, 0, 0, 255);
bunti.setPar56(1, 255, 255, 0); bunti.setPar56(1, 255, 255, 0);
bunti.setPar56(2, 255, 255, 0); bunti.setPar56(2, 255, 255, 0);
bunti.setPar56(3, 0, 0, 255); bunti.setPar56(3, 0, 0, 255);
if(shouldStopDisco) return;
Thread.sleep(500); Thread.sleep(500);
bunti.setPar56(0, 255, 128, 0); bunti.setPar56(0, 255, 128, 0);
bunti.setPar56(1, 0, 255, 255); bunti.setPar56(1, 0, 255, 255);
bunti.setPar56(2, 0, 255, 255); bunti.setPar56(2, 0, 255, 255);
bunti.setPar56(3, 255, 128, 0); bunti.setPar56(3, 255, 128, 0);
if(shouldStopDisco) return;
Thread.sleep(500); Thread.sleep(500);
bunti.setPar56(0, 0, 255, 255); bunti.setPar56(0, 0, 255, 255);
bunti.setPar56(1, 0, 255, 0); bunti.setPar56(1, 0, 255, 0);
bunti.setPar56(2, 0, 255, 0); bunti.setPar56(2, 0, 255, 0);
bunti.setPar56(3, 0, 255, 255); bunti.setPar56(3, 0, 255, 255);
if(shouldStopDisco) return;
Thread.sleep(500); Thread.sleep(500);
} }
} catch (InterruptedException e) { } catch (InterruptedException e) { }
e.printStackTrace();
}
} }
}; };
new Thread(r).start(); discoThread = new Thread(r);
shouldStopDisco = false;
discoThread.start();
} }