Changement d'interface graphique
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Activité de fin de partie
|
||||
* Affiche un résumé de la partie et permet de rejouer ou retourner à l'accueil
|
||||
*/
|
||||
public class EndGameActivity extends AppCompatActivity {
|
||||
|
||||
// Vues
|
||||
private TextView questionsPlayedValue;
|
||||
private TextView playersCountValue;
|
||||
private TextView gorgeesTotalValue;
|
||||
private MaterialButton homeButton;
|
||||
private MaterialButton replayButton;
|
||||
|
||||
// Données
|
||||
private int questionsPlayed;
|
||||
private int playersCount;
|
||||
private ArrayList<String> players;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_end_game);
|
||||
|
||||
// Initialiser les vues
|
||||
initViews();
|
||||
|
||||
// Récupérer les données de la partie
|
||||
getGameData();
|
||||
|
||||
// Afficher les statistiques
|
||||
displayStats();
|
||||
|
||||
// Configurer les boutons
|
||||
setupButtons();
|
||||
|
||||
// Animations d'entrée
|
||||
animateEntry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise toutes les vues
|
||||
*/
|
||||
private void initViews() {
|
||||
questionsPlayedValue = findViewById(R.id.questionsPlayedValue);
|
||||
playersCountValue = findViewById(R.id.playersCountValue);
|
||||
gorgeesTotalValue = findViewById(R.id.gorgeesTotalValue);
|
||||
homeButton = findViewById(R.id.homeButton);
|
||||
replayButton = findViewById(R.id.replayButton);
|
||||
|
||||
// Appliquer les animations aux boutons
|
||||
BoideloAnimationUtils.applyButtonPressAnimation(homeButton);
|
||||
BoideloAnimationUtils.applyButtonPressAnimation(replayButton);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les données de la partie terminée
|
||||
*/
|
||||
private void getGameData() {
|
||||
// Récupérer les données depuis l'intent
|
||||
questionsPlayed = getIntent().getIntExtra("EXTRA_QUESTIONS_PLAYED", 0);
|
||||
playersCount = getIntent().getIntExtra("EXTRA_PLAYERS_COUNT", 0);
|
||||
players = getIntent().getStringArrayListExtra("EXTRA_PLAYERS");
|
||||
|
||||
// Si pas de données, utiliser les SharedPreferences
|
||||
if (questionsPlayed == 0) {
|
||||
android.content.SharedPreferences prefs = getSharedPreferences("game_stats", Context.MODE_PRIVATE);
|
||||
questionsPlayed = prefs.getInt("questions_played", 0);
|
||||
playersCount = prefs.getInt("players_count", 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche les statistiques de la partie
|
||||
*/
|
||||
private void displayStats() {
|
||||
// Animer les chiffres
|
||||
animateValue(questionsPlayedValue, 0, questionsPlayed, 1000);
|
||||
animateValue(playersCountValue, 0, playersCount, 1000);
|
||||
|
||||
// Afficher les joueurs (simplifié pour l'instant)
|
||||
if (players != null && !players.isEmpty()) {
|
||||
StringBuilder playersText = new StringBuilder();
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
if (i > 0) playersText.append(", ");
|
||||
playersText.append(players.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Afficher un message de félicitations
|
||||
showCongratulationMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche un message de félicitations selon le nombre de questions
|
||||
*/
|
||||
private void showCongratulationMessage() {
|
||||
// Le message pourrait être personnalisé selon les performances
|
||||
// Pour l'instant, on utilise le titre par défaut du layout
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure les boutons
|
||||
*/
|
||||
private void setupButtons() {
|
||||
homeButton.setOnClickListener(v -> {
|
||||
BoideloAnimationUtils.triggerHapticFeedback(this);
|
||||
goToHome();
|
||||
});
|
||||
|
||||
replayButton.setOnClickListener(v -> {
|
||||
BoideloAnimationUtils.triggerSuccessHaptic(this);
|
||||
replay();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne à l'écran d'accueil
|
||||
*/
|
||||
private void goToHome() {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Relance une nouvelle partie
|
||||
*/
|
||||
private void replay() {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime l'entrée des éléments
|
||||
*/
|
||||
private void animateEntry() {
|
||||
// Animation du trophée
|
||||
View trophyIcon = findViewById(R.id.trophyIcon);
|
||||
BoideloAnimationUtils.scale(trophyIcon, 1.0f, 400);
|
||||
|
||||
// Animation fade-in pour le contenu
|
||||
View titleText = findViewById(R.id.titleText);
|
||||
View subtitleText = findViewById(R.id.subtitleText);
|
||||
|
||||
BoideloAnimationUtils.fadeIn(titleText, 600);
|
||||
BoideloAnimationUtils.fadeIn(subtitleText, 800);
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime un chiffre de 0 à la valeur cible
|
||||
*/
|
||||
private void animateValue(TextView textView, int start, int end, int duration) {
|
||||
if (textView == null) return;
|
||||
|
||||
android.animation.ValueAnimator animator = android.animation.ValueAnimator.ofInt(start, end);
|
||||
animator.setDuration(duration);
|
||||
animator.setInterpolator(new DecelerateInterpolator());
|
||||
|
||||
animator.addUpdateListener(animation -> {
|
||||
int value = (int) animation.getAnimatedValue();
|
||||
textView.setText(String.valueOf(value));
|
||||
});
|
||||
|
||||
animator.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// Retourner à l'accueil au lieu de revenir au jeu
|
||||
goToHome();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user