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) { public TheGame(IGuiControl guiControl) {
this.guiControl = guiControl; this.guiControl = guiControl;
this.ircClient = new IrcClient(); this.ircClient = new IrcClient("crashtest", "#crashtest","irc.ctdo.de");
this.machine = new Statemachine();
this.bunti = new BuntiClient("bunti.ctdo.de", 8080); 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(); initGame();
} }

View File

@ -17,8 +17,10 @@ public class MainGui extends JFrame implements IGuiControl {
public MainGui() { public MainGui() {
initGui(); initGui();
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setBounds(0,0, 1280, 1024); setBounds(0,0, 1280, 1024);
setExtendedState(Frame.MAXIMIZED_BOTH);
setUndecorated(true);
addKeyListener(new KeyAdapter() { addKeyListener(new KeyAdapter() {
@Override @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 List<IRCEventListener> listenerListIRC = new ArrayList<IRCEventListener>();
private final static String CHANNEL = "#crashtest"; private final static String CHANNEL = "#crashtest";
private Session ircsession; private Session ircsession;
private final String channel;
public IrcClient() { public IrcClient(String nick, String channel, String server) {
ConnectionManager ircConnection = new ConnectionManager(new ProfileImpl("crashtest", "crashtest", this.channel = channel;
"crashtest2", "crashtest3")); ConnectionManager ircConnection = new ConnectionManager(new ProfileImpl(nick,nick, nick+2, nick+3));
ircsession = ircConnection.requestConnection("irc.chaostreff-dortmund.de"); ircsession = ircConnection.requestConnection(server);
ircsession.addIRCEventListener(this); ircsession.addIRCEventListener(this);
} }
@ -34,7 +35,7 @@ public class IrcClient implements IIrcClient, jerklib.events.listeners.IRCEventL
public void recieveEvent(IRCEvent ircEvent) { public void recieveEvent(IRCEvent ircEvent) {
if(ircEvent instanceof ConnectionCompleteEvent) { if(ircEvent instanceof ConnectionCompleteEvent) {
ircEvent.getSession().joinChannel(CHANNEL); ircEvent.getSession().joinChannel(channel);
} }
else if (ircEvent instanceof JoinCompleteEvent) { else if (ircEvent instanceof JoinCompleteEvent) {
JoinCompleteEvent jce = (JoinCompleteEvent) ircEvent; JoinCompleteEvent jce = (JoinCompleteEvent) ircEvent;

View File

@ -1,6 +1,5 @@
package de.ctdo.crashtest.mpd; package de.ctdo.crashtest.mpd;
import de.ctdo.crashtest.game.TheGame;
import de.ctdo.crashtest.log.Logger; import de.ctdo.crashtest.log.Logger;
import org.bff.javampd.MPD; import org.bff.javampd.MPD;
import org.bff.javampd.MPDDatabase; import org.bff.javampd.MPDDatabase;
@ -14,27 +13,17 @@ 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.Collection;
import java.util.List; import java.util.List;
/** /**
* @author: lucas * A MPD abstraction to the org.bff.javampd library
* @date: 01.06.12 10:34
*/ */
public class MPDController implements IMPDController { public class MPDController implements IMPDController {
private MPD mpd; private MPD mpd;
public MPDController() { public MPDController(String host) {
initMPD();
}
private void initMPD() {
try { try {
mpd = new MPD("dampfradio.raum.chaostreff-dortmund.de", 6600); mpd = new MPD(host, 6600);
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
Logger.sLog("MPD error: " + e.getMessage()); Logger.sLog("MPD error: " + e.getMessage());
} catch (MPDConnectionException e) { } 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 @Override
public void playSong(final String artist, final String title) { public void playSong(final String artist, final String title) {
if(mpd != null) { 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 @Override
public void setVolume(final int volume) { public void setVolume(final int volume) {
if(mpd != null) { if(mpd != null) {