www

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

commit 4dddb4f4fc99db28bfe4d668d5396b49497965ab
parent 2327e221dc3b3551313746b5be53edefc1ad27f0
Author: Bertrand BRUN <bertrand0brun@gmail.com>
Date:   Wed,  2 Feb 2011 10:42:52 +0100

Changement du type de parametre pour la methode add de GamePlayed

Diffstat:
Mcode/PtiClic/src/org/pticlic/games/BaseGame.java | 14++++++++------
Mcode/PtiClic/src/org/pticlic/model/GamePlayed.java | 68++++++++++++++++----------------------------------------------------
Mcode/PtiClic/src/org/pticlic/model/Network.java | 55+++++++++++++++++++++++++++++++------------------------
3 files changed, 55 insertions(+), 82 deletions(-)

diff --git a/code/PtiClic/src/org/pticlic/games/BaseGame.java b/code/PtiClic/src/org/pticlic/games/BaseGame.java @@ -9,6 +9,8 @@ import org.pticlic.model.Network; import org.pticlic.model.Relation; import org.pticlic.model.Network.Mode; +import com.google.gson.Gson; + import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; @@ -54,7 +56,7 @@ public class BaseGame extends Activity implements OnClickListener { 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); @@ -64,7 +66,7 @@ public class BaseGame extends Activity implements OnClickListener { // On initialise la partie. gamePlayed = new GamePlayed(); gamePlayed.setGame(game); - + Relation r = Relation.getInstance(); // Boutons des relations @@ -72,7 +74,7 @@ public class BaseGame extends Activity implements OnClickListener { Button r2 = ((Button)findViewById(R.id.relation2)); Button r3 = ((Button)findViewById(R.id.relation3)); Button r4 = ((Button)findViewById(R.id.relation4)); - + // TODO : Pour l'instant la poubelle ne fait rien. Il faudra certainement la ranger dans un categorie dans GamePlayed pour calculer le score. Button trash = ((Button)findViewById(R.id.trash)); trash.setOnClickListener(this); @@ -84,7 +86,7 @@ public class BaseGame extends Activity implements OnClickListener { 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); } - + ((TextView)findViewById(R.id.mainWord)).setText(DownloadedGame.getName(game.getCentre())); } @@ -153,7 +155,7 @@ public class BaseGame extends Activity implements OnClickListener { Intent intent = new Intent(this, Score.class); intent.putExtra(Constant.SCORE_GAMEPLAYED, gamePlayed); intent.putExtra(Constant.SCORE_MODE, Mode.SIMPLE_GAME); - + startActivityForResult(intent, 0x100); } } @@ -163,7 +165,7 @@ public class BaseGame extends Activity implements OnClickListener { */ @Override public void onClick(View v) { - CharSequence currentWord = ((TextView)findViewById(R.id.currentWord)).getText(); + int currentWord = game.getWordInCloud(this.currentWord).getId(); switch (v.getId()) { case (R.id.relation1) : gamePlayed.add(1, currentWord); next(); break; case (R.id.relation2) : gamePlayed.add(2, currentWord); next(); break; diff --git a/code/PtiClic/src/org/pticlic/model/GamePlayed.java b/code/PtiClic/src/org/pticlic/model/GamePlayed.java @@ -14,19 +14,19 @@ import java.util.ArrayList; public class GamePlayed implements Serializable { private static final long serialVersionUID = 1L; - private ArrayList<String> relation1; - private ArrayList<String> relation2; - private ArrayList<String> relation3; - private ArrayList<String> relation4; - private ArrayList<String> trash; + private ArrayList<Integer> relation1; + private ArrayList<Integer> relation2; + private ArrayList<Integer> relation3; + private ArrayList<Integer> relation4; + private ArrayList<Integer> trash; private DownloadedGame game; public GamePlayed() { - relation1 = new ArrayList<String>(); - relation2 = new ArrayList<String>(); - relation3 = new ArrayList<String>(); - relation4 = new ArrayList<String>(); - trash = new ArrayList<String>(); + relation1 = new ArrayList<Integer>(); + relation2 = new ArrayList<Integer>(); + relation3 = new ArrayList<Integer>(); + relation4 = new ArrayList<Integer>(); + trash = new ArrayList<Integer>(); } public void setGame(DownloadedGame game) { @@ -37,7 +37,7 @@ public class GamePlayed implements Serializable { return game; } - public void add(int relation, String word) { + public void add(int relation, int word) { switch (relation) { case 1: relation1.add(word); break; case 2: relation2.add(word); break; @@ -50,72 +50,36 @@ public class GamePlayed implements Serializable { /** * @return the relation1 */ - public ArrayList<String> getRelation1() { + public ArrayList<Integer> getRelation1() { return relation1; } /** * @return the relation2 */ - public ArrayList<String> getRelation2() { + public ArrayList<Integer> getRelation2() { return relation2; } /** * @return the relation3 */ - public ArrayList<String> getRelation3() { + public ArrayList<Integer> getRelation3() { return relation3; } /** * @return the relation4 */ - public ArrayList<String> getRelation4() { + public ArrayList<Integer> getRelation4() { return relation4; } /** * @return the trash */ - public ArrayList<String> getTrash() { + public ArrayList<Integer> getTrash() { return trash; } - - /** - * @param relation1 the relation1 to set - */ - public void setRelation1(ArrayList<String> relation1) { - this.relation1 = relation1; - } - - /** - * @param relation2 the relation2 to set - */ - public void setRelation2(ArrayList<String> relation2) { - this.relation2 = relation2; - } - - /** - * @param relation3 the relation3 to set - */ - public void setRelation3(ArrayList<String> relation3) { - this.relation3 = relation3; - } - - /** - * @param relation4 the relation4 to set - */ - public void setRelation4(ArrayList<String> relation4) { - this.relation4 = relation4; - } - - /** - * @param trash the trash to set - */ - public void setTrash(ArrayList<String> trash) { - this.trash = trash; - } - } diff --git a/code/PtiClic/src/org/pticlic/model/Network.java b/code/PtiClic/src/org/pticlic/model/Network.java @@ -21,24 +21,24 @@ public class Network { public enum Action { GET_GAMES } - + public enum Mode { SIMPLE_GAME("normal"); - + private final String value; - + Mode(String value) { this.value = value; } - + private String value() { return value; } } - + private Mode mode; private String serverURL; private String id; private String passwd; - + /** * Constructeur * @@ -53,7 +53,7 @@ public class Network { this.id = id; this.passwd = passwd; } - + /** * Cette méthode permet de récupérer du serveur un certain nombre de parties. * @param nbGames Le nombre de parties que l'on veut récupérer. @@ -69,10 +69,10 @@ public class Network { connection.addRequestProperty("passwd", this.passwd); connection.addRequestProperty("nb", String.valueOf(nbGames)); connection.addRequestProperty("mode", mode.value()); - + Gson gson = new Gson(); JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); - + // FIXME : Attention lorsque l'on pourra vraiment recupere plusieur partie, il faudra changer ce qui suit. reader.beginArray(); while (reader.hasNext()) { @@ -85,10 +85,10 @@ public class Network { return null; } - + return game; } - + /** * Permet la transformation du Json en une instance de Game. * @@ -105,7 +105,7 @@ public class Network { int cat4 = -1; DownloadedGame.Word center = null; DownloadedGame.Word[] cloud = null; - + reader.beginObject(); while (reader != null && reader.hasNext()) { String name = reader.nextName(); @@ -130,8 +130,8 @@ public class Network { reader.endObject(); return new DownloadedGame(id, cat1, cat2, cat3, cat4, center, cloud); } - - + + /** * Cette méthode permet d'envoyer les parties au serveur pour qu'il puisse les * rajouter à la base de données, et calculer le score. @@ -147,30 +147,37 @@ public class Network { connection.addRequestProperty("user", this.id); connection.addRequestProperty("passwd", this.passwd); connection.addRequestProperty("mode", mode.value()); - + if (game.getGame().getCat1() != -1) { -// for (game.getRelation1()) -// connection.addRequestProperty("cat1[]", newValue); + for (Integer i : game.getRelation1()) { + connection.addRequestProperty("cat1[]", i.toString()); + } } if (game.getGame().getCat2() != -1) { - + for (Integer i : game.getRelation2()) { + connection.addRequestProperty("cat2[]", i.toString()); + } } if (game.getGame().getCat3() != -1) { - + for (Integer i : game.getRelation3()) { + connection.addRequestProperty("cat3[]", i.toString()); + } } if (game.getGame().getCat4() != -1) { - + for (Integer i : game.getRelation4()) { + connection.addRequestProperty("cat4[]", i.toString()); + } + } + for (Integer i : game.getTrash()) { + connection.addRequestProperty("trash[]", i.toString()); } Gson gson = new Gson(); - String json = gson.toJson(game); - - connection.addRequestProperty("json", json); 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, DownloadedScore.class); + } catch (IOException e) { return score; }