com.google.cast.samples.games.spellcast.messages.PlayerPlayingMessage.java Source code

Java tutorial

Introduction

Here is the source code for com.google.cast.samples.games.spellcast.messages.PlayerPlayingMessage.java

Source

// 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 to receiver when the host starts the game.
 */
public class PlayerPlayingMessage extends SpellCastMessage {
    private static final String KEY_DIFFICULTY_SETTING = "difficultySetting";
    private static final String TAG = "PlayerPlayingMessage";

    private DifficultySetting mDifficulty;

    public PlayerPlayingMessage(DifficultySetting difficulty) {
        mDifficulty = difficulty;
    }

    @Override
    public JSONObject toJSON() {
        JSONObject serialized = new JSONObject();
        try {
            serialized.put(KEY_DIFFICULTY_SETTING, SpellCastMessage.spellCastEnumToInt(mDifficulty));
        } catch (JSONException e) {
            Log.w(TAG, "JSONException converting spell list to JSON.", e);
        }

        return serialized;
    }
}