- added extra state to table game
- added jingle player via pulseaudio
This commit is contained in:
parent
0765e1c017
commit
1b69470d9c
|
@ -0,0 +1,45 @@
|
|||
package de.ctdo.crashtest.domotics;
|
||||
|
||||
import de.ctdo.crashtest.log.Logger;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class ExtraSoundControl implements IExtraSoundControl {
|
||||
|
||||
|
||||
@Override
|
||||
public void playJingle(final String name) {
|
||||
|
||||
System.out.println("ExtraSoundControl: playJingle name=" + name );
|
||||
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
HttpClient client = new DefaultHttpClient();
|
||||
HttpGet get = new HttpGet("http://dampfradio.raum.ctdo.de/controller.php?command=jingle&mpd=mpd1&arg=" +name);
|
||||
|
||||
|
||||
client.execute(get);
|
||||
get.abort();
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Logger.sLog("ExtraSoundControl error: " + e.getMessage());
|
||||
} catch (ClientProtocolException e) {
|
||||
Logger.sLog("ExtraSoundControl error: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Logger.sLog("ExtraSoundControl error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
new Thread(r).start();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package de.ctdo.crashtest.domotics;
|
||||
|
||||
public interface IExtraSoundControl {
|
||||
void playJingle(String name);
|
||||
}
|
|
@ -15,10 +15,14 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
private final IBuntiClient bunti;
|
||||
private final IMPDController mpdController;
|
||||
private final IRelaisboard relaisboard;
|
||||
private final IExtraSoundControl extraSoundControl;
|
||||
private int gamerRating = 3;
|
||||
private Thread discoThread;
|
||||
private boolean shouldStopDisco;
|
||||
private boolean gemActivated = false;
|
||||
private boolean startedHurrySound = false;
|
||||
private char lastInput;
|
||||
private boolean sproing;
|
||||
|
||||
public TheGame(IGuiControl guiControl1) {
|
||||
guiControl = guiControl1;
|
||||
|
@ -27,7 +31,15 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
mpdController = new MPDController("dampfradio.raum.ctdo.de");
|
||||
relaisboard = new Relaisboard("/dev/ttyUSB0");
|
||||
machine = new Statemachine();
|
||||
initGame();
|
||||
extraSoundControl = new ExtraSoundControl();
|
||||
|
||||
guiControl.addListener(this);
|
||||
ircClient.addListener(this);
|
||||
machine.addListener(this);
|
||||
|
||||
machine.reset();
|
||||
relaisboard.open();
|
||||
resetDomotics();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,18 +61,19 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
break;
|
||||
case IDLE:
|
||||
gamerRating = 3;
|
||||
machine.stopTimer();
|
||||
resetDomotics();
|
||||
mpdController.clearPlaylist();
|
||||
machine.stopTimer();
|
||||
startedHurrySound = false;
|
||||
|
||||
resetDomotics();
|
||||
discoStop();
|
||||
|
||||
guiControl.setExtra("");
|
||||
guiControl.setWall("");
|
||||
guiControl.showCountDown(false);
|
||||
|
||||
playRandomStartMix();
|
||||
mpdController.setVolume(50);
|
||||
|
||||
guiControl.showCountDown(false);
|
||||
//mpdController.setVolume(50);
|
||||
break;
|
||||
case ENTERED_ROOM:
|
||||
relaisboard.setRelais(7, false); // disable light barrier over relais
|
||||
|
@ -73,18 +86,28 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
guiControl.showCountDown(true);
|
||||
|
||||
machine.startTimer(60*8);
|
||||
mpdController.setVolume(50);
|
||||
break;
|
||||
case TABLE_GAME_WRONG:
|
||||
extraSoundControl.playJingle("block");
|
||||
mpdController.playSong("crashtest", "table_game_one");
|
||||
bunti.setLampel(true,false,false);
|
||||
sproing = true;
|
||||
break;
|
||||
case TABLE_GAME_ONE:
|
||||
relaisboard.setRelais(6, true); // enable third green circle
|
||||
|
||||
mpdController.playSong("crashtest", "table_game_one");
|
||||
extraSoundControl.playJingle("jump");
|
||||
//mpdController.playSong("crashtest", "table_game_one");
|
||||
|
||||
bunti.setLampel(true,false,false);
|
||||
bunti.setLampel(false, true, false);
|
||||
bunti.setPar56(20,0,100);
|
||||
guiControl.showCountDown(true);
|
||||
break;
|
||||
case TABLE_GAME_TWO:
|
||||
mpdController.playSong("crashtest", "table_game_two");
|
||||
//mpdController.playSong("crashtest", "table_game_two");
|
||||
|
||||
extraSoundControl.playJingle("jump");
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(100,0,100);
|
||||
|
@ -92,7 +115,9 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
guiControl.showCountDown(true);
|
||||
break;
|
||||
case TABLE_GAME_THREE:
|
||||
mpdController.playSong("crashtest", "table_game_three");
|
||||
//mpdController.playSong("crashtest", "table_game_three");
|
||||
|
||||
extraSoundControl.playJingle("jump");
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(255,35,0);
|
||||
|
@ -102,13 +127,17 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
case TABLE_GAME_FOUR:
|
||||
mpdController.playSong("crashtest", "table_game_four");
|
||||
|
||||
extraSoundControl.playJingle("jump");
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(200,100,0);
|
||||
|
||||
guiControl.showCountDown(true);
|
||||
break;
|
||||
case TABLE_GAME_FIVE:
|
||||
mpdController.playSong("crashtest", "table_game_five");
|
||||
//mpdController.playSong("crashtest", "table_game_five");
|
||||
|
||||
extraSoundControl.playJingle("jump");
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(150,150,0);
|
||||
|
@ -116,7 +145,9 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
guiControl.showCountDown(true);
|
||||
break;
|
||||
case TABLE_GAME_SIX:
|
||||
mpdController.playSong("crashtest", "table_game_six");
|
||||
//mpdController.playSong("crashtest", "table_game_six");
|
||||
|
||||
extraSoundControl.playJingle("jump");
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(100,200,0);
|
||||
|
@ -126,6 +157,8 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
case TABLE_GAME_DONE:
|
||||
mpdController.playSong("crashtest", "table_game_done");
|
||||
|
||||
extraSoundControl.playJingle("jump");
|
||||
|
||||
bunti.setLampel(false,false,true);
|
||||
bunti.setPar56(100,255,0);
|
||||
|
||||
|
@ -153,6 +186,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
mpdController.playSong("crashtest", "roket_started");
|
||||
mpdController.addToPlayList("crashtest", "roket_started2");
|
||||
|
||||
startedHurrySound = false;
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(0, 255, 0);
|
||||
|
||||
|
@ -188,7 +222,6 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
discoStart();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -200,12 +233,43 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
guiControl.setCountDown(tsecondsLeft);
|
||||
if(tsecondsLeft == 0) {
|
||||
ircClient.say("timer expired");
|
||||
Statemachine.state bla = machine.getCurrentState();
|
||||
Statemachine.state state = machine.getCurrentState();
|
||||
|
||||
if( state == Statemachine.state.TABLE_GAME_ONE || state == Statemachine.state.TABLE_GAME_TWO ||
|
||||
state == Statemachine.state.TABLE_GAME_THREE || state == Statemachine.state.TABLE_GAME_FOUR ||
|
||||
state == Statemachine.state.TABLE_GAME_FIVE || state == Statemachine.state.TABLE_GAME_SIX ||
|
||||
state == Statemachine.state.TABLE_GAME_WRONG || state == Statemachine.state.ROKET_STARTED ) {
|
||||
|
||||
if( bla != Statemachine.state.TABLE_GAME_DONE &&
|
||||
bla != Statemachine.state.ROKET_DONE ) {
|
||||
rate(-2, "game not done in time");
|
||||
guiControl.setWall("die Zeit ist abgelaufen");
|
||||
sayScore();
|
||||
|
||||
mpdController.playSong("crashtest","timeouted");
|
||||
|
||||
if(state == Statemachine.state.ROKET_STARTED) {
|
||||
ircClient.say("if ready, use >reset");
|
||||
} else {
|
||||
ircClient.say("if ready, set state with >state TABLE_GAME_DONE");
|
||||
}
|
||||
|
||||
/*
|
||||
if(state != Statemachine.state.ROKET_STARTED) {
|
||||
ircClient.say("switching to roket started");
|
||||
machine.setNewState(Statemachine.state.ROKET_STARTED);
|
||||
} */
|
||||
}
|
||||
} else {
|
||||
if(tsecondsLeft % 600 == 0) {
|
||||
sayScore();
|
||||
}
|
||||
|
||||
if(tsecondsLeft <= 627 && !startedHurrySound) {
|
||||
Statemachine.state state = machine.getCurrentState();
|
||||
if( state != Statemachine.state.TABLE_GAME_DONE &&
|
||||
state != Statemachine.state.ROKET_DONE ) {
|
||||
startedHurrySound = true;
|
||||
mpdController.playSong("crashtest", "hurry");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -217,6 +281,24 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
@Override
|
||||
public void keyPress(char key) {
|
||||
machine.handleInput(key);
|
||||
|
||||
Statemachine.state state = machine.getCurrentState();
|
||||
|
||||
if(state == Statemachine.state.ENTERED_ROOM) {
|
||||
if(key == Statemachine.TABLE_TWO || key == Statemachine.TABLE_THREE) {
|
||||
if(lastInput != key) {
|
||||
extraSoundControl.playJingle("block");
|
||||
}
|
||||
}
|
||||
} else if(state == Statemachine.state.TABLE_GAME_WRONG) {
|
||||
if(key == Statemachine.TABLE_ONE || key == Statemachine.TABLE_TWO || key == Statemachine.TABLE_THREE) {
|
||||
if(lastInput != key && !sproing) {
|
||||
extraSoundControl.playJingle("block");
|
||||
}
|
||||
sproing = false;
|
||||
}
|
||||
}
|
||||
lastInput = key;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -247,9 +329,6 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
handleHelpCommand(message);
|
||||
} else if(message.equals("reset")) {
|
||||
machine.reset();
|
||||
mpdController.clearPlaylist();
|
||||
playRandomStartMix();
|
||||
resetDomotics();
|
||||
} else if(message.startsWith("state")) {
|
||||
handleStateCommand(message);
|
||||
} else if(message.startsWith("timer")) {
|
||||
|
@ -273,16 +352,6 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
}
|
||||
}
|
||||
|
||||
private void initGame() {
|
||||
guiControl.addListener(this);
|
||||
ircClient.addListener(this);
|
||||
machine.addListener(this);
|
||||
|
||||
machine.reset();
|
||||
relaisboard.open();
|
||||
resetDomotics();
|
||||
}
|
||||
|
||||
private void rate(int rating, String text) {
|
||||
gamerRating += rating;
|
||||
ircClient.say("rated: " + rating + " (" + gamerRating + ") " + text);
|
||||
|
@ -425,7 +494,12 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
}
|
||||
|
||||
private void sayScore() {
|
||||
ircClient.say("stateChangeCounter: " + machine.getStateChangeCounter());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("stateChangeCounter: ");
|
||||
sb.append(machine.getStateChangeCounter());
|
||||
|
||||
sb.append(" gamerRating: ");
|
||||
sb.append(gamerRating);
|
||||
|
||||
int secondsLeft = machine.getTimerSecondsLeft();
|
||||
int seconds = machine.getTimerSeconds();
|
||||
|
@ -435,10 +509,10 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
int minsUsed = secondsUsed / 60;
|
||||
int minsLeft = secondsLeft / 60;
|
||||
|
||||
ircClient.say(String.format("time: %d:%02d used: %d:%02d left: %d:%02d",
|
||||
sb.append(String.format(" time: %d:%02d used: %d:%02d left: %d:%02d",
|
||||
mins, seconds % 60, minsUsed, secondsUsed % 60, minsLeft, secondsLeft % 60));
|
||||
|
||||
ircClient.say("gamerRating: " + gamerRating);
|
||||
ircClient.say(sb.toString());
|
||||
}
|
||||
|
||||
private void resetDomotics() {
|
||||
|
@ -473,24 +547,28 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
bunti.setPar56(1, 0, 255, 0);
|
||||
bunti.setPar56(2, 0, 255, 0);
|
||||
bunti.setPar56(3, 255, 0, 0);
|
||||
bunti.setLampel(true, false, false);
|
||||
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);
|
||||
bunti.setLampel(false, true, false);
|
||||
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);
|
||||
bunti.setLampel(false, false, true);
|
||||
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);
|
||||
bunti.setLampel(true, true, true);
|
||||
if(shouldStopDisco) return;
|
||||
Thread.sleep(500);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue