Example usage for org.json JSONObject toString

List of usage examples for org.json JSONObject toString

Introduction

In this page you can find the example usage for org.json JSONObject toString.

Prototype

public String toString() 

Source Link

Document

Make a JSON text of this JSONObject.

Usage

From source file:reseau.jeu.serveur.Protocole.java

public static String construireMsgJoueurInitialisation(int etat) {
    JSONObject msg = new JSONObject();

    try {//from w ww .ja v a  2  s  .  c o  m
        msg.put("TYPE", JOUEUR_INITIALISATION);
        msg.put("STATUS", etat);
    } catch (JSONException jsone) {
        jsone.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

public static String construireMsgPartieChangementEtat(int etat) {
    JSONObject msg = new JSONObject();

    try {/*www.  j a  v  a  2  s.  c  om*/
        msg.put("TYPE", PARTIE_ETAT);
        msg.put("ETAT", etat);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

/**
 * Permet de construire le message d'tat d'un joueur
 * //from   w w w  . jav  a2  s. c  o  m
 * @param joueur le joueur
 * @return Une structure JSONObject
 */
public static String construireMsgJoueurEtat(Joueur joueur) {
    JSONObject msg = new JSONObject();

    try {
        msg.put("TYPE", JOUEUR_ETAT);
        msg.put("ID_JOUEUR", joueur.getId());
        msg.put("NB_PIECES_OR", joueur.getNbPiecesDOr());
        msg.put("NB_VIES_RESTANTES_EQUIPE", joueur.getEquipe().getNbViesRestantes());
        msg.put("REVENU", joueur.getRevenu());
        msg.put("SCORE", joueur.getScore());
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

/**
 * Permet de construire le message de demande d'ajout d'une tour
 * /*w  w w .j  a  va 2s. com*/
 * @param tour la tour
 * @return Une structure JSONObject
 */
public static String construireMsgTourAjout(Tour tour) {
    JSONObject msg = new JSONObject();

    try {
        msg.put("TYPE", TOUR_AJOUT);
        msg.put("ID_PROPRIETAIRE", tour.getPrioprietaire().getId());
        msg.put("ID_TOUR", tour.getId());
        msg.put("X", tour.x);
        msg.put("Y", tour.y);
        msg.put("TYPE_TOUR", TypeDeTour.getTypeDeTour(tour));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

/**
 * Permet de construire le message de demande d'amlioration d'une tour
 * //w  w  w .ja v a  2s  .c  o  m
 * @param tour la tour
 * @return Une structure JSONObject
 */
public static String construireMsgTourAmelioration(Tour tour) {
    JSONObject msg = new JSONObject();

    try {
        msg.put("TYPE", TOUR_AMELIORATION);
        msg.put("ID_TOUR", tour.getId());
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

/**
 * Permet de construire le message de demander la suppression d'une tour
 * //from  ww  w .j a  v  a2  s  .  com
 * @param tour la tour
 * @return Une structure JSONObject
 */
public static String construireMsgTourSuppression(Tour tour) {
    JSONObject msg = new JSONObject();

    try {
        msg.put("TYPE", TOUR_SUPRESSION);
        msg.put("ID_TOUR", tour.getId());
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

/**
 * Permet de construire le message d'ajout d'une crature
 * //from   ww w  .  jav  a  2  s  .com
 * @param creature la creature
 * @return Une structure JSONObject
 */
public static String construireMsgCreatureAjout(Creature creature) {
    JSONObject msg = new JSONObject();

    try {
        msg.put("TYPE", CREATURE_AJOUT);
        msg.put("TYPE_CREATURE", TypeDeCreature.getTypeCreature(creature));
        msg.put("ID_CREATURE", creature.getId());
        msg.put("ID_PROPRIETAIRE", creature.getProprietaire().getId());
        msg.put("ID_EQUIPE_CIBLEE", creature.getEquipeCiblee().getId());
        msg.put("X", creature.x);
        msg.put("Y", creature.y);
        msg.put("SANTE_MAX", creature.getSanteMax());
        msg.put("NB_PIECES_OR", creature.getNbPiecesDOr());
        msg.put("VITESSE", creature.getVitesseNormale());
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

/**
 * Permet de construire le message d'tat d'une crature
 * // w  w w  . j  ava  2 s  .  co  m
 * @param creature la creature
 * @return Une structure JSONObject
 */
public static String construireMsgCreatureEtat(Creature creature) {
    JSONObject msg = new JSONObject();

    try {
        msg.put("TYPE", CREATURE_ETAT);
        msg.put("ID_CREATURE", creature.getId());

        msg.put("X", creature.x);
        msg.put("Y", creature.y);
        msg.put("SANTE", creature.getSante());
        msg.put("ANGLE", creature.getAngle());
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

/**
 * Permet de construire le message de suppression d'une crature
 * //from   w  w w .  j av a  2 s.c  o m
 * @param creature la creature
 * @return Une structure JSONObject
 */
public static String construireMsgCreatureSuppression(Creature creature, Joueur joueur) {
    JSONObject msg = new JSONObject();

    try {
        msg.put("TYPE", CREATURE_SUPPRESSION);
        msg.put("ID_CREATURE", creature.getId());
        msg.put("ID_TUEUR", joueur.getId());

    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

public static String construireMsgPartieTerminee(Jeu jeu) {
    JSONObject msg = new JSONObject();

    try {/*from  w w  w  . j  av a  2s.  c  om*/
        msg.put("TYPE", PARTIE_ETAT);
        msg.put("ETAT", PARTIE_TERMINEE);

        // construction des tats des quipes
        JSONArray JSONequipes = new JSONArray();
        for (Equipe e : jeu.getEquipes()) {
            JSONObject JSONequipe = new JSONObject();

            JSONequipe.put("ID_EQUIPE", e.getId());

            if (e.estHorsJeu())
                JSONequipe.put("NB_VIES_RESTANTES", 0);
            else
                JSONequipe.put("NB_VIES_RESTANTES", e.getNbViesRestantes());

            JSONequipes.put(JSONequipe);
        }
        msg.put("EQUIPES", JSONequipes);

        // TODO construction des tats des joueurs
        // ...
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}