www

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

commit 339c1fb4663ba3ee1d6f2c7a0457e0f7c0a56e9e
parent dfa0ae5c1057d423f7b20e9effe17fba5940e5f0
Author: Bertrand BRUN <bertrand0brun@gmail.com>
Date:   Sat, 29 Jan 2011 18:25:47 +0100

Changement de nom Game devient BaseGame
La classe Network est normalement fini reste a la tester sur le serveur
Deplacement de GamePlayed de model a org.pticlic.model et modification du code de celle-ci.
Modification dans la vue de game.xml
Ajout des animation dans BaseGame
Diffstat:
Mcode/PtiClic/AndroidManifest.xml | 2+-
Mcode/PtiClic/res/layout/game.xml | 5+----
Dcode/PtiClic/src/model/GamePlayed.java | 62--------------------------------------------------------------
Dcode/PtiClic/src/org/pticlic/Game.java | 49-------------------------------------------------
Mcode/PtiClic/src/org/pticlic/Main.java | 4+++-
Acode/PtiClic/src/org/pticlic/games/BaseGame.java | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcode/PtiClic/src/org/pticlic/model/Game.java | 12++++++------
Acode/PtiClic/src/org/pticlic/model/GamePlayed.java | 32++++++++++++++++++++++++++++++++
Mcode/PtiClic/src/org/pticlic/model/Network.java | 2--
9 files changed, 167 insertions(+), 125 deletions(-)

diff --git a/code/PtiClic/AndroidManifest.xml b/code/PtiClic/AndroidManifest.xml @@ -12,7 +12,7 @@ </activity> <activity android:name=".Preference" android:label="Préférence"></activity> - <activity android:name=".Game"></activity> + <activity android:name=".games.BaseGame"></activity> <activity android:name=".Info" android:label="Information"></activity> <activity android:name=".Score" android:label="Score"></activity> </application> diff --git 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"> </TextView> - <TextView android:text="secondWord" android:id="@+id/secondWord" - android:layout_width="fill_parent" android:layout_height="wrap_content" - android:textStyle="bold" android:gravity="center" android:visibility="gone"> - </TextView> + </LinearLayout> diff --git a/code/PtiClic/src/model/GamePlayed.java b/code/PtiClic/src/model/GamePlayed.java @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -0,0 +1,32 @@ +package org.pticlic.model; + +import java.util.ArrayList; + +public class GamePlayed { + private ArrayList<CharSequence> relation1; + private ArrayList<CharSequence> relation2; + private ArrayList<CharSequence> relation3; + private ArrayList<CharSequence> relation4; + private Game game; + + public GamePlayed() { + relation1 = new ArrayList<CharSequence>(); + relation2 = new ArrayList<CharSequence>(); + relation3 = new ArrayList<CharSequence>(); + relation4 = new ArrayList<CharSequence>(); + } + + 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 @@ -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 {