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