Android Open Source - Airplanes Message






From Project

Back to project page Airplanes.

License

The source code is released under:

GNU General Public License

If you think the Android project Airplanes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.axnsan.airplanes.online;
/* www  . jav a2s. co m*/
import java.nio.ByteBuffer;
import java.nio.charset.Charset;

import com.axnsan.airplanes.online.SocketClosedMessage.REASON;


public abstract class Message {
  public abstract int getMessageType();
  public abstract void serialize(ByteBuffer dst);
  public abstract int serializeLength();
  
  public static Message deserialize(ByteBuffer src) {
    switch ((int) (src.get() & 0xff)) {
      case MESSAGE_TYPE.ACCOUNT_REGISTER:         return AccountRegisterMessage.deserialize(src);
      case MESSAGE_TYPE.ACCOUNT_LOGIN:          return AccountLoginMessage.deserialize(src);
      case MESSAGE_TYPE.SERVER_RESPONSE:          return ServerResponseMessage.deserialize(src);
      case MESSAGE_TYPE.EVENT_GAME_CREATED:        return GameCreatedMessage.deserialize(src);
      case MESSAGE_TYPE.EVENT_PLAYER_JOINED_GAME:      return PlayerJoinedMessage.deserialize(src);
      case MESSAGE_TYPE.EVENT_PLAYER_LEFT_GAME:      return PlayerLeftMessage.deserialize(src);
      case MESSAGE_TYPE.EVENT_TURN_STARTED:        return TurnStartedMessage.deserialize(src);
      case MESSAGE_TYPE.PLANE_LOCATIONS:          return PlaneLocationsMessage.deserialize(src);
      case MESSAGE_TYPE.ATTACK_CELL:            return AttackCellMessage.deserialize(src);
      case MESSAGE_TYPE.GAME_FINISHED:          return GameEndMessage.deserialize(src);
      case MESSAGE_TYPE.CONNECTION_CLOSED:        return new SocketClosedMessage(REASON.DISCONNECTED_BY_SERVER);
    }
    
    return null;
  }
  
  private static Charset CHARSET_UTF8 = Charset.forName("UTF-8");
  
  public static String getString(ByteBuffer bytes) {
    int len = (int) (bytes.getShort() & 0xffff);
    byte[] b = new byte[len];
    bytes.get(b);
    return new String(b, CHARSET_UTF8);
  }
  
  public static void putString(String string, ByteBuffer buffer) {
    buffer.putShort((short)string.length());
    buffer.put(string.getBytes(CHARSET_UTF8));
  }
}




Java Source Code List

com.axnsan.airplanes.Airplanes.java
com.axnsan.airplanes.BaseGrid.java
com.axnsan.airplanes.GameConfiguration.java
com.axnsan.airplanes.GameState.java
com.axnsan.airplanes.GridRandomizer.java
com.axnsan.airplanes.Grid.java
com.axnsan.airplanes.GuardedScreen.java
com.axnsan.airplanes.HotseatMatchHandler.java
com.axnsan.airplanes.MainActivity.java
com.axnsan.airplanes.Main.java
com.axnsan.airplanes.MatchHandler.java
com.axnsan.airplanes.PlacementGrid.java
com.axnsan.airplanes.Plane.java
com.axnsan.airplanes.Player.java
com.axnsan.airplanes.PlayingGrid.java
com.axnsan.airplanes.online.ClientSocket.java
com.axnsan.airplanes.online.EventHandler.java
com.axnsan.airplanes.online.Game.java
com.axnsan.airplanes.online.LobbyScreen.java
com.axnsan.airplanes.online.LoginScreen.java
com.axnsan.airplanes.online.Message.java
com.axnsan.airplanes.online.Messages.java
com.axnsan.airplanes.online.OnlineGameScreen.java
com.axnsan.airplanes.online.OnlineMatchHandler.java
com.axnsan.airplanes.online.OnlineMenuScreen.java
com.axnsan.airplanes.online.OnlineSettingsScreen.java
com.axnsan.airplanes.online.SessionData.java
com.axnsan.airplanes.screens.BeginTurnScreen.java
com.axnsan.airplanes.screens.HotseatPlayersScreen.java
com.axnsan.airplanes.screens.HotseatScreen.java
com.axnsan.airplanes.screens.HotseatSettingsScreen.java
com.axnsan.airplanes.screens.HotseatStartScreen.java
com.axnsan.airplanes.screens.MainMenuScreen.java
com.axnsan.airplanes.screens.PlacementScreen.java
com.axnsan.airplanes.screens.PlayMenuScreen.java
com.axnsan.airplanes.screens.PracticeScreen.java
com.axnsan.airplanes.screens.PracticeSettingsScreen.java
com.axnsan.airplanes.screens.PracticeStartScreen.java
com.axnsan.airplanes.util.ActionManager.java
com.axnsan.airplanes.util.ActionResolver.java
com.axnsan.airplanes.util.BasicFontManager.java
com.axnsan.airplanes.util.Detector.java
com.axnsan.airplanes.util.DoubleTapDetector.java
com.axnsan.airplanes.util.DoubleTapListener.java
com.axnsan.airplanes.util.FontManagerInterface.java
com.axnsan.airplanes.util.FontManager.java
com.axnsan.airplanes.util.JavaXmlParser.java
com.axnsan.airplanes.util.Point2D.java
com.axnsan.airplanes.util.RandomizedQueue.java
com.axnsan.airplanes.util.StringManager.java
com.axnsan.airplanes.util.StringXmlParser.java
com.axnsan.airplanes.util.TTFFontManager.java
com.axnsan.airplanes.util.TapDetector.java
com.axnsan.airplanes.util.TapListener.java