Search in sources :

Example 1 with ShakeWindow

use of org.jivesoftware.spark.ui.ShakeWindow in project Spark by igniterealtime.

the class GamePanel method onGameBoardPlaceMark.

/**
 * being called from GameBoardPanel, places the Mark on the Logical Board
 * and sends the Move if it was one
 *
 * @param m
 * @param x
 * @param y
 */
public void onGameBoardPlaceMark(Mark m, int x, int y) {
    _gameboard.placeMark(x, y);
    _playerdisplay.setCurrentPlayer(_gameboard.getCurrentPlayer());
    if (m == getMyMark()) {
        MovePacket move = new MovePacket();
        move.setGameID(_gameID);
        move.setPositionX(x);
        move.setPositionY(y);
        Message message = new Message(_opponent);
        message.addExtension(move);
        try {
            _connection.sendStanza(message);
        } catch (SmackException.NotConnectedException e) {
            Log.warning("Unable to send move to " + message.getTo(), e);
        }
    }
    if (_gameboard.isGameFinished()) {
        _gameboardpanel.colorizeWinners(_gameboard.getWinningPositions());
        if (_gameboard.getWinner() == getMyMark().getValue()) {
            remove(_playerdisplay);
            add(new GameEndsUI(TTTRes.getString("ttt.win"), Color.GREEN), BorderLayout.SOUTH);
        }
        if (_gameboard.getWinner() == getYourMark().getValue()) {
            remove(_playerdisplay);
            add(new GameEndsUI(TTTRes.getString("ttt.lose"), Color.RED), BorderLayout.SOUTH);
        }
        if (_gameboard.getWinner() == -1) {
            remove(_playerdisplay);
            add(new GameEndsUI(TTTRes.getString("ttt.tie"), Color.BLACK), BorderLayout.SOUTH);
        }
        ShakeWindow sw = new ShakeWindow(_frame);
        sw.startShake();
        repaint();
        revalidate();
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) MovePacket(tic.tac.toe.packet.MovePacket) SmackException(org.jivesoftware.smack.SmackException) ShakeWindow(org.jivesoftware.spark.ui.ShakeWindow)

Aggregations

SmackException (org.jivesoftware.smack.SmackException)1 Message (org.jivesoftware.smack.packet.Message)1 ShakeWindow (org.jivesoftware.spark.ui.ShakeWindow)1 MovePacket (tic.tac.toe.packet.MovePacket)1