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