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
This commit is contained in:
parent
dfa0ae5c10
commit
339c1fb466
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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 + "]";
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
123
code/PtiClic/src/org/pticlic/games/BaseGame.java
Normal file
123
code/PtiClic/src/org/pticlic/games/BaseGame.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
32
code/PtiClic/src/org/pticlic/model/GamePlayed.java
Normal file
32
code/PtiClic/src/org/pticlic/model/GamePlayed.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user