Java tutorial
// Copyright 2015 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.cast.samples.games.spellcast.messages; import android.util.Log; import org.json.JSONException; import org.json.JSONObject; /** * Message sent when a player chooses to join a game. */ public class PlayerReadyMessage extends SpellCastMessage { private static final String KEY_PLAYER_NAME = "playerName"; private static final String KEY_AVATAR_INDEX = "avatarIndex"; private static final String TAG = "PlayerPlayingMessage"; private final String mPlayerName; private final int mAvatarIndex; public PlayerReadyMessage(String playerName, int avatarIndex) { mPlayerName = playerName; mAvatarIndex = avatarIndex; } @Override public JSONObject toJSON() { JSONObject serialized = new JSONObject(); try { serialized.put(KEY_PLAYER_NAME, mPlayerName); serialized.put(KEY_AVATAR_INDEX, mAvatarIndex); } catch (JSONException e) { Log.w(TAG, "JSONException converting spell list to JSON.", e); } return serialized; } }