minor fixes
This commit is contained in:
parent
60b0ff6ea9
commit
3fead845ac
|
@ -23,7 +23,6 @@ public class Statemachine implements IStatemachine {
|
|||
NEUTRAL
|
||||
}
|
||||
|
||||
private final char RESET = '1';
|
||||
private final char BLUE_BUTTON = 'E';
|
||||
private final char LIGHT_BARRIER = 'F';
|
||||
private final char TABLE_ONE = 'G';
|
||||
|
@ -147,71 +146,66 @@ public class Statemachine implements IStatemachine {
|
|||
private state getNewState(char input) {
|
||||
state retVal = currentState;
|
||||
|
||||
if(input == RESET) {
|
||||
retVal = state.IDLE;
|
||||
} else {
|
||||
|
||||
switch (currentState) {
|
||||
case IDLE:
|
||||
if(input == LIGHT_BARRIER) {
|
||||
retVal = state.ENTERED_ROOM;
|
||||
}
|
||||
break;
|
||||
case ENTERED_ROOM:
|
||||
if(input == TABLE_ONE) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_ONE:
|
||||
if(input == TABLE_TWO) {
|
||||
retVal = state.TABLE_GAME_TWO;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_TWO:
|
||||
if(input == TABLE_THREE) {
|
||||
retVal = state.TABLE_GAME_THREE;
|
||||
} else if (input == TABLE_ONE) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_THREE:
|
||||
if(input == TABLE_TWO) {
|
||||
retVal = state.TABLE_GAME_FOUR;
|
||||
} else if (input == TABLE_ONE) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_FOUR:
|
||||
if(input == TABLE_THREE) {
|
||||
retVal = state.TABLE_GAME_FIVE;
|
||||
} else if (input == TABLE_ONE) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_FIVE:
|
||||
if(input == TABLE_ONE) {
|
||||
retVal = state.TABLE_GAME_SIX;
|
||||
} else if (input == TABLE_TWO) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_SIX:
|
||||
if(input == TABLE_THREE) {
|
||||
retVal = state.TABLE_GAME_DONE;
|
||||
} else if (input == TABLE_TWO) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_DONE:
|
||||
if(input == BLUE_BUTTON) {
|
||||
retVal = state.ROKET_STARTED;
|
||||
}
|
||||
break;
|
||||
case ROKET_STARTED:
|
||||
if(input == ROKET_INPUT) {
|
||||
retVal = state.ROKET_DONE;
|
||||
}
|
||||
}
|
||||
switch (currentState) {
|
||||
case IDLE:
|
||||
if(input == LIGHT_BARRIER) {
|
||||
retVal = state.ENTERED_ROOM;
|
||||
}
|
||||
break;
|
||||
case ENTERED_ROOM:
|
||||
if(input == TABLE_ONE) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_ONE:
|
||||
if(input == TABLE_TWO) {
|
||||
retVal = state.TABLE_GAME_TWO;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_TWO:
|
||||
if(input == TABLE_THREE) {
|
||||
retVal = state.TABLE_GAME_THREE;
|
||||
} else if (input == TABLE_ONE) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_THREE:
|
||||
if(input == TABLE_TWO) {
|
||||
retVal = state.TABLE_GAME_FOUR;
|
||||
} else if (input == TABLE_ONE) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_FOUR:
|
||||
if(input == TABLE_THREE) {
|
||||
retVal = state.TABLE_GAME_FIVE;
|
||||
} else if (input == TABLE_ONE) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_FIVE:
|
||||
if(input == TABLE_ONE) {
|
||||
retVal = state.TABLE_GAME_SIX;
|
||||
} else if (input == TABLE_TWO) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_SIX:
|
||||
if(input == TABLE_THREE) {
|
||||
retVal = state.TABLE_GAME_DONE;
|
||||
} else if (input == TABLE_TWO) {
|
||||
retVal = state.TABLE_GAME_ONE;
|
||||
}
|
||||
break;
|
||||
case TABLE_GAME_DONE:
|
||||
if(input == BLUE_BUTTON) {
|
||||
retVal = state.ROKET_STARTED;
|
||||
}
|
||||
break;
|
||||
case ROKET_STARTED:
|
||||
if(input == ROKET_INPUT) {
|
||||
retVal = state.ROKET_DONE;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
|
|
|
@ -6,6 +6,8 @@ import de.ctdo.crashtest.irc.*;
|
|||
import de.ctdo.crashtest.mpd.IMPDController;
|
||||
import de.ctdo.crashtest.mpd.MPDController;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class TheGame implements StatemachineListener, GuiEventListener, IRCEventListener {
|
||||
private final IGuiControl guiControl;
|
||||
private final IIrcClient ircClient;
|
||||
|
@ -14,7 +16,6 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
private final IMPDController mpdController;
|
||||
private final IRelaisboard relaisboard;
|
||||
private int gamerRating = 3;
|
||||
private long lastHandleWall;
|
||||
private Thread discoThread;
|
||||
private boolean shouldStopDisco;
|
||||
private boolean gemActivated = false;
|
||||
|
@ -50,21 +51,21 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
gamerRating = 3;
|
||||
machine.stopTimer();
|
||||
resetDomotics();
|
||||
mpdController.clearPlaylist();
|
||||
discoStop();
|
||||
|
||||
guiControl.setExtra("");
|
||||
guiControl.setWall("");
|
||||
|
||||
playRandomStartMix();
|
||||
mpdController.setVolume(50);
|
||||
mpdController.playSong("start", "mix");
|
||||
|
||||
guiControl.showCountDown(false);
|
||||
break;
|
||||
case ENTERED_ROOM:
|
||||
relaisboard.setRelais(7, false); // disable light barrier over relais
|
||||
mpdController.playSong("crashtest", "entered_room");
|
||||
mpdController.setVolume(70);
|
||||
mpdController.playSong("tidirium", "welcome");
|
||||
|
||||
|
||||
bunti.setLampel(false,false,false);
|
||||
bunti.setPar56(20,0,100);
|
||||
|
@ -75,31 +76,35 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
break;
|
||||
case TABLE_GAME_ONE:
|
||||
relaisboard.setRelais(6, true); // enable third green circle
|
||||
//guiControl.setWall("64K RAM SYSTEM 38911 BASIC BYTES FREE. **** COMMODORE 64 BASIC V2 ****");
|
||||
|
||||
mpdController.playSong("crashtest", "table_game_one");
|
||||
mpdController.setVolume(70);
|
||||
mpdController.playSong("K2", "Der Berg Ruft");
|
||||
|
||||
bunti.setLampel(true,false,false);
|
||||
bunti.setPar56(20,0,100);
|
||||
guiControl.showCountDown(true);
|
||||
break;
|
||||
case TABLE_GAME_TWO:
|
||||
mpdController.playSong("crashtest", "table_game_two");
|
||||
mpdController.setVolume(67);
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(100,0,100);
|
||||
|
||||
guiControl.showCountDown(true);
|
||||
break;
|
||||
case TABLE_GAME_THREE:
|
||||
mpdController.playSong("crashtest", "table_game_three");
|
||||
mpdController.setVolume(63);
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(255,35,0);
|
||||
|
||||
guiControl.showCountDown(true);
|
||||
break;
|
||||
case TABLE_GAME_FOUR:
|
||||
mpdController.playSong("crashtest", "table_game_four");
|
||||
mpdController.setVolume(60);
|
||||
mpdController.playSong("Mo-Do","9 Eins Zwei Polizei");
|
||||
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(200,100,0);
|
||||
|
@ -107,14 +112,17 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
guiControl.showCountDown(true);
|
||||
break;
|
||||
case TABLE_GAME_FIVE:
|
||||
mpdController.playSong("crashtest", "table_game_five");
|
||||
mpdController.setVolume(57);
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
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.playSong("crashtest", "table_game_six");
|
||||
mpdController.setVolume(53);
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(100,200,0);
|
||||
|
@ -122,6 +130,9 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
guiControl.showCountDown(true);
|
||||
break;
|
||||
case TABLE_GAME_DONE:
|
||||
mpdController.playSong("crashtest", "table_game_done");
|
||||
mpdController.setVolume(50);
|
||||
|
||||
bunti.setLampel(false,false,true);
|
||||
bunti.setPar56(100,255,0);
|
||||
|
||||
|
@ -146,9 +157,9 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
|
||||
break;
|
||||
case ROKET_STARTED:
|
||||
mpdController.playSong("crashtest", "roket_started");
|
||||
mpdController.addToPlayList("crashtest", "roket_started2");
|
||||
mpdController.setVolume(50);
|
||||
mpdController.playSong("The Underdog Project", "Summer Jam");
|
||||
mpdController.addToPlayList("Maximo Park", "Books of Boxes");
|
||||
|
||||
bunti.setLampel(false,true,false);
|
||||
bunti.setPar56(0, 255, 0);
|
||||
|
@ -156,14 +167,15 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
relaisboard.toggleRelais(0, 300); // r0kets toogle
|
||||
relaisboard.toggleRelais(3, 10000); // oven
|
||||
relaisboard.blinkRelaisStop(2); // stop hint button lamp
|
||||
relaisboard.setRelais(2, false);
|
||||
|
||||
guiControl.setWall("Pizza ist fertig!");
|
||||
guiControl.showCountDown(true);
|
||||
machine.startTimer(7*60);
|
||||
break;
|
||||
case ROKET_DONE:
|
||||
mpdController.setVolume(50);
|
||||
mpdController.playSong("CTDO", "finish");
|
||||
mpdController.playSong("crashtest", "roket_done");
|
||||
mpdController.setVolume(60);
|
||||
|
||||
bunti.setLampel(false,false,true);
|
||||
bunti.setPar56(255, 255, 255);
|
||||
|
@ -222,9 +234,14 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
public void windowClosing() {
|
||||
discoStop();
|
||||
resetDomotics();
|
||||
relaisboard.close();
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ignored) { }
|
||||
|
||||
bunti.setPar56(0xff,0xff,0xff);
|
||||
ircClient.say("bye");
|
||||
relaisboard.close();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
@ -238,6 +255,9 @@ 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")) {
|
||||
|
@ -245,7 +265,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
} else if(message.startsWith("score")) {
|
||||
sayScore();
|
||||
} else if(message.startsWith("wall")) {
|
||||
handleWallCommand(message);
|
||||
guiControl.setWall(message.substring("wall".length()).trim());
|
||||
} else if(message.startsWith("extra")) {
|
||||
guiControl.setExtra(message.substring("extra".length()).trim());
|
||||
} else if(message.startsWith("relais")) {
|
||||
|
@ -278,17 +298,6 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
if(gamerRating < 1) gamerRating = 1;
|
||||
}
|
||||
|
||||
private void handleWallCommand(final String message) {
|
||||
if(System.currentTimeMillis() - lastHandleWall < 7000 ) {
|
||||
ircClient.say("not enough mana!");
|
||||
return;
|
||||
}
|
||||
|
||||
guiControl.setWall(message.substring("wall".length()).trim());
|
||||
|
||||
lastHandleWall = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private void handleTimerCommand(final String message) {
|
||||
String params = message.substring("timer".length()).trim().toLowerCase();
|
||||
|
||||
|
@ -445,9 +454,8 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
relaisboard.setRelais(6, true); // enable third green circle
|
||||
relaisboard.setRelais(2, false); // disable the lamp
|
||||
relaisboard.setRelais(3, false); // disable the oven
|
||||
bunti.setPar56(0,0,0);
|
||||
bunti.setLampel(false,false,false);
|
||||
mpdController.clearPlaylist();
|
||||
bunti.setPar56(0, 0, 0);
|
||||
bunti.setLampel(false, false, false);
|
||||
}
|
||||
|
||||
private void discoStop() {
|
||||
|
@ -503,4 +511,20 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
|||
discoThread.start();
|
||||
}
|
||||
|
||||
private void playRandomStartMix() {
|
||||
Random r = new Random();
|
||||
int num = r.nextInt(3)+1;
|
||||
if(num == 1) {
|
||||
mpdController.playSong("crashtest", "idle");
|
||||
} else if(num == 2) {
|
||||
mpdController.playSong("crashtest", "idle2");
|
||||
} else if(num == 3) {
|
||||
mpdController.playSong("crashtest", "idle3");
|
||||
} else if(num == 4) {
|
||||
mpdController.playSong("crashtest", "idle4");
|
||||
}
|
||||
|
||||
mpdController.skipRandomStart();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,4 +5,5 @@ public interface IMPDController {
|
|||
void setVolume(final int volume);
|
||||
void clearPlaylist();
|
||||
void addToPlayList(final String artist, final String title);
|
||||
void skipRandomStart();
|
||||
}
|
||||
|
|
|
@ -14,13 +14,13 @@ import org.bff.javampd.objects.MPDSong;
|
|||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* A MPD abstraction to the org.bff.javampd library
|
||||
*/
|
||||
public class MPDController implements IMPDController {
|
||||
private MPD mpd;
|
||||
private final Object lockObject = new Object();
|
||||
|
||||
public MPDController(String host) {
|
||||
try {
|
||||
|
@ -40,6 +40,7 @@ public class MPDController implements IMPDController {
|
|||
*/
|
||||
@Override
|
||||
public void playSong(final String artist, final String title) {
|
||||
System.out.println("playSong: " + artist + " - " + title);
|
||||
if(mpd != null) {
|
||||
|
||||
addToPlayListIfNeeded(artist, title);
|
||||
|
@ -101,6 +102,27 @@ public class MPDController implements IMPDController {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skipRandomStart() {
|
||||
if(mpd != null) {
|
||||
MPDPlayer player = mpd.getMPDPlayer();
|
||||
|
||||
try {
|
||||
int length;
|
||||
MPDSong song = player.getCurrentSong();
|
||||
if(song!= null) {
|
||||
length = song.getLength();
|
||||
int skip = new Random().nextInt(length/2);
|
||||
player.seek(skip);
|
||||
}
|
||||
} catch (MPDConnectionException e) {
|
||||
e.printStackTrace();
|
||||
} catch (MPDPlayerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current mpd volume
|
||||
* @param volume the volume in percent (0-100)
|
||||
|
|
Loading…
Reference in New Issue