Search in sources :

Example 1 with DefaultSoundChannel

use of games.strategy.sound.DefaultSoundChannel in project triplea by triplea-game.

the class TripleA method startGame.

@Override
public void startGame(final IGame game, final Set<IGamePlayer> players, final boolean headless) throws InterruptedException {
    this.game = game;
    if (game.getData().getDelegateList().getDelegate("edit") == null) {
        // An evil hack: instead of modifying the XML, force an EditDelegate by adding one here
        final EditDelegate delegate = new EditDelegate();
        delegate.initialize("edit", "edit");
        game.getData().getDelegateList().addDelegate(delegate);
        if (game instanceof ServerGame) {
            ((ServerGame) game).addDelegateMessenger(delegate);
        }
    }
    final LocalPlayers localPlayers = new LocalPlayers(players);
    if (headless) {
        final UiContext uiContext = new HeadlessUiContext();
        uiContext.setDefaultMapDir(game.getData());
        uiContext.setLocalPlayers(localPlayers);
        display = new HeadlessDisplay();
        soundChannel = new HeadlessSoundChannel();
        game.addDisplay(display);
        game.addSoundChannel(soundChannel);
        // technically not needed because we won't have any "local human players" in a headless game.
        connectPlayers(players, null);
    } else {
        SwingAction.invokeAndWait(() -> {
            final TripleAFrame frame = new TripleAFrame(game, localPlayers);
            LookAndFeelSwingFrameListener.register(frame);
            display = new TripleADisplay(frame);
            game.addDisplay(display);
            soundChannel = new DefaultSoundChannel(localPlayers);
            game.addSoundChannel(soundChannel);
            frame.setSize(700, 400);
            frame.setVisible(true);
            ClipPlayer.play(SoundPath.CLIP_GAME_START);
            connectPlayers(players, frame);
            frame.setExtendedState(Frame.MAXIMIZED_BOTH);
            frame.toFront();
        });
    }
}
Also used : LocalPlayers(games.strategy.engine.framework.LocalPlayers) ITripleADisplay(games.strategy.triplea.ui.display.ITripleADisplay) TripleADisplay(games.strategy.triplea.ui.display.TripleADisplay) HeadlessDisplay(games.strategy.triplea.ui.display.HeadlessDisplay) ServerGame(games.strategy.engine.framework.ServerGame) EditDelegate(games.strategy.triplea.delegate.EditDelegate) HeadlessUiContext(games.strategy.triplea.ui.HeadlessUiContext) HeadlessSoundChannel(games.strategy.sound.HeadlessSoundChannel) TripleAFrame(games.strategy.triplea.ui.TripleAFrame) DefaultSoundChannel(games.strategy.sound.DefaultSoundChannel) UiContext(games.strategy.triplea.ui.UiContext) HeadlessUiContext(games.strategy.triplea.ui.HeadlessUiContext)

Aggregations

LocalPlayers (games.strategy.engine.framework.LocalPlayers)1 ServerGame (games.strategy.engine.framework.ServerGame)1 DefaultSoundChannel (games.strategy.sound.DefaultSoundChannel)1 HeadlessSoundChannel (games.strategy.sound.HeadlessSoundChannel)1 EditDelegate (games.strategy.triplea.delegate.EditDelegate)1 HeadlessUiContext (games.strategy.triplea.ui.HeadlessUiContext)1 TripleAFrame (games.strategy.triplea.ui.TripleAFrame)1 UiContext (games.strategy.triplea.ui.UiContext)1 HeadlessDisplay (games.strategy.triplea.ui.display.HeadlessDisplay)1 ITripleADisplay (games.strategy.triplea.ui.display.ITripleADisplay)1 TripleADisplay (games.strategy.triplea.ui.display.TripleADisplay)1