diff --git a/code/PtiClic/AndroidManifest.xml b/code/PtiClic/AndroidManifest.xml
index 62efc1d..e375dd7 100644
--- a/code/PtiClic/AndroidManifest.xml
+++ b/code/PtiClic/AndroidManifest.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/code/PtiClic/res/layout/game.xml b/code/PtiClic/res/layout/game.xml
index a324591..b629152 100644
--- a/code/PtiClic/res/layout/game.xml
+++ b/code/PtiClic/res/layout/game.xml
@@ -15,10 +15,7 @@
android:layout_height="wrap_content" android:text="currentWord"
android:textStyle="bold" android:gravity="center">
-
-
+
diff --git a/code/PtiClic/src/model/GamePlayed.java b/code/PtiClic/src/model/GamePlayed.java
deleted file mode 100644
index 6d83c81..0000000
--- a/code/PtiClic/src/model/GamePlayed.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package model;
-
-import java.util.Arrays;
-
-public class GamePlayed {
-
- private int id;
- private String centre;
- private String[] cloud;
- private String[] category;
- private static GamePlayed instance = null;
-
- private GamePlayed(){
- this.id = -1;
- this.centre = "";
- this.cloud = null;
- this.category = null;
- }
-
- private GamePlayed(int id, String centre, String[] cloud, String[] category) {
- this.id = id;
- this.centre = centre;
- this.cloud = cloud;
- this.category = category;
- }
-
- public final static GamePlayed getInstance(){
- if(instance == null) instance = new GamePlayed();
- return instance;
- }
-
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getCentre() {
- return centre;
- }
- public void setCentre(String centre) {
- this.centre = centre;
- }
- public String[] getCloud() {
- return cloud;
- }
- public void setCloud(String[] cloud) {
- this.cloud = cloud;
- }
- public String[] getCategory() {
- return category;
- }
- public void setCategory(String[] category) {
- this.category = category;
- }
-
- @Override
- public String toString() {
- return "GamePlayed [id=" + id + ", centre=" + centre + ", cloud="
- + Arrays.toString(cloud) + ", category=" + category + "]";
- }
-}
diff --git a/code/PtiClic/src/org/pticlic/Game.java b/code/PtiClic/src/org/pticlic/Game.java
deleted file mode 100644
index 3bfc6f3..0000000
--- a/code/PtiClic/src/org/pticlic/Game.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package org.pticlic;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.TextView;
-
-public class Game extends Activity implements OnClickListener {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- int nbrel = 2;
- setContentView(R.layout.game);
-
- // 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));
-
- // É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); }
-
- r1.setText("=");
- r2.setText("∈");
- ((TextView)findViewById(R.id.mainWord)).setText("Chat");
- ((TextView)findViewById(R.id.currentWord)).setText("Matou");
- }
-
- /* (non-Javadoc)
- * @see android.view.View.OnClickListener#onClick(android.view.View)
- */
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case (R.id.relation1) : break;
- case (R.id.relation2) : break;
- case (R.id.relation3) : break;
- case (R.id.relation4) : break;
- }
- }
-}
\ No newline at end of file
diff --git a/code/PtiClic/src/org/pticlic/Main.java b/code/PtiClic/src/org/pticlic/Main.java
index e658c58..abeaaa8 100644
--- a/code/PtiClic/src/org/pticlic/Main.java
+++ b/code/PtiClic/src/org/pticlic/Main.java
@@ -1,5 +1,7 @@
package org.pticlic;
+import org.pticlic.games.BaseGame;
+
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -35,7 +37,7 @@ public class Main extends Activity implements OnClickListener {
public void onClick(View v) {
switch (v.getId()) {
case (R.id.prefs) : startActivity(new Intent(this, Preference.class)); break;
- case (R.id.play) : startActivity(new Intent(this, Game.class)); break;
+ case (R.id.play) : startActivity(new Intent(this, BaseGame.class)); break;
}
if (v.getId()==R.id.voirscore){
// TODO: à supprimer
diff --git a/code/PtiClic/src/org/pticlic/games/BaseGame.java b/code/PtiClic/src/org/pticlic/games/BaseGame.java
new file mode 100644
index 0000000..0049dfc
--- /dev/null
+++ b/code/PtiClic/src/org/pticlic/games/BaseGame.java
@@ -0,0 +1,123 @@
+package org.pticlic.games;
+
+import org.pticlic.R;
+import org.pticlic.model.Constant;
+import org.pticlic.model.Game;
+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.Display;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.animation.AlphaAnimation;
+import android.view.animation.AnimationSet;
+import android.view.animation.TranslateAnimation;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class BaseGame extends Activity implements OnClickListener {
+ private int currentWord = 0;
+ private int nbWord = 0;
+ private Game game;
+ private GamePlayed gamePlayed;
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.game);
+
+ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
+ String serverURL = sp.getString(Constant.SERVER_URL, "http://serveur/pticlic.php");
+
+ Network network = new Network(serverURL, Mode.SIMPLE_GAME);
+ game = network.getGames(1);
+ int nbrel = game.getNbRelation();
+ nbWord = game.getNbWord();
+
+ gamePlayed = new GamePlayed();
+ gamePlayed.setGame(game);
+
+ // 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));
+
+ // É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); }
+
+ r1.setText("=");
+ r2.setText("Poubelle");
+ r3.setText("∈");
+ ((TextView)findViewById(R.id.mainWord)).setText(Game.getName(game.getCentre()));
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+
+ start();
+ }
+
+ private void arrivalView() {
+ //On recupere la largueur de l'ecran.
+ Display display = getWindowManager().getDefaultDisplay();
+ int width = display.getWidth();
+
+ //On recupere le centre de mainWord pour l'animation de translation.
+ TextView mainWord = (TextView)findViewById(R.id.mainWord);
+
+ // On defini un ensemble d'animation
+ AnimationSet set = new AnimationSet(true);
+ set.setFillAfter(true);
+ set.setDuration(1000);
+
+ TranslateAnimation translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 2);
+ translate.setDuration(1000);
+ set.addAnimation(translate);
+
+ AlphaAnimation alpha = new AlphaAnimation(.1f, 1);
+ alpha.setDuration(1000);
+ set.addAnimation(alpha);
+
+ // Que l'on rajoute a notre vue.
+ findViewById(R.id.currentWord).startAnimation(set);
+ }
+
+ private void start() {
+ ((TextView)findViewById(R.id.currentWord)).setText(Game.getName(game.getWordInCloud(currentWord)));
+ arrivalView();
+ }
+
+ private void next() {
+ if (currentWord < nbWord) {
+ currentWord++;
+ start();
+ } else {
+ //TODO : Ajout l'envoie de GamePlayed a Score
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see android.view.View.OnClickListener#onClick(android.view.View)
+ */
+ @Override
+ public void onClick(View v) {
+ CharSequence currentWord = ((TextView)findViewById(R.id.currentWord)).getText();
+ switch (v.getId()) {
+ case (R.id.relation1) : gamePlayed.add(1, currentWord); next(); break;
+ case (R.id.relation2) : gamePlayed.add(2, currentWord); next(); break;
+ case (R.id.relation3) : gamePlayed.add(3, currentWord); next(); break;
+ case (R.id.relation4) : gamePlayed.add(4, currentWord); next(); break;
+ }
+ }
+}
\ No newline at end of file
diff --git a/code/PtiClic/src/org/pticlic/model/Game.java b/code/PtiClic/src/org/pticlic/model/Game.java
index 963bde1..7a0036b 100644
--- a/code/PtiClic/src/org/pticlic/model/Game.java
+++ b/code/PtiClic/src/org/pticlic/model/Game.java
@@ -3,7 +3,7 @@ package org.pticlic.model;
public class Game {
- static class Word {
+ public static class Word {
private int id;
private String name;
@@ -109,12 +109,12 @@ public class Game {
this.center = center;
}
- public Game.Word[] getCloud() {
- return cloud;
+ public int getNbWord() {
+ return cloud.length;
}
-
- public void setCloud(Game.Word[] cloud) {
- this.cloud = cloud;
+
+ public Game.Word getWordInCloud(int index) {
+ return cloud[index];
}
@Override
diff --git a/code/PtiClic/src/org/pticlic/model/GamePlayed.java b/code/PtiClic/src/org/pticlic/model/GamePlayed.java
new file mode 100644
index 0000000..8eba77c
--- /dev/null
+++ b/code/PtiClic/src/org/pticlic/model/GamePlayed.java
@@ -0,0 +1,32 @@
+package org.pticlic.model;
+
+import java.util.ArrayList;
+
+public class GamePlayed {
+ private ArrayList relation1;
+ private ArrayList relation2;
+ private ArrayList relation3;
+ private ArrayList relation4;
+ private Game game;
+
+ public GamePlayed() {
+ relation1 = new ArrayList();
+ relation2 = new ArrayList();
+ relation3 = new ArrayList();
+ relation4 = new ArrayList();
+ }
+
+ public void setGame(Game game) {
+ this.game = 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;
+ }
+ }
+
+}
diff --git a/code/PtiClic/src/org/pticlic/model/Network.java b/code/PtiClic/src/org/pticlic/model/Network.java
index a51acd9..d376771 100644
--- a/code/PtiClic/src/org/pticlic/model/Network.java
+++ b/code/PtiClic/src/org/pticlic/model/Network.java
@@ -1,12 +1,10 @@
package org.pticlic.model;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import com.google.gson.Gson;
-import com.google.gson.stream.JsonReader;
public class Network {