Modification dans le mode normal. Manque encore l'affichage dynamique des noms des relations

This commit is contained in:
Bertrand BRUN 2011-02-01 04:02:18 +01:00
parent da5127cc2b
commit 5f166574b0
3 changed files with 58 additions and 38 deletions

View File

@ -28,6 +28,9 @@
<Button android:id="@+id/relation2"
android:text="relation2" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1" android:layout_gravity="bottom">
</Button>
<Button android:id="@+id/poubelle"
android:text="poubelle" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1" android:layout_gravity="bottom">
</Button>
<Button android:id="@+id/relation3"
android:text="relation3" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1" android:layout_gravity="bottom">
</Button>

View File

@ -27,51 +27,59 @@ public class BaseGame extends Activity implements OnClickListener {
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"); // TODO : Mettre comme valeur par defaut l'adresse reel du serveur
String serverURL = sp.getString(Constant.SERVER_URL, "http://dumbs.fr/~bbrun/pticlic.json"); // TODO : Mettre comme valeur par defaut l'adresse reel du serveur
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));
Button poubelle = ((Button)findViewById(R.id.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); }
//TODO : Faudrait gere dynamiquement la gestion des nom des relations.
r1.setText("=");
r2.setText("Poubelle");
r3.setText("");
r1.setText("Idée");
r2.setText("Partie");
poubelle.setText("Poubelle");
((TextView)findViewById(R.id.mainWord)).setText(Game.getName(game.getCentre()));
}
@Override
protected void onStart() {
super.onStart();
start();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
finish();
}
/**
* Cette methode permet au mot courant de partir du mot central vers le centre de l'appareil.
*/
@ -79,27 +87,27 @@ public class BaseGame extends Activity implements OnClickListener {
//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);
}
/**
* Cette methode permet de passer au mot courant suivant et de lancer l'animation.
*/
@ -107,7 +115,7 @@ public class BaseGame extends Activity implements OnClickListener {
((TextView)findViewById(R.id.currentWord)).setText(Game.getName(game.getWordInCloud(currentWord)));
arrivalView();
}
/**
* Permet de verifier si la partie est fini auquel cas on lance l'activite Score, sinon on passe au mot suivant.
*/
@ -117,10 +125,10 @@ public class BaseGame extends Activity implements OnClickListener {
} else {
Intent intent = new Intent(this, Score.class);
intent.putExtra(Constant.SCORE_INTENT, gamePlayed);
startActivity(intent);
startActivityForResult(intent, 0x100);
}
}
/* (non-Javadoc)
* @see android.view.View.OnClickListener#onClick(android.view.View)
*/

View File

@ -1,11 +1,12 @@
package org.pticlic.model;
import java.io.Serializable;
import java.util.ArrayList;
public class Game implements Serializable {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
public static class Word implements Serializable {
@ -32,16 +33,26 @@ public class Game implements Serializable {
}
}
private int id;
private int cat1;
private int cat2;
private int cat3;
private int cat4;
private Word center;
private Game.Word[] cloud;
private int id;
private int cat1;
private int cat2;
private int cat3;
private int cat4;
private Word center;
private Word[] cloud;
public Game() {
cloud = new Game.Word[3];
public Game(int id, int cat1, int cat2, int cat3, int cat4, Word center,
Word[] cloud) {
super();
this.id = id;
this.cat1 = cat1;
this.cat2 = cat2;
this.cat3 = cat3;
this.cat4 = cat4;
this.center = center;
this.cloud = cloud;
}
public int getNbRelation() {
@ -119,7 +130,7 @@ public class Game implements Serializable {
return cloud.length;
}
public Game.Word getWordInCloud(int index) {
public Word getWordInCloud(int index) {
return cloud[index];
}
@ -128,7 +139,5 @@ public class Game implements Serializable {
return "Game [id=" + id + ", cat1=" + cat1 + ", cat2=" + cat2
+ ", cat3=" + cat3 + ", cat4=" + cat4 + ", center=" + center
+ ", cloud=" + cloud + "]";
}
}
}