www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit edeb47c32589cc0b1b89fd7377fd3096a9cee488
parent 71a9759bde6a23a801f73aca6d9e0613e31570c9
Author: Bertrand BRUN <bertrand0brun@gmail.com>
Date:   Tue,  1 Feb 2011 23:58:53 +0100

Rajout de commentaire (Car il en faut !!)
Diffstat:
Mcode/PtiClic/src/org/pticlic/Score.java | 24+++++++++++++++++++++++-
Mcode/PtiClic/src/org/pticlic/games/BaseGame.java | 55++++++++++++++++++++++++++++++++++++++++---------------
Mcode/PtiClic/src/org/pticlic/model/Constant.java | 3++-
Mcode/PtiClic/src/org/pticlic/model/GamePlayed.java | 25++++++++++++++++++-------
Mcode/PtiClic/src/org/pticlic/model/Network.java | 22+++++++++++-----------
Mcode/PtiClic/src/org/pticlic/model/Relation.java | 1+
6 files changed, 95 insertions(+), 35 deletions(-)

diff --git a/code/PtiClic/src/org/pticlic/Score.java b/code/PtiClic/src/org/pticlic/Score.java @@ -1,14 +1,24 @@ package org.pticlic; import org.pticlic.model.Constant; +import org.pticlic.model.DownloadedScore; import org.pticlic.model.GamePlayed; +import org.pticlic.model.Network; +import org.pticlic.model.Network.Mode; import android.app.Activity; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; +/** + * @author John CHARRON + * + * Permet l'affichage du score obtenu par le joueur lors de sa partie. + */ public class Score extends Activity implements OnClickListener{ private GamePlayed gamePlayed; @@ -18,10 +28,22 @@ public class Score extends Activity implements OnClickListener{ super.onCreate(savedInstanceState); setContentView(R.layout.score); + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + String serverURL = sp.getString(Constant.SERVER_URL, "http://dumbs.fr/~bbrun/pticlic.json"); // TODO : Mettre comme valeur par defaut l'adresse reel du serveur + String id = sp.getString(Constant.USER_ID, "joueur"); + String passwd = sp.getString(Constant.USER_PASSWD, ""); + Mode mode = null; + if (getIntent().getExtras() != null) { // Pour JC : GamePlayed contient toutes les infos sur la partie jouee - this.gamePlayed = (GamePlayed) getIntent().getExtras().get(Constant.SCORE_INTENT); + this.gamePlayed = (GamePlayed) getIntent().getExtras().get(Constant.SCORE_GAMEPLAYED); + mode = (Mode) getIntent().getExtras().get(Constant.SCORE_MODE); } + + Network network = new Network(serverURL, mode, id, passwd); + + // FIXME : Pour l'instant ne marche pas, attend de savoir comment est formater le score que l'on recois. + //DownloadedScore score = network.sendGame(gamePlayed); ((Button)findViewById(R.id.saw)).setOnClickListener(this); diff --git a/code/PtiClic/src/org/pticlic/games/BaseGame.java b/code/PtiClic/src/org/pticlic/games/BaseGame.java @@ -3,9 +3,10 @@ package org.pticlic.games; import org.pticlic.R; import org.pticlic.Score; import org.pticlic.model.Constant; -import org.pticlic.model.Game; +import org.pticlic.model.DownloadedGame; import org.pticlic.model.GamePlayed; import org.pticlic.model.Network; +import org.pticlic.model.Relation; import org.pticlic.model.Network.Mode; import android.app.Activity; @@ -22,10 +23,24 @@ import android.view.animation.TranslateAnimation; import android.widget.Button; import android.widget.TextView; +/** + * @author Bertrand BRUN et Georges DUPÉRON + * + * Cette classe est le controlleur du premier jeu. + * + * Ce premier jeu appeler "Jeux de Base", permet de creer des relations en selectionnant + * le type de relation d'un mot du nuage de mot par rapport au mot central. + * + * La vue de ce jeu se presente sous la forme d'un fenetre presentant en haut le mot central, + * et les mots du nuage descende en partant du mot central vers le centre du mobile. + * Une fois le mot du nuage afficher, l'utilisateur peut selectionner, parmis les relations + * proposer celle qui lui semble le mieux approprier. + * + */ public class BaseGame extends Activity implements OnClickListener { private int currentWord = 0; private int nbWord = 0; - private Game game; + private DownloadedGame game; private GamePlayed gamePlayed; /** Called when the activity is first created. */ @@ -34,41 +49,46 @@ public class BaseGame extends Activity implements OnClickListener { super.onCreate(savedInstanceState); setContentView(R.layout.game); + // On recupere du PreferenceManager les differentes information dont on a besoin SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); String serverURL = sp.getString(Constant.SERVER_URL, "http://dumbs.fr/~bbrun/pticlic.json"); // TODO : Mettre comme valeur par defaut l'adresse reel du serveur String id = sp.getString(Constant.USER_ID, "joueur"); String passwd = sp.getString(Constant.USER_PASSWD, ""); + // On initialise la classe permettant la communication avec le serveur. Network network = new Network(serverURL, Mode.SIMPLE_GAME, id, passwd); game = network.getGames(1); int nbrel = game.getNbRelation(); nbWord = game.getNbWord(); + // On initialise la partie. gamePlayed = new GamePlayed(); gamePlayed.setGame(game); + + Relation r = Relation.getInstance(); // Boutons des relations Button r1 = ((Button)findViewById(R.id.relation1)); Button r2 = ((Button)findViewById(R.id.relation2)); Button r3 = ((Button)findViewById(R.id.relation3)); Button r4 = ((Button)findViewById(R.id.relation4)); - Button poubelle = ((Button)findViewById(R.id.poubelle)); + + // TODO : Pour l'instant la poubelle ne fait rien. Il faudra certainement la ranger dans un categorie dans GamePlayed pour calculer le score. + ((Button)findViewById(R.id.poubelle)).setText("Poubelle"); // Écoute des clics sur les relations - if (nbrel > 0) { r1.setOnClickListener(this); } else { r1.setVisibility(View.GONE); } - if (nbrel > 1) { r2.setOnClickListener(this); } else { r2.setVisibility(View.GONE); } - if (nbrel > 2) { r3.setOnClickListener(this); } else { r3.setVisibility(View.GONE); } - if (nbrel > 3) { r4.setOnClickListener(this); } else { r4.setVisibility(View.GONE); } + if (nbrel > 0) { r1.setOnClickListener(this); r1.setText(r.getRelationName(game.getCat1())); } else { r1.setVisibility(View.GONE); } + if (nbrel > 1) { r2.setOnClickListener(this); r2.setText(r.getRelationName(game.getCat2()));} else { r2.setVisibility(View.GONE); } + if (nbrel > 2) { r3.setOnClickListener(this); r3.setText(r.getRelationName(game.getCat3()));} else { r3.setVisibility(View.GONE); } + if (nbrel > 3) { r4.setOnClickListener(this); r4.setText(r.getRelationName(game.getCat4()));} else { r4.setVisibility(View.GONE); } - - //TODO : Faudrait gere dynamiquement la gestion des nom des relations. - r1.setText("Idée"); - r2.setText("Partie"); - poubelle.setText("Poubelle"); - ((TextView)findViewById(R.id.mainWord)).setText(Game.getName(game.getCentre())); + ((TextView)findViewById(R.id.mainWord)).setText(DownloadedGame.getName(game.getCentre())); } + /* (non-Javadoc) + * @see android.app.Activity#onStart() + */ @Override protected void onStart() { super.onStart(); @@ -76,6 +96,9 @@ public class BaseGame extends Activity implements OnClickListener { start(); } + /* (non-Javadoc) + * @see android.app.Activity#onActivityResult(int, int, android.content.Intent) + */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); @@ -114,7 +137,7 @@ public class BaseGame extends Activity implements OnClickListener { * Cette methode permet de passer au mot courant suivant et de lancer l'animation. */ private void start() { - ((TextView)findViewById(R.id.currentWord)).setText(Game.getName(game.getWordInCloud(currentWord))); + ((TextView)findViewById(R.id.currentWord)).setText(DownloadedGame.getName(game.getWordInCloud(currentWord))); arrivalView(); } @@ -126,7 +149,9 @@ public class BaseGame extends Activity implements OnClickListener { start(); } else { Intent intent = new Intent(this, Score.class); - intent.putExtra(Constant.SCORE_INTENT, gamePlayed); + intent.putExtra(Constant.SCORE_GAMEPLAYED, gamePlayed); + intent.putExtra(Constant.SCORE_MODE, Mode.SIMPLE_GAME); + startActivityForResult(intent, 0x100); } } diff --git a/code/PtiClic/src/org/pticlic/model/Constant.java b/code/PtiClic/src/org/pticlic/model/Constant.java @@ -8,5 +8,6 @@ public class Constant { public static final String USER_PASSWD = "passwd"; // Constant pour les intents - public static final String SCORE_INTENT = "SCORE_INTENT"; + public static final String SCORE_GAMEPLAYED = "SCORE_INTENT"; + public static final String SCORE_MODE = "SCORE_MODE"; } diff --git a/code/PtiClic/src/org/pticlic/model/GamePlayed.java b/code/PtiClic/src/org/pticlic/model/GamePlayed.java @@ -3,6 +3,14 @@ package org.pticlic.model; import java.io.Serializable; import java.util.ArrayList; +/** + * @author Bertrand BRUN + * + * Cette classe represente une partie joue. + * Elle sera envoyer au serveur pour que celui-ci + * puisse calculer le score obtenue. + * + */ public class GamePlayed implements Serializable { private static final long serialVersionUID = 1L; @@ -10,29 +18,32 @@ public class GamePlayed implements Serializable { private ArrayList<CharSequence> relation2; private ArrayList<CharSequence> relation3; private ArrayList<CharSequence> relation4; - private Game game; + private ArrayList<CharSequence> poubelle; + private DownloadedGame game; public GamePlayed() { relation1 = new ArrayList<CharSequence>(); relation2 = new ArrayList<CharSequence>(); relation3 = new ArrayList<CharSequence>(); relation4 = new ArrayList<CharSequence>(); + poubelle = new ArrayList<CharSequence>(); } - public void setGame(Game game) { + public void setGame(DownloadedGame game) { this.game = game; } - public Game getGame() { + public DownloadedGame getGame() { return game; } public void add(int relation, CharSequence word) { switch (relation) { - case 1: relation1.add(word); break; - case 2: relation2.add(word); break; - case 3: relation3.add(word); break; - case 4: relation4.add(word); break; + case 1: relation1.add(word); break; + case 2: relation2.add(word); break; + case 3: relation3.add(word); break; + case 4: relation4.add(word); break; + default: poubelle.add(word); break; } } } diff --git a/code/PtiClic/src/org/pticlic/model/Network.java b/code/PtiClic/src/org/pticlic/model/Network.java @@ -59,8 +59,8 @@ public class Network { * @param nbGames Le nombre de parties que l'on veut récupérer. * @return */ - public Game getGames(int nbGames) { - Game game = null; + public DownloadedGame getGames(int nbGames) { + DownloadedGame game = null; try { URL url = new URL(this.serverURL); URLConnection connection = url.openConnection(); @@ -97,14 +97,14 @@ public class Network { * @return Une nouvelle instance de Game. * @throws IOException */ - private Game makeGame(JsonReader reader, Gson gson) throws IOException { + private DownloadedGame makeGame(JsonReader reader, Gson gson) throws IOException { int id = -1; int cat1 = -1; int cat2 = -1; int cat3 = -1; int cat4 = -1; - Game.Word center = null; - Game.Word[] cloud = null; + DownloadedGame.Word center = null; + DownloadedGame.Word[] cloud = null; reader.beginObject(); while (reader != null && reader.hasNext()) { @@ -120,15 +120,15 @@ public class Network { } else if (name.equals("cat4")) { cat4 = reader.nextInt(); } else if (name.equals("center")) { - center = gson.fromJson(reader, Game.Word.class); + center = gson.fromJson(reader, DownloadedGame.Word.class); } else if (name.equals("cloud")) { - cloud = gson.fromJson(reader, Game.Word[].class); + cloud = gson.fromJson(reader, DownloadedGame.Word[].class); } else { reader.skipValue(); } } reader.endObject(); - return new Game(id, cat1, cat2, cat3, cat4, center, cloud); + return new DownloadedGame(id, cat1, cat2, cat3, cat4, center, cloud); } @@ -138,8 +138,8 @@ public class Network { * @param game La partie jouee par l'utilisateur * @return Le score sous forme JSON. */ - public String sendGame(GamePlayed game) { - String score = null; + public DownloadedScore sendGame(GamePlayed game) { + DownloadedScore score = null; try { URL url = new URL(this.serverURL); URLConnection connection = url.openConnection(); @@ -155,7 +155,7 @@ public class Network { JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); // TODO : A changer lorsque je serais exactement ce que renvoie le serveur. - score = gson.fromJson(reader, String.class); + score = gson.fromJson(reader, DownloadedScore.class); } catch (IOException e) { return score; diff --git a/code/PtiClic/src/org/pticlic/model/Relation.java b/code/PtiClic/src/org/pticlic/model/Relation.java @@ -20,6 +20,7 @@ public class Relation { private Relation() { stringRelations = new HashMap<Integer, String>(); + stringRelations.put(-1, ""); stringRelations.put(0, "idée"); stringRelations.put(1, "raffinement sémantique"); stringRelations.put(2, "raffinement morphologique");