Search in sources :

Example 11 with MainScreen

use of net.rim.device.api.ui.container.MainScreen in project Samples-for-Java by blackberry.

the class StartGameScreen method gameMessage.

public void gameMessage(ProtocolMessage message) {
    if (message instanceof ProtocolMessageMasterBid) {
        ProtocolMessageMasterBid other_bid = (ProtocolMessageMasterBid) message;
        int device_status = 0;
        boolean initialised = false;
        if (my_bid.getBid() > other_bid.getBid()) {
            Utilities.log("XXXX won the bid: player 1");
            device_status = Constants.PLAYER_1;
            initialised = true;
        } else {
            if (my_bid.getBid() < other_bid.getBid()) {
                Utilities.log("XXXX lost the bid: player 2");
                device_status = Constants.PLAYER_2;
                initialised = true;
            } else {
                Utilities.popupMessage("It didn't work, try again!");
            }
        }
        if (initialised) {
            try {
                proto.disableMessaging();
            } catch (NFCException e) {
                Utilities.log("XXXX StartGameScreen:" + e.getClass().getName() + ":" + e.getMessage());
                Utilities.popupMessage("We had a problem, please try again");
            }
            final int player_no = device_status;
            final MainScreen next_screen;
            if (player_no == Constants.PLAYER_2) {
                next_screen = GameScreen.getInstance(player_no);
            } else {
                next_screen = new SymbolSelectionScreen();
            }
            UiApplication.getUiApplication().invokeLater(new Runnable() {

                public void run() {
                    UiApplication.getUiApplication().pushScreen(next_screen);
                }
            });
        }
    }
}
Also used : ProtocolMessageMasterBid(nfc.sample.tictactoe.protocol.ProtocolMessageMasterBid) NFCException(net.rim.device.api.io.nfc.NFCException) MainScreen(net.rim.device.api.ui.container.MainScreen)

Aggregations

MainScreen (net.rim.device.api.ui.container.MainScreen)11 NfcVirtTargScreen (nfc.sample.virtual.target.ui.NfcVirtTargScreen)3 NFCException (net.rim.device.api.io.nfc.NFCException)2 CustomTagScreen (nfc.sample.Ndef.Write.ui.CustomTagScreen)1 SpTagScreen (nfc.sample.Ndef.Write.ui.SpTagScreen)1 TextTagScreen (nfc.sample.Ndef.Write.ui.TextTagScreen)1 UriTagScreen (nfc.sample.Ndef.Write.ui.UriTagScreen)1 ClientTextScreen (nfc.sample.llcp.ui.ClientTextScreen)1 NfcSnepResponderScreen (nfc.sample.peer2peer.ui.NfcSnepResponderScreen)1 ProtocolMessageMasterBid (nfc.sample.tictactoe.protocol.ProtocolMessageMasterBid)1 ResponseTextScreen (nfc.sample.virtual.target.ui.ResponseTextScreen)1