some small refactorings. made the hosts configurable

This commit is contained in:
Lucas Pleß 2012-06-03 15:45:39 +02:00
parent 1c28a2a381
commit 6900121829
4 changed files with 27 additions and 24 deletions

View File

@ -23,10 +23,10 @@ public class TheGame implements StateChangeListener, GuiEventListener, IRCEventL
public TheGame(IGuiControl guiControl) {
this.guiControl = guiControl;
this.ircClient = new IrcClient();
this.machine = new Statemachine();
this.ircClient = new IrcClient("crashtest", "#crashtest","irc.ctdo.de");
this.bunti = new BuntiClient("bunti.ctdo.de", 8080);
this.mpdController = new MPDController();
this.mpdController = new MPDController("dampfradio.raum.ctdo.de");
this.machine = new Statemachine();
initGame();
}

View File

@ -17,8 +17,10 @@ public class MainGui extends JFrame implements IGuiControl {
public MainGui() {
initGui();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setBounds(0,0, 1280, 1024);
setExtendedState(Frame.MAXIMIZED_BOTH);
setUndecorated(true);
addKeyListener(new KeyAdapter() {
@Override
@ -39,6 +41,8 @@ public class MainGui extends JFrame implements IGuiControl {
}
}
});
setVisible(true);
}
//

View File

@ -22,11 +22,12 @@ public class IrcClient implements IIrcClient, jerklib.events.listeners.IRCEventL
private final List<IRCEventListener> listenerListIRC = new ArrayList<IRCEventListener>();
private final static String CHANNEL = "#crashtest";
private Session ircsession;
private final String channel;
public IrcClient() {
ConnectionManager ircConnection = new ConnectionManager(new ProfileImpl("crashtest", "crashtest",
"crashtest2", "crashtest3"));
ircsession = ircConnection.requestConnection("irc.chaostreff-dortmund.de");
public IrcClient(String nick, String channel, String server) {
this.channel = channel;
ConnectionManager ircConnection = new ConnectionManager(new ProfileImpl(nick,nick, nick+2, nick+3));
ircsession = ircConnection.requestConnection(server);
ircsession.addIRCEventListener(this);
}
@ -34,7 +35,7 @@ public class IrcClient implements IIrcClient, jerklib.events.listeners.IRCEventL
public void recieveEvent(IRCEvent ircEvent) {
if(ircEvent instanceof ConnectionCompleteEvent) {
ircEvent.getSession().joinChannel(CHANNEL);
ircEvent.getSession().joinChannel(channel);
}
else if (ircEvent instanceof JoinCompleteEvent) {
JoinCompleteEvent jce = (JoinCompleteEvent) ircEvent;

View File

@ -1,6 +1,5 @@
package de.ctdo.crashtest.mpd;
import de.ctdo.crashtest.game.TheGame;
import de.ctdo.crashtest.log.Logger;
import org.bff.javampd.MPD;
import org.bff.javampd.MPDDatabase;
@ -14,27 +13,17 @@ import org.bff.javampd.objects.MPDSong;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @author: lucas
* @date: 01.06.12 10:34
* A MPD abstraction to the org.bff.javampd library
*/
public class MPDController implements IMPDController {
private MPD mpd;
public MPDController() {
initMPD();
}
private void initMPD() {
public MPDController(String host) {
try {
mpd = new MPD("dampfradio.raum.chaostreff-dortmund.de", 6600);
mpd = new MPD(host, 6600);
} catch (UnknownHostException e) {
Logger.sLog("MPD error: " + e.getMessage());
} catch (MPDConnectionException e) {
@ -42,7 +31,12 @@ public class MPDController implements IMPDController {
}
}
/**
* Play a song, defined by artist and track title
* Song gets added to current playlist and is played.
* @param artist Artist of the track to play
* @param title Title of the track to play
*/
@Override
public void playSong(final String artist, final String title) {
if(mpd != null) {
@ -109,6 +103,10 @@ public class MPDController implements IMPDController {
}
}
/**
* Sets the current mpd volume
* @param volume the volume in percent (0-100)
*/
@Override
public void setVolume(final int volume) {
if(mpd != null) {