www

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

commit 3bb6f98e483751b09d8ea024d822772394df9725
parent bfa301206893018d8af33637413c01b24b061180
Author: Bertrand BRUN <bertrand0brun@gmail.com>
Date:   Wed,  9 Feb 2011 13:51:49 +0100

Ajout d'abstraction au niveau de la classe DownloadedGame, pour que les prochaine mode de jeux puissent s'implementer plus facilement + ajout du nombre de mot restant dans le mode normal.
Diffstat:
Mcode/PtiClic/res/layout/game.xml | 51+++++++++++++++++++++++++++++----------------------
Mcode/PtiClic/src/org/pticlic/games/BaseGame.java | 29+++++++++++++++++------------
Acode/PtiClic/src/org/pticlic/model/DownloadedBaseGame.java | 153+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcode/PtiClic/src/org/pticlic/model/DownloadedGame.java | 144++++++-------------------------------------------------------------------------
Mcode/PtiClic/src/org/pticlic/model/Network.java | 18+++++++++---------
5 files changed, 219 insertions(+), 176 deletions(-)

diff --git a/code/PtiClic/res/layout/game.xml b/code/PtiClic/res/layout/game.xml @@ -7,8 +7,15 @@ android:layout_height="fill_parent" android:orientation="vertical" android:layout_weight="2"> - <AbsoluteLayout android:layout_width="fill_parent" - android:layout_height="wrap_content" android:paddingTop="10px"> + <LinearLayout android:layout_width="fill_parent" + android:layout_height="wrap_content" android:paddingTop="10px" + android:orientation="horizontal"> + + <TextView android:id="@+id/wordRemaining" android:text="0/10" + android:textStyle="bold" android:paddingTop="10px" + android:paddingLeft="20px" android:layout_height="wrap_content" + android:layout_width="wrap_content"> + </TextView> <TextView android:id="@+id/mainWord" android:text="mainWord" android:textStyle="bold" android:textSize="30dip" @@ -16,17 +23,12 @@ android:paddingTop="10px" android:layout_height="fill_parent" android:layout_width="fill_parent"> </TextView> - - <LinearLayout android:layout_width="fill_parent" - android:layout_height="fill_parent" android:gravity="right"> - <ImageView android:src="@drawable/aide" android:id="@+id/aideBaseGame" - android:paddingRight="10px" android:layout_width="wrap_content" - android:layout_height="wrap_content"></ImageView> + <ImageView android:src="@drawable/aide" android:id="@+id/aideBaseGame" + android:paddingRight="10px" android:layout_width="wrap_content" + android:layout_height="wrap_content"></ImageView> - </LinearLayout> - - </AbsoluteLayout> + </LinearLayout> <TextView android:id="@+id/currentWord" android:layout_width="fill_parent" android:text="currentWord" android:textStyle="bold" android:textSize="20dip" @@ -41,7 +43,8 @@ <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" - android:id="@+id/relation1Layout" android:layout_weight="1" android:layout_gravity="center"> + android:id="@+id/relation1Layout" android:layout_weight="1" + android:layout_gravity="center"> <ImageView android:id="@+id/relation1" android:src="@drawable/contenant" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content"> @@ -53,10 +56,11 @@ android:layout_gravity="center_vertical" android:visibility="gone"> </TextView> </LinearLayout> - + <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" - android:id="@+id/relation2Layout" android:layout_weight="1" android:layout_gravity="center"> + android:id="@+id/relation2Layout" android:layout_weight="1" + android:layout_gravity="center"> <ImageView android:id="@+id/relation2" android:src="@drawable/contenu" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content"> @@ -68,10 +72,11 @@ android:layout_gravity="center_vertical" android:visibility="gone"> </TextView> </LinearLayout> - + <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" - android:id="@+id/relation3Layout" android:layout_weight="1" android:layout_gravity="center"> + android:id="@+id/relation3Layout" android:layout_weight="1" + android:layout_gravity="center"> <ImageView android:id="@+id/relation3" android:src="@drawable/contraire" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content"> @@ -83,10 +88,11 @@ android:layout_gravity="center_vertical" android:visibility="gone"> </TextView> </LinearLayout> - + <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" - android:id="@+id/relation4Layout" android:layout_weight="1" android:layout_gravity="center"> + android:id="@+id/relation4Layout" android:layout_weight="1" + android:layout_gravity="center"> <ImageView android:id="@+id/relation4" android:src="@drawable/synonyme" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center"> @@ -98,11 +104,12 @@ android:layout_gravity="center_vertical" android:visibility="gone"> </TextView> </LinearLayout> - + <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" - android:id="@+id/trashLayout" android:layout_weight="1" android:layout_gravity="center"> - + android:id="@+id/trashLayout" android:layout_weight="1" + android:layout_gravity="center"> + <ImageView android:id="@+id/trash" android:src="@android:drawable/ic_menu_delete" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center"> @@ -113,7 +120,7 @@ android:layout_gravity="center_vertical" android:visibility="gone"> </TextView> </LinearLayout> - + </LinearLayout> </LinearLayout> diff --git a/code/PtiClic/src/org/pticlic/games/BaseGame.java b/code/PtiClic/src/org/pticlic/games/BaseGame.java @@ -3,7 +3,7 @@ package org.pticlic.games; import org.pticlic.R; import org.pticlic.Score; import org.pticlic.model.Constant; -import org.pticlic.model.DownloadedGame; +import org.pticlic.model.DownloadedBaseGame; import org.pticlic.model.Match; import org.pticlic.model.Network; import org.pticlic.model.Network.Mode; @@ -42,13 +42,14 @@ import android.widget.TextView; */ public class BaseGame extends Activity implements OnClickListener { - private int currentWord = 0; - private TextView currentWordTextView; - private int nbWord = 0; - private DownloadedGame game; - private Match match; - private Network network; - private boolean help = false; + private int currentWord = 0; + private TextView currentWordTextView; + private TextView wordRemaining; + private int nbWord = 0; + private DownloadedBaseGame game; + private Match match; + private Network network; + private boolean help = false; /** Called when the activity is first created. */ @Override @@ -75,7 +76,7 @@ public class BaseGame extends Activity implements OnClickListener { protected void onStart() { super.onStart(); - game = network.getGames(1); + game = (DownloadedBaseGame)network.getGames(1); runMatch(); start(); } @@ -83,7 +84,10 @@ public class BaseGame extends Activity implements OnClickListener { private void runMatch() { int nbrel = game.getNbRelation(); nbWord = game.getNbWord(); - + + wordRemaining = (TextView)findViewById(R.id.wordRemaining); + wordRemaining.setText((currentWord + 1) + "/" + nbWord); + // On initialise la partie. match = new Match(); match.setGame(game); @@ -167,7 +171,7 @@ public class BaseGame extends Activity implements OnClickListener { rl4.setVisibility(View.GONE); } - ((TextView)findViewById(R.id.mainWord)).setText(DownloadedGame.getName(game.getCentre())); + ((TextView)findViewById(R.id.mainWord)).setText(DownloadedBaseGame.getName(game.getCentre())); } /* (non-Javadoc) @@ -223,7 +227,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(DownloadedGame.getName(game.getWordInCloud(currentWord))); + ((TextView)findViewById(R.id.currentWord)).setText(DownloadedBaseGame.getName(game.getWordInCloud(currentWord))); arrivalView(); } @@ -232,6 +236,7 @@ public class BaseGame extends Activity implements OnClickListener { */ private void next() { if (++currentWord < nbWord) { + wordRemaining.setText((currentWord + 1) + "/" + nbWord); leaveView(); start(); } else { diff --git a/code/PtiClic/src/org/pticlic/model/DownloadedBaseGame.java b/code/PtiClic/src/org/pticlic/model/DownloadedBaseGame.java @@ -0,0 +1,153 @@ +package org.pticlic.model; + +import java.io.Serializable; +import java.util.Arrays; + +/** + * @author Bertrand BRUN + * + * Classe metier reprensentant une parti "Normal" telecharge. + */ +public class DownloadedBaseGame extends DownloadedGame { + + private static final long serialVersionUID = 1L; + + public static class Word implements Serializable { + + private static final long serialVersionUID = 1L; + private int id; + private String name; + + public Word() {} + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + private int cat1; + private int cat2; + private int cat3; + private int cat4; + private Word center; + private Word[] cloud; + + public DownloadedBaseGame() { + super(); + this.cat1 = -1; + this.cat2 = -1; + this.cat3 = -1; + this.cat4 = -1; + this.center = null; + this.cloud = null; + } + + public DownloadedBaseGame(int id, int gid, int pgid, int cat1, int cat2, + int cat3, int cat4, Word center, Word[] cloud) { + super(id, gid, pgid); + this.cat1 = cat1; + this.cat2 = cat2; + this.cat3 = cat3; + this.cat4 = cat4; + this.center = center; + this.cloud = cloud; + } + + /** + * Permet de recupere le nombre de relation que l'on va utiliser. + * + * @return le nombre de relation + */ + public int getNbRelation() { + int res = 0; + + if (cat1 != -1) { + res++; + } + if (cat2 != -1) { + res++; + } + if (cat3 != -1) { + res++; + } + if (cat4 != -1) { + res++; + } + + return res; + } + + public static String getName(Word word) { + return word.getName(); + } + + public int getCat1() { + return cat1; + } + + public void setCat1(int cat1) { + this.cat1 = cat1; + } + + public int getCat2() { + return cat2; + } + + public void setCat2(int cat2) { + this.cat2 = cat2; + } + + public int getCat3() { + return cat3; + } + + public void setCat3(int cat3) { + this.cat3 = cat3; + } + + public int getCat4() { + return cat4; + } + + public void setCat4(int cat4) { + this.cat4 = cat4; + } + + public Word getCentre() { + return center; + } + + public void setCentre(Word center) { + this.center = center; + } + + public int getNbWord() { + return cloud.length; + } + + public Word getWordInCloud(int index) { + return cloud[index]; + } + + + @Override + public String toString() { + return "DownloadedBaseGame [gid=" + gid + ", pgid=" + pgid + ", id=" + id + + ", cat1=" + cat1 + ", cat2=" + cat2 + ", cat3=" + cat3 + + ", cat4=" + cat4 + ", center=" + center + ", cloud=" + + Arrays.toString(cloud) + "]"; + } + +} diff --git a/code/PtiClic/src/org/pticlic/model/DownloadedGame.java b/code/PtiClic/src/org/pticlic/model/DownloadedGame.java @@ -1,101 +1,35 @@ package org.pticlic.model; import java.io.Serializable; -import java.util.Arrays; /** * @author Bertrand BRUN * - * Classe metier reprensentant le jeu telecharger du serveur. + * Classe metier reprensentant n'importe quel le jeu telecharger du serveur. * */ -public class DownloadedGame implements Serializable { +public abstract class DownloadedGame implements Serializable { private static final long serialVersionUID = 1L; - public static class Word implements Serializable { - - private static final long serialVersionUID = 1L; - private int id; - private String name; - - public Word() {} - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - } - - private int gid; - private int pgid; - private int id; - private int cat1; - private int cat2; - private int cat3; - private int cat4; - private Word center; - private Word[] cloud; - + protected int gid; + protected int pgid; + protected int id; - public DownloadedGame() {} + public DownloadedGame() { + this.id = -1; + this.gid = -1; + this.pgid = -1; + } - public DownloadedGame(int id, int gid, int pgid, int cat1, int cat2, int cat3, int cat4, Word center, - Word[] cloud) { + public DownloadedGame(int id, int gid, int pgid) { super(); this.id = id; this.gid = gid; this.pgid = pgid; - this.cat1 = cat1; - this.cat2 = cat2; - this.cat3 = cat3; - this.cat4 = cat4; - this.center = center; - this.cloud = cloud; - } - - /** - * Permet de recupere le nombre de relation que l'on va utiliser. - * - * @return le nombre de relation - */ - public int getNbRelation() { - int res = 0; - - if (cat1 != -1) { - res++; - } - if (cat2 != -1) { - res++; - } - if (cat3 != -1) { - res++; - } - if (cat4 != -1) { - res++; - } - - return res; } - public static String getName(Word word) { - return word.getName(); - } - - - public int getGid() { return gid; } @@ -119,61 +53,5 @@ public class DownloadedGame implements Serializable { public void setId(int id) { this.id = id; } - - public int getCat1() { - return cat1; - } - - public void setCat1(int cat1) { - this.cat1 = cat1; - } - - public int getCat2() { - return cat2; - } - - public void setCat2(int cat2) { - this.cat2 = cat2; - } - - public int getCat3() { - return cat3; - } - - public void setCat3(int cat3) { - this.cat3 = cat3; - } - - public int getCat4() { - return cat4; - } - - public void setCat4(int cat4) { - this.cat4 = cat4; - } - - public Word getCentre() { - return center; - } - - public void setCentre(Word center) { - this.center = center; - } - - public int getNbWord() { - return cloud.length; - } - - public Word getWordInCloud(int index) { - return cloud[index]; - } - - @Override - public String toString() { - return "DownloadedGame [gid=" + gid + ", pgid=" + pgid + ", id=" + id - + ", cat1=" + cat1 + ", cat2=" + cat2 + ", cat3=" + cat3 - + ", cat4=" + cat4 + ", center=" + center + ", cloud=" - + Arrays.toString(cloud) + "]"; - } } diff --git a/code/PtiClic/src/org/pticlic/model/Network.java b/code/PtiClic/src/org/pticlic/model/Network.java @@ -179,8 +179,8 @@ public class Network { int cat2 = -1; int cat3 = -1; int cat4 = -1; - DownloadedGame.Word center = null; - DownloadedGame.Word[] cloud = null; + DownloadedBaseGame.Word center = null; + DownloadedBaseGame.Word[] cloud = null; reader.beginObject(); while (reader.hasNext()) { @@ -200,15 +200,15 @@ public class Network { } else if (name.equals("cat4")) { cat4 = reader.nextInt(); } else if (name.equals("center")) { - center = gson.fromJson(reader, DownloadedGame.Word.class); + center = gson.fromJson(reader, DownloadedBaseGame.Word.class); } else if (name.equals("cloud")) { - cloud = gson.fromJson(reader, DownloadedGame.Word[].class); + cloud = gson.fromJson(reader, DownloadedBaseGame.Word[].class); } else { reader.skipValue(); } } reader.endObject(); - return new DownloadedGame(id, gid, pgid, cat1, cat2, cat3, cat4, center, cloud); + return new DownloadedBaseGame(id, gid, pgid, cat1, cat2, cat3, cat4, center, cloud); } @@ -229,22 +229,22 @@ public class Network { connection.addRequestProperty("mode", mode.value()); connection.addRequestProperty("pgid", String.valueOf(game.getGame().getId())); - if (game.getGame().getCat1() != -1) { + if (((DownloadedBaseGame)game.getGame()).getCat1() != -1) { for (Integer i : game.getRelation1()) { connection.addRequestProperty("cat1[]", i.toString()); } } - if (game.getGame().getCat2() != -1) { + if (((DownloadedBaseGame)game.getGame()).getCat2() != -1) { for (Integer i : game.getRelation2()) { connection.addRequestProperty("cat2[]", i.toString()); } } - if (game.getGame().getCat3() != -1) { + if (((DownloadedBaseGame)game.getGame()).getCat3() != -1) { for (Integer i : game.getRelation3()) { connection.addRequestProperty("cat3[]", i.toString()); } } - if (game.getGame().getCat4() != -1) { + if (((DownloadedBaseGame)game.getGame()).getCat4() != -1) { for (Integer i : game.getRelation4()) { connection.addRequestProperty("cat4[]", i.toString()); }