Changement d'interface graphique
This commit is contained in:
@@ -0,0 +1,415 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
/**
|
||||
* Classe utilitaire pour les animations et effets visuels
|
||||
*/
|
||||
public class BoideloAnimationUtils {
|
||||
|
||||
private static final Interpolator OVERSHOOT = new OvershootInterpolator();
|
||||
|
||||
/**
|
||||
* Anime le changement de couleur de fond d'une vue
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param targetColor La couleur cible
|
||||
* @param duration La durée de l'animation en ms
|
||||
*/
|
||||
public static void animateBackgroundColor(View view, int targetColor, int duration) {
|
||||
if (view == null) return;
|
||||
|
||||
int currentColor = getBackgroundColor(view);
|
||||
if (currentColor == targetColor) return;
|
||||
|
||||
ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), currentColor, targetColor);
|
||||
anim.setDuration(duration);
|
||||
anim.addUpdateListener(animation -> {
|
||||
int color = (int) animation.getAnimatedValue();
|
||||
view.setBackgroundColor(color);
|
||||
});
|
||||
anim.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime le changement de couleur de fond avec la durée par défaut (500ms)
|
||||
*/
|
||||
public static void animateBackgroundColor(View view, int targetColor) {
|
||||
animateBackgroundColor(view, targetColor, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtient la couleur de fond actuelle d'une vue
|
||||
*/
|
||||
private static int getBackgroundColor(View view) {
|
||||
if (view.getBackground() instanceof ColorDrawable) {
|
||||
return ((ColorDrawable) view.getBackground()).getColor();
|
||||
}
|
||||
return 0xFFFFFFFF; // Blanc par défaut
|
||||
}
|
||||
|
||||
/**
|
||||
* Déclenche une vibration haptique
|
||||
*
|
||||
* @param context Le contexte
|
||||
* @param duration Durée de la vibration en ms
|
||||
*/
|
||||
public static void triggerHapticFeedback(Context context, int duration) {
|
||||
if (context == null) return;
|
||||
|
||||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (vibrator != null && vibrator.hasVibrator()) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
VibrationEffect effect = VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE);
|
||||
vibrator.vibrate(effect);
|
||||
} else {
|
||||
vibrator.vibrate(duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Déclenche une vibration haptique courte (100ms)
|
||||
*/
|
||||
public static void triggerHapticFeedback(Context context) {
|
||||
triggerHapticFeedback(context, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Déclenche une vibration haptique de succès
|
||||
*/
|
||||
public static void triggerSuccessHaptic(Context context) {
|
||||
if (context == null) return;
|
||||
|
||||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (vibrator != null && vibrator.hasVibrator() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
long[] pattern = {0, 50, 50, 50};
|
||||
VibrationEffect effect = VibrationEffect.createWaveform(pattern, -1);
|
||||
vibrator.vibrate(effect);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Déclenche une vibration haptique d'erreur
|
||||
*/
|
||||
public static void triggerErrorHaptic(Context context) {
|
||||
if (context == null) return;
|
||||
|
||||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (vibrator != null && vibrator.hasVibrator() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
long[] pattern = {0, 100, 50, 100};
|
||||
VibrationEffect effect = VibrationEffect.createWaveform(pattern, -1);
|
||||
vibrator.vibrate(effect);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime l'apparition d'une vue avec un effet de fade-in
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param duration Durée de l'animation
|
||||
*/
|
||||
public static void fadeIn(View view, int duration) {
|
||||
if (view == null) return;
|
||||
|
||||
view.setAlpha(0f);
|
||||
view.setVisibility(View.VISIBLE);
|
||||
view.animate()
|
||||
.alpha(1f)
|
||||
.setDuration(duration)
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime la disparition d'une vue avec un effet de fade-out
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param duration Durée de l'animation
|
||||
*/
|
||||
public static void fadeOut(View view, int duration) {
|
||||
if (view == null) return;
|
||||
|
||||
view.animate()
|
||||
.alpha(0f)
|
||||
.setDuration(duration)
|
||||
.withEndAction(() -> view.setVisibility(View.GONE))
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime une vue avec un effet de scale
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param scale Échelle cible (1.0 = normal, 0.5 = moitié)
|
||||
* @param duration Durée de l'animation
|
||||
*/
|
||||
public static void scale(View view, float scale, int duration) {
|
||||
if (view == null) return;
|
||||
|
||||
view.animate()
|
||||
.scaleX(scale)
|
||||
.scaleY(scale)
|
||||
.setDuration(duration)
|
||||
.setInterpolator(OVERSHOOT)
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime une vue avec un effet de slide depuis le bas
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param duration Durée de l'animation
|
||||
*/
|
||||
public static void slideUp(View view, int duration) {
|
||||
if (view == null) return;
|
||||
|
||||
view.setTranslationY(view.getHeight());
|
||||
view.setVisibility(View.VISIBLE);
|
||||
view.animate()
|
||||
.translationY(0f)
|
||||
.setDuration(duration)
|
||||
.setInterpolator(new android.view.animation.DecelerateInterpolator())
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Applique une animation de pression à un bouton
|
||||
*
|
||||
* @param view La vue (bouton) à animer
|
||||
*/
|
||||
public static void applyButtonPressAnimation(View view) {
|
||||
if (view == null) return;
|
||||
|
||||
view.setOnTouchListener((v, event) -> {
|
||||
switch (event.getAction()) {
|
||||
case android.view.MotionEvent.ACTION_DOWN:
|
||||
v.animate()
|
||||
.scaleX(0.95f)
|
||||
.scaleY(0.95f)
|
||||
.setDuration(100)
|
||||
.start();
|
||||
return true;
|
||||
case android.view.MotionEvent.ACTION_UP:
|
||||
case android.view.MotionEvent.ACTION_CANCEL:
|
||||
v.animate()
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.setDuration(100)
|
||||
.start();
|
||||
v.performClick();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime une vue avec un effet de pulsation
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param duration Durée d'un cycle de pulsation
|
||||
*/
|
||||
public static void pulse(View view, int duration) {
|
||||
if (view == null) return;
|
||||
|
||||
view.animate()
|
||||
.scaleX(1.05f)
|
||||
.scaleY(1.05f)
|
||||
.setDuration(duration / 2)
|
||||
.withEndAction(() -> {
|
||||
view.animate()
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.setDuration(duration / 2)
|
||||
.start();
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime une vue avec un effet de shake (tremblement)
|
||||
*
|
||||
* @param view La vue à animer
|
||||
*/
|
||||
public static void shake(View view) {
|
||||
if (view == null) return;
|
||||
|
||||
Animation shake = AnimationUtils.loadAnimation(view.getContext(), R.anim.button_press);
|
||||
view.startAnimation(shake);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtient la couleur depuis une ressource de couleur
|
||||
*/
|
||||
public static int getColorFromResource(Context context, int colorResId) {
|
||||
return ContextCompat.getColor(context, colorResId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime une vue avec un effet de bounce (rebond)
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param duration Durée de l'animation
|
||||
*/
|
||||
public static void bounce(View view, int duration) {
|
||||
if (view == null) return;
|
||||
|
||||
view.animate()
|
||||
.scaleY(0.8f)
|
||||
.scaleX(0.8f)
|
||||
.setDuration(duration / 2)
|
||||
.setInterpolator(new android.view.animation.DecelerateInterpolator())
|
||||
.withEndAction(() -> {
|
||||
view.animate()
|
||||
.scaleY(1f)
|
||||
.scaleX(1f)
|
||||
.setDuration(duration / 2)
|
||||
.setInterpolator(OVERSHOOT)
|
||||
.start();
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime une vue pour la supprimer (slide out + fade out)
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param duration Durée de l'animation
|
||||
* @param endAction Action à exécuter après l'animation
|
||||
*/
|
||||
public static void slideOutToRemove(View view, int duration, Runnable endAction) {
|
||||
if (view == null) return;
|
||||
|
||||
view.animate()
|
||||
.translationX(-view.getWidth())
|
||||
.alpha(0f)
|
||||
.setDuration(duration)
|
||||
.setInterpolator(new android.view.animation.AccelerateInterpolator())
|
||||
.withEndAction(endAction)
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime l'apparition d'une vue (slide in + fade in)
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param duration Durée de l'animation
|
||||
*/
|
||||
public static void slideIn(View view, int duration) {
|
||||
if (view == null) return;
|
||||
|
||||
view.setTranslationX(view.getWidth());
|
||||
view.setAlpha(0f);
|
||||
view.setVisibility(View.VISIBLE);
|
||||
view.animate()
|
||||
.translationX(0f)
|
||||
.alpha(1f)
|
||||
.setDuration(duration)
|
||||
.setInterpolator(new android.view.animation.DecelerateInterpolator())
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime une vue avec un effet de rotation
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param degrees Angle de rotation en degrés
|
||||
* @param duration Durée de l'animation
|
||||
*/
|
||||
public static void rotate(View view, float degrees, int duration) {
|
||||
if (view == null) return;
|
||||
|
||||
view.animate()
|
||||
.rotation(degrees)
|
||||
.setDuration(duration)
|
||||
.setInterpolator(new android.view.animation.DecelerateInterpolator())
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime une vue avec un effet de wiggle (gauche-droite)
|
||||
*
|
||||
* @param view La vue à animer
|
||||
*/
|
||||
public static void wiggle(View view) {
|
||||
if (view == null) return;
|
||||
|
||||
view.animate()
|
||||
.rotation(5f)
|
||||
.setDuration(50)
|
||||
.withEndAction(() -> {
|
||||
view.animate()
|
||||
.rotation(-5f)
|
||||
.setDuration(50)
|
||||
.withEndAction(() -> {
|
||||
view.animate()
|
||||
.rotation(3f)
|
||||
.setDuration(50)
|
||||
.withEndAction(() -> {
|
||||
view.animate()
|
||||
.rotation(0f)
|
||||
.setDuration(50)
|
||||
.start();
|
||||
})
|
||||
.start();
|
||||
})
|
||||
.start();
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime une vue avec un effet de pop-in (apparition avec scale)
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param duration Durée de l'animation
|
||||
*/
|
||||
public static void popIn(View view, int duration) {
|
||||
if (view == null) return;
|
||||
|
||||
view.setScaleX(0f);
|
||||
view.setScaleY(0f);
|
||||
view.setAlpha(0f);
|
||||
view.setVisibility(View.VISIBLE);
|
||||
view.animate()
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.alpha(1f)
|
||||
.setDuration(duration)
|
||||
.setInterpolator(OVERSHOOT)
|
||||
.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime une vue avec un effet de pop-out (disparition avec scale)
|
||||
*
|
||||
* @param view La vue à animer
|
||||
* @param duration Durée de l'animation
|
||||
* @param endAction Action à exécuter après l'animation
|
||||
*/
|
||||
public static void popOut(View view, int duration, Runnable endAction) {
|
||||
if (view == null) return;
|
||||
|
||||
view.animate()
|
||||
.scaleX(0f)
|
||||
.scaleY(0f)
|
||||
.alpha(0f)
|
||||
.setDuration(duration)
|
||||
.setInterpolator(new android.view.animation.AccelerateInterpolator())
|
||||
.withEndAction(endAction)
|
||||
.start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
//public class ChatGPTTask extends AsyncTask<Void, Void, String> {
|
||||
//// private Jeux jeuxActivity;
|
||||
//// private String keyOpenai;
|
||||
////
|
||||
//// public ChatGPTTask(Jeux jeuxActivity, String keyOpenai) {
|
||||
//// this.jeuxActivity = jeuxActivity;
|
||||
//// this.keyOpenai = keyOpenai;
|
||||
//// }
|
||||
////
|
||||
////
|
||||
//// @Override
|
||||
//// protected String doInBackground(Void... voids) {
|
||||
//// String url = "https://api.openai.com/v1/chat/completions";
|
||||
//// String apiKey = keyOpenai;
|
||||
//// System.out.println("apiKey de ChatGPTTASK.java: " + apiKey);
|
||||
//// String model = "gpt-3.5-turbo";
|
||||
////
|
||||
//// String prompt = "Tu es une IA française qui génère des questions ainsi que la categories de la question. Voici des exemples :" +
|
||||
//// "Celles/Ceux qui ont habité dans plus de 3 villes diferentes';'La vie" +
|
||||
//// "Ceux qui ont dansé aujourd'hui' ; 'Soirée'" +
|
||||
//// "'Pour se décoincer, le/la plus timide' ; 'Caractère'" +
|
||||
//// "'Celles et ceux qui ont déjà dépenser plus de 2000 euros en un achat' ; 'Dépense'" +
|
||||
//// "'Le/La plus radin(e)' ; 'Caractère'";
|
||||
//
|
||||
//// try {
|
||||
//// URL obj = new URL(url);
|
||||
//// HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
|
||||
//// connection.setRequestMethod("POST");
|
||||
//// connection.setRequestProperty("Authorization", "Bearer " + apiKey);
|
||||
//// connection.setRequestProperty("Content-Type", "application/json");
|
||||
////
|
||||
//// // The request body
|
||||
//// String body = "{\"model\": \"" + model + "\", \"messages\": [{\"role\": \"user\", \"content\": \"" + prompt + "\"}]}";
|
||||
//// System.out.println("body: " + body);
|
||||
//// connection.setDoOutput(true);
|
||||
//// OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
|
||||
//// writer.write(body);
|
||||
//// writer.flush();
|
||||
//// writer.close();
|
||||
////
|
||||
//// // Response from ChatGPT
|
||||
//// BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
//// String line;
|
||||
////
|
||||
//// StringBuffer response = new StringBuffer();
|
||||
////
|
||||
//// while ((line = br.readLine()) != null) {
|
||||
//// response.append(line);
|
||||
//// }
|
||||
//// br.close();
|
||||
////
|
||||
//// // calls the method to extract the message.
|
||||
//// return extractMessageFromJSONResponse(response.toString());
|
||||
////
|
||||
//// } catch (IOException e) {
|
||||
//// System.out.println("Il y a eu une erreur" + e);
|
||||
//// throw new RuntimeException(e);
|
||||
////
|
||||
//// }
|
||||
//// }
|
||||
////
|
||||
//// public String extractMessageFromJSONResponse(String response) {
|
||||
//// int start = response.indexOf("content") + 11;
|
||||
//// int end = response.indexOf("\"", start);
|
||||
//// String extractedMessage = response.substring(start, end);
|
||||
//// System.out.println("extractedMessage: " + extractedMessage);
|
||||
//// return extractedMessage;
|
||||
//// }
|
||||
////
|
||||
//// @Override
|
||||
//// protected void onPostExecute(String result) {
|
||||
//// if (result != null) {
|
||||
//// // Handle the extracted message here
|
||||
//// jeuxActivity.handleExtractedMessage(result);
|
||||
//// } else {
|
||||
//// Toast.makeText(jeuxActivity.getApplicationContext(), "Échec de la communication avec l'API !", Toast.LENGTH_SHORT).show();
|
||||
//// jeuxActivity.navigateToJeuxParametres();
|
||||
//// }
|
||||
//// }
|
||||
//
|
||||
//
|
||||
// return url;
|
||||
// }}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.impossibl.postgres.api.jdbc.PGConnection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DatabaseConnection extends AsyncTask<Void, Void, PGConnection> {
|
||||
private static final String DB_URL = "jdbc:postgresql://82.65.214.214:5432/boidelo";
|
||||
private static final String USER = "Tux2543";
|
||||
private static final String PASSWORD = "6wa*teCnuxsG#grAc5HzC!Rh%#@c&";
|
||||
|
||||
@Override
|
||||
protected PGConnection doInBackground(Void... params) {
|
||||
PGConnection connection = null;
|
||||
try {
|
||||
// Code de connexion à la base de données PostgreSQL
|
||||
String url = DB_URL;
|
||||
String username = USER;
|
||||
String password = PASSWORD;
|
||||
connection = (PGConnection) DriverManager.getConnection(url, username, password);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
protected void onPostExecute(Connection connection) {
|
||||
// Traitez le résultat de la connexion ici
|
||||
if (connection != null) {
|
||||
// Connexion réussie
|
||||
} else {
|
||||
// Échec de la connexion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,687 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Activité principale du jeu Boidelo
|
||||
* Affiche les questions et gère les interactions de jeu
|
||||
*/
|
||||
public class Jeux extends AppCompatActivity {
|
||||
// Vues
|
||||
private TextView questionTextView;
|
||||
private TextView progressTextView;
|
||||
private TextView mancheCounterTextView;
|
||||
private TextView mancheQuestionText;
|
||||
private ProgressBar progressBar;
|
||||
private MaterialButton suivantButton;
|
||||
private MaterialButton skipButton;
|
||||
private LinearLayout questionIndicator;
|
||||
private ImageView indicatorIcon;
|
||||
private TextView indicatorText;
|
||||
|
||||
// Données
|
||||
private Questions questions;
|
||||
private List<String> toutlesjoueurs;
|
||||
private List<Question> questionsAvecManches = new ArrayList<>();
|
||||
|
||||
// Paramètres de partie
|
||||
private int nombreQuestions;
|
||||
private int ajoutGorgees;
|
||||
private boolean openAI;
|
||||
private int ratiOpenai;
|
||||
private String keyOpenai;
|
||||
|
||||
// État du jeu
|
||||
private int currentQuestionIndex = 0;
|
||||
private int totalQuestionsAsked = 0;
|
||||
private String currentQuestionText = "";
|
||||
private boolean isMancheActive = false;
|
||||
|
||||
// Clés pour sauvegarde d'état
|
||||
private static final String KEY_TOTAL_QUESTIONS = "total_questions_asked";
|
||||
private static final String KEY_CURRENT_QUESTION_TEXT = "current_question_text";
|
||||
private static final String KEY_IS_MANCHE_ACTIVE = "is_manche_active";
|
||||
private static final String KEY_MANCHES_COUNT = "manches_count";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_jeux);
|
||||
|
||||
// Initialiser les vues
|
||||
initViews();
|
||||
|
||||
// Récupération des données passées par l'activité précédente
|
||||
toutlesjoueurs = getIntent().getStringArrayListExtra("EXTRA_LIST_JOUEUR");
|
||||
nombreQuestions = getIntent().getIntExtra("EXTRA_NOMBRE_QUESTIONS", 50);
|
||||
ajoutGorgees = getIntent().getIntExtra("EXTRA_AJOUT_GORGEE", 0);
|
||||
openAI = getIntent().getBooleanExtra("EXTRA_OPENAI", false);
|
||||
ratiOpenai = getIntent().getIntExtra("EXTRA_RATIO_OPENAI", 0);
|
||||
keyOpenai = getIntent().getStringExtra("EXTRA_KEY_OPENAI");
|
||||
|
||||
// Charger les questions depuis le JSON
|
||||
loadQuestions();
|
||||
|
||||
// Configurer la barre de progression
|
||||
setupProgressBar();
|
||||
|
||||
// Restaurer l'état si disponible (rotation)
|
||||
if (savedInstanceState != null) {
|
||||
restoreGameState(savedInstanceState);
|
||||
} else {
|
||||
// Afficher la première question
|
||||
updateQuestion();
|
||||
}
|
||||
|
||||
// Configuration des listeners de boutons
|
||||
setupButtonListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise toutes les vues de l'activité
|
||||
*/
|
||||
private void initViews() {
|
||||
questionTextView = findViewById(R.id.textView1);
|
||||
progressTextView = findViewById(R.id.progressText);
|
||||
mancheCounterTextView = findViewById(R.id.mancheCounter);
|
||||
mancheQuestionText = findViewById(R.id.mancheQuestionText);
|
||||
progressBar = findViewById(R.id.progressBar);
|
||||
suivantButton = findViewById(R.id.button);
|
||||
skipButton = findViewById(R.id.skipButton);
|
||||
questionIndicator = findViewById(R.id.questionIndicator);
|
||||
indicatorIcon = findViewById(R.id.indicatorIcon);
|
||||
indicatorText = findViewById(R.id.indicatorText);
|
||||
|
||||
// Appliquer les animations aux boutons
|
||||
BoideloAnimationUtils.applyButtonPressAnimation(suivantButton);
|
||||
BoideloAnimationUtils.applyButtonPressAnimation(skipButton);
|
||||
|
||||
// Initialiser la couleur de fond (respecte le mode jour/nuit)
|
||||
int backgroundColor = ContextCompat.getColor(this, R.color.game_normal);
|
||||
getWindow().getDecorView().setBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge les questions depuis le fichier JSON
|
||||
*/
|
||||
private void loadQuestions() {
|
||||
try {
|
||||
InputStream is = getAssets().open("question.json");
|
||||
int size = is.available();
|
||||
byte[] buffer = new byte[size];
|
||||
is.read(buffer);
|
||||
is.close();
|
||||
String json = new String(buffer, "UTF-8");
|
||||
|
||||
Gson gson = new Gson();
|
||||
questions = gson.fromJson(json, Questions.class);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
Toast.makeText(this, "Erreur de chargement des questions", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure la barre de progression initiale
|
||||
*/
|
||||
private void setupProgressBar() {
|
||||
progressBar.setMax(nombreQuestions);
|
||||
progressBar.setProgress(0);
|
||||
updateProgressText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure les listeners des boutons
|
||||
*/
|
||||
private void setupButtonListeners() {
|
||||
suivantButton.setOnClickListener(v -> {
|
||||
BoideloAnimationUtils.triggerHapticFeedback(this);
|
||||
updateQuestion();
|
||||
});
|
||||
|
||||
skipButton.setOnClickListener(v -> {
|
||||
BoideloAnimationUtils.triggerHapticFeedback(this);
|
||||
skipQuestion();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour le texte de progression
|
||||
*/
|
||||
private void updateProgressText() {
|
||||
progressTextView.setText("Question " + (totalQuestionsAsked + 1) + " / " + nombreQuestions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour la barre de progression
|
||||
*/
|
||||
private void updateProgressBar() {
|
||||
progressBar.setProgress(totalQuestionsAsked);
|
||||
updateProgressText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour la question affichée avec toutes les animations
|
||||
*/
|
||||
private void updateQuestion() {
|
||||
// Vérifier si toutes les questions ont été posées
|
||||
if (totalQuestionsAsked >= nombreQuestions) {
|
||||
// Vérifier s'il y a encore des manches actives
|
||||
if (!questionsAvecManches.isEmpty()) {
|
||||
// Afficher le message de fin de manche et terminer
|
||||
showFinalMancheEndMessage();
|
||||
return;
|
||||
}
|
||||
endGame();
|
||||
return;
|
||||
}
|
||||
|
||||
// Gérer les questions avec manches actives
|
||||
Iterator<Question> iterator = questionsAvecManches.iterator();
|
||||
boolean hasMancheActive = false;
|
||||
while (iterator.hasNext()) {
|
||||
Question mancheQuestion = iterator.next();
|
||||
mancheQuestion.setManchesRestantes(mancheQuestion.getManchesRestantes() - 1);
|
||||
|
||||
if (mancheQuestion.getManchesRestantes() <= 0) {
|
||||
// Afficher brièvement le message d'arrêt et continuer
|
||||
showMancheEndNotification(mancheQuestion.getArretMessageManche());
|
||||
iterator.remove();
|
||||
// Continuer avec une nouvelle question après la fin de manche
|
||||
break;
|
||||
} else {
|
||||
// Afficher la question de manche en petit et continuer
|
||||
hasMancheActive = true;
|
||||
displayMancheQuestionSmall(mancheQuestion);
|
||||
break; // Un seul défi à manches à la fois
|
||||
}
|
||||
}
|
||||
|
||||
// Afficher une nouvelle question (que ce soit pendant ou hors manche)
|
||||
Question question = getRandomQuestion();
|
||||
if (question != null) {
|
||||
displayQuestion(question, hasMancheActive);
|
||||
totalQuestionsAsked++;
|
||||
updateProgressBar();
|
||||
} else {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche une notification de fin de manche (sans bloquer le jeu)
|
||||
*/
|
||||
private void showMancheEndNotification(String message) {
|
||||
// Afficher un Toast avec le message de fin
|
||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
|
||||
|
||||
// Vibration de succès
|
||||
BoideloAnimationUtils.triggerSuccessHaptic(this);
|
||||
|
||||
// Masquer le compteur de manches et l'indicateur
|
||||
mancheCounterTextView.setVisibility(View.GONE);
|
||||
questionIndicator.setVisibility(View.GONE);
|
||||
mancheQuestionText.setVisibility(View.GONE);
|
||||
|
||||
// Animation de fond jaune temporaire
|
||||
int yellowColor = ContextCompat.getColor(this, R.color.game_manche_end);
|
||||
BoideloAnimationUtils.animateBackgroundColor(getWindow().getDecorView(), yellowColor);
|
||||
|
||||
// Revenir à la couleur normale après un délai
|
||||
mancheCounterTextView.postDelayed(() -> {
|
||||
int defaultColor = ContextCompat.getColor(this, R.color.game_normal);
|
||||
BoideloAnimationUtils.animateBackgroundColor(getWindow().getDecorView(), defaultColor);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche le message de fin de manche finale (quand le jeu se termine)
|
||||
*/
|
||||
private void showFinalMancheEndMessage() {
|
||||
// Récupérer le message de la dernière manche
|
||||
if (!questionsAvecManches.isEmpty()) {
|
||||
Question lastManche = questionsAvecManches.get(0);
|
||||
questionTextView.setText(Html.fromHtml(lastManche.getArretMessageManche(), Html.FROM_HTML_MODE_LEGACY));
|
||||
}
|
||||
|
||||
// Animation de fond jaune
|
||||
int yellowColor = ContextCompat.getColor(this, R.color.game_manche_end);
|
||||
BoideloAnimationUtils.animateBackgroundColor(getWindow().getDecorView(), yellowColor);
|
||||
|
||||
// Vibration de succès
|
||||
BoideloAnimationUtils.triggerSuccessHaptic(this);
|
||||
|
||||
// Masquer le compteur et l'indicateur
|
||||
mancheCounterTextView.setVisibility(View.GONE);
|
||||
questionIndicator.setVisibility(View.GONE);
|
||||
mancheQuestionText.setVisibility(View.GONE);
|
||||
|
||||
// Terminer après un délai
|
||||
mancheCounterTextView.postDelayed(() -> {
|
||||
questionsAvecManches.clear();
|
||||
endGame();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche une question de manche en petit (sans bloquer le jeu)
|
||||
*/
|
||||
private void displayMancheQuestionSmall(Question question) {
|
||||
// Afficher la question de manche en petit avec le nombre de manches restantes
|
||||
String mancheQuestion = question.getQuestion() + " <small>(" + question.getManchesRestantes() + " manche(s) restante(s))</small>";
|
||||
mancheQuestionText.setText(Html.fromHtml(mancheQuestion, Html.FROM_HTML_MODE_LEGACY));
|
||||
mancheQuestionText.setVisibility(View.VISIBLE);
|
||||
|
||||
// Mettre à jour le compteur
|
||||
updateMancheCounter(question.getManchesRestantes(), question.getQuestion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche une question de manche active (ancienne méthode, plus utilisée)
|
||||
*/
|
||||
private void displayMancheQuestion(Question question) {
|
||||
questionTextView.setText(Html.fromHtml(question.getQuestion(), Html.FROM_HTML_MODE_LEGACY));
|
||||
|
||||
// Fond bleu pour les manches
|
||||
int blueColor = ContextCompat.getColor(this, R.color.game_question_manche);
|
||||
BoideloAnimationUtils.animateBackgroundColor(getWindow().getDecorView(), blueColor);
|
||||
|
||||
// Afficher l'indicateur de manche
|
||||
showQuestionIndicator(R.drawable.ic_manche, "Manche en cours");
|
||||
|
||||
// Mettre à jour le compteur
|
||||
updateMancheCounter(question.getManchesRestantes(), question.getQuestion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour le compteur de manches (affiché comme rappel)
|
||||
*/
|
||||
private void updateMancheCounter(int manchesRestantes, String mancheQuestion) {
|
||||
mancheCounterTextView.setText("Défi en cours: " + manchesRestantes + " tour(s) restant(s)");
|
||||
mancheCounterTextView.setVisibility(View.VISIBLE);
|
||||
|
||||
// Afficher l'indicateur de manche en haut
|
||||
showQuestionIndicator(R.drawable.ic_manche, "Manche en cours");
|
||||
|
||||
// Animation du compteur
|
||||
BoideloAnimationUtils.pulse(mancheCounterTextView, 300);
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche une nouvelle question
|
||||
*/
|
||||
private void displayQuestion(Question question, boolean hasMancheActive) {
|
||||
questionTextView.setText(Html.fromHtml(question.getQuestion(), Html.FROM_HTML_MODE_LEGACY));
|
||||
|
||||
// Masquer ou afficher la question de manche selon l'état
|
||||
if (!hasMancheActive) {
|
||||
mancheQuestionText.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// Déterminer le type de question et animer le fond en conséquence
|
||||
String questionText = question.getQuestion();
|
||||
|
||||
// Réinitialiser les indicateurs
|
||||
questionIndicator.setVisibility(View.GONE);
|
||||
mancheCounterTextView.setVisibility(View.GONE);
|
||||
|
||||
// Fond par défaut (respecte le mode jour/nuit)
|
||||
int defaultColor = ContextCompat.getColor(this, R.color.game_normal);
|
||||
BoideloAnimationUtils.animateBackgroundColor(
|
||||
getWindow().getDecorView(),
|
||||
defaultColor
|
||||
);
|
||||
|
||||
// Vérifier le type de question
|
||||
boolean isJoueurs1 = questionText.contains("<J1>");
|
||||
boolean isJoueurs2 = questionText.contains("<J2>");
|
||||
boolean isJoueurs3 = questionText.contains("<J3>");
|
||||
boolean hasManches = questionText.contains("<manches>");
|
||||
|
||||
if (hasManches) {
|
||||
int blueColor = ContextCompat.getColor(this, R.color.game_question_manche);
|
||||
BoideloAnimationUtils.animateBackgroundColor(getWindow().getDecorView(), blueColor);
|
||||
showQuestionIndicator(R.drawable.ic_manche, "Défi à manches");
|
||||
} else if (isJoueurs1 && isJoueurs2 && isJoueurs3) {
|
||||
int greenDarkColor = ContextCompat.getColor(this, R.color.game_question_3players);
|
||||
BoideloAnimationUtils.animateBackgroundColor(getWindow().getDecorView(), greenDarkColor);
|
||||
showQuestionIndicator(R.drawable.ic_player_three, "3 joueurs");
|
||||
} else if (isJoueurs1 && isJoueurs2) {
|
||||
int greenColor = ContextCompat.getColor(this, R.color.game_question_2players);
|
||||
BoideloAnimationUtils.animateBackgroundColor(getWindow().getDecorView(), greenColor);
|
||||
showQuestionIndicator(R.drawable.ic_player_two, "2 joueurs");
|
||||
} else if (isJoueurs1) {
|
||||
int greenLightColor = ContextCompat.getColor(this, R.color.game_question_1player);
|
||||
BoideloAnimationUtils.animateBackgroundColor(getWindow().getDecorView(), greenLightColor);
|
||||
showQuestionIndicator(R.drawable.ic_player_one, "1 joueur");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche l'indicateur de type de question
|
||||
*/
|
||||
private void showQuestionIndicator(int iconRes, String text) {
|
||||
indicatorIcon.setImageResource(iconRes);
|
||||
indicatorText.setText(text);
|
||||
questionIndicator.setVisibility(View.VISIBLE);
|
||||
BoideloAnimationUtils.fadeIn(questionIndicator, 300);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passe la question actuelle
|
||||
*/
|
||||
private void skipQuestion() {
|
||||
// Marquer la question comme posée pour ne pas la revoir
|
||||
totalQuestionsAsked++;
|
||||
updateProgressBar();
|
||||
updateQuestion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Termine la partie et affiche l'écran de fin
|
||||
*/
|
||||
private void endGame() {
|
||||
// Sauvegarder les statistiques de la partie
|
||||
saveGameStats();
|
||||
|
||||
// Lancer l'activité de fin de partie
|
||||
Intent intent = new Intent(this, EndGameActivity.class);
|
||||
intent.putExtra("EXTRA_QUESTIONS_PLAYED", totalQuestionsAsked);
|
||||
intent.putExtra("EXTRA_PLAYERS_COUNT", toutlesjoueurs != null ? toutlesjoueurs.size() : 0);
|
||||
intent.putStringArrayListExtra("EXTRA_PLAYERS", (ArrayList<String>) toutlesjoueurs);
|
||||
startActivity(intent);
|
||||
|
||||
// Animation de transition
|
||||
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
|
||||
|
||||
// Vibration de fin
|
||||
BoideloAnimationUtils.triggerErrorHaptic(this);
|
||||
|
||||
// Réinitialiser les questions posées pour une prochaine partie
|
||||
resetAskedQuestions();
|
||||
|
||||
// Terminer l'activité
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sauvegarde les statistiques de la partie
|
||||
*/
|
||||
private void saveGameStats() {
|
||||
SharedPreferences prefs = getSharedPreferences("game_stats", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putInt("questions_played", totalQuestionsAsked);
|
||||
editor.putInt("players_count", toutlesjoueurs != null ? toutlesjoueurs.size() : 0);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Réinitialise la liste des questions posées
|
||||
*/
|
||||
private void resetAskedQuestions() {
|
||||
SharedPreferences prefs = getSharedPreferences("app", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.remove("askedQuestions");
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sélectionne trois joueurs aléatoires différents
|
||||
*/
|
||||
public List<String> TroisJoueurAleatoire(List<String> toutlesjoueurs) {
|
||||
Set<String> setJoueur = new HashSet<>();
|
||||
Random rand = new Random();
|
||||
|
||||
while (setJoueur.size() < 3 && toutlesjoueurs.size() >= 3) {
|
||||
setJoueur.add(toutlesjoueurs.get(rand.nextInt(toutlesjoueurs.size())));
|
||||
}
|
||||
|
||||
return new ArrayList<>(setJoueur);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le message d'arrêt par ID
|
||||
*/
|
||||
private String getArretById(int id) {
|
||||
for (Question question : questions.getQuestions()) {
|
||||
if (question.getId() == id) {
|
||||
return question.getArret();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtient une question aléatoire qui n'a pas encore été posée
|
||||
*/
|
||||
private Question getRandomQuestion() {
|
||||
if (questions == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences("app", Context.MODE_PRIVATE);
|
||||
Set<String> askedQuestions = prefs.getStringSet("askedQuestions", new HashSet<>());
|
||||
|
||||
List<Question> unaskedQuestions = new ArrayList<>();
|
||||
for (Question question : questions.getQuestions()) {
|
||||
if (!askedQuestions.contains(String.valueOf(question.getId()))) {
|
||||
unaskedQuestions.add(question);
|
||||
}
|
||||
}
|
||||
|
||||
if (unaskedQuestions.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
Question question = unaskedQuestions.get(random.nextInt(unaskedQuestions.size()));
|
||||
askedQuestions.add(String.valueOf(question.getId()));
|
||||
|
||||
// Sauvegarder les questions posées
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putStringSet("askedQuestions", askedQuestions);
|
||||
editor.apply();
|
||||
|
||||
// Traiter la question
|
||||
processQuestion(question);
|
||||
|
||||
return question;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traite une question (remplace les variables, etc.)
|
||||
*/
|
||||
private void processQuestion(Question question) {
|
||||
Random random = new Random();
|
||||
String questionText = question.getQuestion();
|
||||
|
||||
// Remplacer les variantes
|
||||
if (question.getVariante() != null && !question.getVariante().isEmpty()) {
|
||||
String chosenVariante = question.getVariante().get(random.nextInt(question.getVariante().size()));
|
||||
questionText = questionText.replace("<variante>", chosenVariante);
|
||||
}
|
||||
|
||||
// Gérer les manches
|
||||
if (questionText.contains("<manches>")) {
|
||||
int nbaleatoiremanches = random.nextInt(10) + 5;
|
||||
questionText = questionText.replace("<manches>", String.valueOf(nbaleatoiremanches));
|
||||
question.setManchesRestantes(nbaleatoiremanches);
|
||||
|
||||
String stopid = getArretById(question.getId());
|
||||
question.setArretMessageManche("Fin de défi!\n" + stopid);
|
||||
questionsAvecManches.add(question);
|
||||
}
|
||||
|
||||
// Remplacer les joueurs
|
||||
boolean isJoueurs1 = questionText.contains("<J1>");
|
||||
boolean isJoueurs2 = questionText.contains("<J2>");
|
||||
boolean isJoueurs3 = questionText.contains("<J3>");
|
||||
|
||||
if (isJoueurs1 || isJoueurs2 || isJoueurs3) {
|
||||
List<String> aleatoirejoueurs = TroisJoueurAleatoire(toutlesjoueurs);
|
||||
|
||||
if (isJoueurs1 && isJoueurs2 && isJoueurs3 && aleatoirejoueurs.size() >= 3) {
|
||||
questionText = questionText.replace("<J1>", aleatoirejoueurs.get(0));
|
||||
questionText = questionText.replace("<J2>", aleatoirejoueurs.get(1));
|
||||
questionText = questionText.replace("<J3>", aleatoirejoueurs.get(2));
|
||||
} else if (isJoueurs1 && isJoueurs2 && aleatoirejoueurs.size() >= 2) {
|
||||
questionText = questionText.replace("<J1>", aleatoirejoueurs.get(0));
|
||||
questionText = questionText.replace("<J2>", aleatoirejoueurs.get(1));
|
||||
} else if (isJoueurs1 && aleatoirejoueurs.size() >= 1) {
|
||||
questionText = questionText.replace("<J1>", aleatoirejoueurs.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
// Ajouter les gorgées
|
||||
if (question.isDistribution() || question.isRecois()) {
|
||||
if (question.isRecois() && question.isDistribution()) {
|
||||
boolean rand = random.nextBoolean();
|
||||
if (rand) {
|
||||
questionText = questionText.concat(" <b>bois</b>");
|
||||
} else {
|
||||
questionText = questionText.concat(" <b>distribue</b>");
|
||||
}
|
||||
} else if (question.isRecois()) {
|
||||
questionText = questionText.concat(" <b>bois</b>");
|
||||
} else if (question.isDistribution()) {
|
||||
questionText = questionText.concat(" <b>distribue</b>");
|
||||
}
|
||||
|
||||
questionText = questionText.concat(" " + (question.getGorger() + ajoutGorgees) + " gorgée" +
|
||||
((question.getGorger() + ajoutGorgees) > 1 ? "s" : "") + ".");
|
||||
}
|
||||
|
||||
question.setQuestion(questionText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode publique pour le bouton suivant (compatibilité avec XML)
|
||||
*/
|
||||
public void OnClickButton1(View view) {
|
||||
BoideloAnimationUtils.triggerHapticFeedback(this);
|
||||
updateQuestion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode publique pour le bouton passer
|
||||
*/
|
||||
public void onSkipClick(View view) {
|
||||
BoideloAnimationUtils.triggerHapticFeedback(this);
|
||||
skipQuestion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigue vers l'activité JeuxParametres en cas d'échec API
|
||||
*/
|
||||
public void navigateToJeuxParametres() {
|
||||
Intent intent = new Intent(Jeux.this, JeuxParametres.class);
|
||||
Toast.makeText(getApplicationContext(), "Échec de la communication avec l'API !", Toast.LENGTH_SHORT).show();
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sauvegarde l'état du jeu avant la rotation
|
||||
*/
|
||||
@Override
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(KEY_TOTAL_QUESTIONS, totalQuestionsAsked);
|
||||
outState.putString(KEY_CURRENT_QUESTION_TEXT, questionTextView.getText().toString());
|
||||
outState.putBoolean(KEY_IS_MANCHE_ACTIVE, isMancheActive);
|
||||
|
||||
// Sauvegarder l'état des manches actives
|
||||
ArrayList<Integer> mancheIds = new ArrayList<>();
|
||||
ArrayList<Integer> mancheCounts = new ArrayList<>();
|
||||
for (Question q : questionsAvecManches) {
|
||||
mancheIds.add(q.getId());
|
||||
mancheCounts.add(q.getManchesRestantes());
|
||||
}
|
||||
outState.putIntegerArrayList("manche_ids", mancheIds);
|
||||
outState.putIntegerArrayList("manche_counts", mancheCounts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restaure l'état du jeu après rotation
|
||||
*/
|
||||
private void restoreGameState(Bundle savedInstanceState) {
|
||||
totalQuestionsAsked = savedInstanceState.getInt(KEY_TOTAL_QUESTIONS, 0);
|
||||
currentQuestionText = savedInstanceState.getString(KEY_CURRENT_QUESTION_TEXT, "");
|
||||
isMancheActive = savedInstanceState.getBoolean(KEY_IS_MANCHE_ACTIVE, false);
|
||||
|
||||
// Restaurer la progression
|
||||
progressBar.setProgress(totalQuestionsAsked);
|
||||
updateProgressText();
|
||||
|
||||
// Restaurer le texte de la question
|
||||
if (!currentQuestionText.isEmpty()) {
|
||||
questionTextView.setText(Html.fromHtml(currentQuestionText, Html.FROM_HTML_MODE_LEGACY));
|
||||
}
|
||||
|
||||
// Restaurer les manches actives
|
||||
ArrayList<Integer> mancheIds = savedInstanceState.getIntegerArrayList("manche_ids");
|
||||
ArrayList<Integer> mancheCounts = savedInstanceState.getIntegerArrayList("manche_counts");
|
||||
if (mancheIds != null && mancheCounts != null) {
|
||||
questionsAvecManches.clear();
|
||||
for (int i = 0; i < mancheIds.size(); i++) {
|
||||
Question q = findQuestionById(mancheIds.get(i));
|
||||
if (q != null) {
|
||||
q.setManchesRestantes(mancheCounts.get(i));
|
||||
questionsAvecManches.add(q);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trouve une question par son ID
|
||||
*/
|
||||
private Question findQuestionById(int id) {
|
||||
if (questions == null) return null;
|
||||
for (Question q : questions.getQuestions()) {
|
||||
if (q.getId() == id) {
|
||||
// Créer une copie pour éviter de modifier l'original
|
||||
Question copy = new Question();
|
||||
copy.setId(q.getId());
|
||||
copy.setQuestion(q.getQuestion());
|
||||
copy.setArret(q.getArret());
|
||||
copy.setVariante(q.getVariante());
|
||||
copy.setDistribution(q.isDistribution());
|
||||
copy.setRecois(q.isRecois());
|
||||
copy.setGorger(q.getGorger());
|
||||
copy.setManchesRestantes(q.getManchesRestantes());
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import com.google.android.material.switchmaterial.SwitchMaterial;
|
||||
import android.widget.EditText;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class JeuxParametres extends AppCompatActivity {
|
||||
|
||||
private SeekBar seekBar1, seekBar2, seekBar3;
|
||||
private TextView textView1, textView2, textView5, textViewRatioGen;
|
||||
private SwitchMaterial checkBoxGPT;
|
||||
private EditText editText, editTextKeyGPT;
|
||||
private String keyGPT;
|
||||
private int nbQuestions;
|
||||
|
||||
private List<String> toutlesjoueurs;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
toutlesjoueurs = getIntent().getStringArrayListExtra("EXTRA_LIST_JOUEUR");
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_jeux_parametres);
|
||||
|
||||
// Initialisation des vues
|
||||
seekBar1 = findViewById(R.id.seekBar1);
|
||||
seekBar2 = findViewById(R.id.seekBar2);
|
||||
seekBar3 = findViewById(R.id.seekBar3);
|
||||
textView1 = findViewById(R.id.textView1);
|
||||
textView2 = findViewById(R.id.textView2);
|
||||
textView5 = findViewById(R.id.textView5);
|
||||
editTextKeyGPT = findViewById(R.id.editTextGPT);
|
||||
textViewRatioGen = findViewById(R.id.textViewRatioGen);
|
||||
|
||||
// Initialiser les TextView avec les valeurs par défaut
|
||||
int initialQuestions = 50;
|
||||
int initialGorgees = 0;
|
||||
int initialRatio = 8;
|
||||
|
||||
textView1.setText("Nombre de questions avant la fin de partie : " + initialQuestions);
|
||||
textView2.setText("Ajout de gorgées : " + initialGorgees);
|
||||
textView5.setText("Palier : Grosse merde");
|
||||
textViewRatioGen.setText("Ratio BDD/OPENAI : 1/" + initialRatio);
|
||||
|
||||
Button buttonTestApi = findViewById(R.id.ButtonTestApi);
|
||||
|
||||
// Configuration de la seekBar1
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
seekBar1.setMin(20);
|
||||
}
|
||||
seekBar1.setMax(150);
|
||||
seekBar1.setProgress(50);
|
||||
|
||||
// Configuration de la seekBar2
|
||||
seekBar2.setMax(20);
|
||||
seekBar2.setProgress(0);
|
||||
|
||||
// Configuration de la seekBar3
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
seekBar2.setMin(0);
|
||||
seekBar3.setMin(1);
|
||||
}
|
||||
seekBar3.setMax(15);
|
||||
seekBar3.setProgress(8);
|
||||
|
||||
// Configuration des listeners pour les seekBars
|
||||
seekBar1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
// Ajustement de la valeur au multiple de 10 le plus proche
|
||||
int adjustedProgress = Math.round(progress / 10) * 10;
|
||||
seekBar.setProgress(adjustedProgress);
|
||||
textView1.setText("Nombre de questions avant la fin de partie : " + adjustedProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
|
||||
seekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
// Mise à jour du textView2 en fonction de la valeur de la seekBar2
|
||||
textView2.setText("Ajout de gorgées : " + progress);
|
||||
// Mise à jour du textView5 en fonction de la valeur de la seekBar2
|
||||
switch (progress) {
|
||||
case 0:
|
||||
textView5.setText("Palier : Grosse merde");
|
||||
break;
|
||||
case 2:
|
||||
textView5.setText("Palier : Petite merde");
|
||||
break;
|
||||
case 4:
|
||||
textView5.setText("Palier : Petit joueur");
|
||||
break;
|
||||
case 6:
|
||||
textView5.setText("Palier : Un p'tit verre ?!");
|
||||
break;
|
||||
case 8:
|
||||
textView5.setText("Palier : ça commence à aller");
|
||||
break;
|
||||
case 10:
|
||||
textView5.setText("Palier : Alcoolique");
|
||||
break;
|
||||
case 12:
|
||||
textView5.setText("Palier : COMA ETHYLIX");
|
||||
break;
|
||||
case 13:
|
||||
textView5.setText("Palier : APÉROOOOO !!");
|
||||
break;
|
||||
case 14:
|
||||
textView5.setText("Palier : LA J'SUIS BIENG");
|
||||
break;
|
||||
case 15:
|
||||
textView5.setText("Palier : J'VOIS PLUS RIENG");
|
||||
break;
|
||||
case 17:
|
||||
textView5.setText("Palier : J'AI PLUS DE VERRES");
|
||||
break;
|
||||
case 18 :
|
||||
textView5.setText("Palier : Soirée Murge");
|
||||
break;
|
||||
case 19:
|
||||
textView5.setText("Palier : Soirée Pétée");
|
||||
break;
|
||||
case 20:
|
||||
textView5.setText("Palier : L'ENDER DRAGON");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
|
||||
// Configuration du checkBox // Q : IL sert a quoi ?
|
||||
// R : Il sert à activer/désactiver les vues en dessous
|
||||
|
||||
checkBoxGPT = findViewById(R.id.checkBoxGPT);
|
||||
checkBoxGPT.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
// Activation/désactivation des vues en fonction de l'état du checkBox
|
||||
editTextKeyGPT.setEnabled(isChecked);
|
||||
//editText.setEnabled(isChecked);
|
||||
textViewRatioGen.setEnabled(isChecked);
|
||||
seekBar3.setEnabled(isChecked);
|
||||
buttonTestApi.setEnabled(isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
// Configuration de la seekBar3
|
||||
seekBar3.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar3, int progress, boolean fromUser) {
|
||||
textViewRatioGen.setText("Ratio BDD/OPENAI : 1/" + progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar3) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar3) {
|
||||
}
|
||||
});
|
||||
|
||||
// Partie OpenAI : enregistrement de la clé en dur.
|
||||
// Récupérer une instance des SharedPreferences
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("MyPrefs", MODE_PRIVATE);
|
||||
final SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
// Récupérer l'EditText
|
||||
final EditText editText = findViewById(R.id.editTextGPT);
|
||||
// Récupérer la valeur enregistrée dans les SharedPreferences
|
||||
String apiKey = editText.getText().toString();
|
||||
|
||||
// Récupérer la valeur enregistrée dans les SharedPreferences
|
||||
String savedText = sharedPreferences.getString("savedText", "");
|
||||
editText.setText(savedText);
|
||||
|
||||
// Enregistrer le contenu de l'EditText lorsque l'utilisateur modifie le texte
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// Enregistrer le texte dans les SharedPreferences
|
||||
editor.putString("savedText", editText.getText().toString());
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onClickButtonTestAPI(View view) {
|
||||
|
||||
String apiKey = editTextKeyGPT.getText().toString();
|
||||
// Créer un client OkHttpClient pour effectuer la requête
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
// Construire la requête d'essai vers l'API
|
||||
Request request = new Request.Builder()
|
||||
.url("https://api.openai.com/v1/engines/davinci") // Endpoint d'essai, vous pouvez le modifier selon vos besoins
|
||||
.header("Authorization", "Bearer " + apiKey) // Ajouter la clé API dans l'en-tête de la requête
|
||||
.build();
|
||||
|
||||
// Exécuter la requête de test
|
||||
client.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Call call, IOException e) {
|
||||
// Gérer les erreurs de requête
|
||||
e.printStackTrace();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(), "Échec de la communication avec l'API !", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
// Vérifier le code de réponse de la requête
|
||||
if (response.isSuccessful()) {
|
||||
// La clé API est valide et l'API a répondu avec succès
|
||||
// Vous pouvez effectuer d'autres opérations ici
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(), "Communication avec l'API réussie !", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// La clé API est invalide ou il y a eu une erreur de communication avec l'API
|
||||
System.out.println("Échec de la communication avec l'API !");
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(), "Échec de la communication avec l'API !", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
response.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onClickButtonStart(View view) {
|
||||
// Récupérer les paramètres de la partie
|
||||
int nombreQuestions = seekBar1.getProgress();
|
||||
int ajoutGorgees = seekBar2.getProgress();
|
||||
int ratioBddOpenAI = seekBar3.getProgress();
|
||||
boolean openAI = checkBoxGPT.isChecked();
|
||||
|
||||
toutlesjoueurs = getIntent().getStringArrayListExtra("EXTRA_LIST_JOUEUR");
|
||||
// Récupérer les joueurs (vous devrez définir comment vous les récupérez)
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("Joueurs", Context.MODE_PRIVATE);
|
||||
ArrayList<String> joueurs = new ArrayList<>();
|
||||
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
String joueur = sharedPreferences.getString("J" + i, "");
|
||||
if (!joueur.isEmpty()) {
|
||||
joueurs.add(joueur);
|
||||
}
|
||||
}
|
||||
|
||||
// Récupérer les joueurs supplémentaires en utilisant une boucle
|
||||
int i = 4;
|
||||
String nomJoueur = sharedPreferences.getString("J" + i, "");
|
||||
while (!nomJoueur.isEmpty()) {
|
||||
joueurs.add(nomJoueur);
|
||||
i++;
|
||||
nomJoueur = sharedPreferences.getString("J" + i, "");
|
||||
}
|
||||
|
||||
// Créer une instance de la classe Jeux avec les paramètres récupérés
|
||||
Jeux jeux = new Jeux();
|
||||
|
||||
// Lancer l'activité Jeux avec les paramètres
|
||||
Intent intent = new Intent(this, Jeux.class);
|
||||
intent.putExtra("EXTRA_NOMBRE_QUESTIONS", nombreQuestions);
|
||||
intent.putExtra("EXTRA_AJOUT_GORGEE", ajoutGorgees);
|
||||
intent.putExtra("EXTRA_RATIO_OPENAI", ratioBddOpenAI);
|
||||
intent.putExtra("EXTRA_OPENAI", openAI);
|
||||
final EditText editText = findViewById(R.id.editTextGPT);
|
||||
intent.putExtra("EXTRA_KEY_OPENAI",editText.getText().toString() );
|
||||
|
||||
toutlesjoueurs = getIntent().getStringArrayListExtra("EXTRA_LIST_JOUEUR");
|
||||
intent.putStringArrayListExtra("EXTRA_LIST_JOUEUR", (ArrayList<String>) toutlesjoueurs);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class Jeuxold extends AppCompatActivity {
|
||||
private List<String> toutlesjoueurs, phraseGPT;
|
||||
private int nombreQuestions;
|
||||
private int ajoutGorgees;
|
||||
boolean openAI;
|
||||
int ratiOpenai;
|
||||
String keyOpenai, phraseGPTString;
|
||||
|
||||
|
||||
public Jeuxold() {
|
||||
//System.out.println("Je suis dans le constructeur jeux");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_jeux);
|
||||
//Recuperation des valeurs des activités précédentes
|
||||
toutlesjoueurs = getIntent().getStringArrayListExtra("EXTRA_LIST_JOUEUR");
|
||||
nombreQuestions = getIntent().getIntExtra("EXTRA_NOMBRE_QUESTIONS", 75);
|
||||
ajoutGorgees = getIntent().getIntExtra("EXTRA_AJOUT_GORGEE", 0);
|
||||
openAI = getIntent().getBooleanExtra("EXTRA_OPENAI", false);
|
||||
ratiOpenai = getIntent().getIntExtra("EXTRA_RATIO_OPENAI", 0);
|
||||
keyOpenai = getIntent().getStringExtra("EXTRA_KEY_OPENAI");
|
||||
|
||||
|
||||
|
||||
System.out.println("ACTJeux all player : " + toutlesjoueurs);
|
||||
System.out.println("ACTJeux nombre de questions : " + nombreQuestions);
|
||||
System.out.println("ACTJeux ajout de gorgées : " + ajoutGorgees);
|
||||
System.out.println("ACTJeux openAI : " + openAI);
|
||||
System.out.println("ACTJeux ratio openAI : " + ratiOpenai);
|
||||
System.out.println("ACTJeux key openAI : " + keyOpenai);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Parti OpenAI ; keyOpenai ; ratiOpenai, openAI
|
||||
//new DatabaseConnection().execute();
|
||||
|
||||
// if(openAI) {
|
||||
// ChatGPTTask chatGPTTask = new ChatGPTTask( this, keyOpenai);
|
||||
// chatGPTTask.execute();
|
||||
//
|
||||
// }
|
||||
|
||||
//Phrase avec nom ou pas?
|
||||
/* if(JoueurOuPas()){
|
||||
PhraseAvecNom(toutlesjoueurs);
|
||||
}else{
|
||||
PhraseSansNom();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
public void handleExtractedMessage(String phraseGPTString) {
|
||||
// Traitez la réponse extraite ici
|
||||
System.out.println(phraseGPTString);
|
||||
// Par exemple, affichez-la dans une TextView ou effectuez une action en fonction de la réponse
|
||||
}
|
||||
|
||||
public void navigateToJeuxParametres() {
|
||||
Intent intent = new Intent(Jeuxold.this, JeuxParametres.class);
|
||||
Toast.makeText(getApplicationContext(), "Échec de la communication avec l'API !", Toast.LENGTH_SHORT).show();
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
/*public void PhraseAvecNom(List toutlesjoueurs){
|
||||
//System.out.println("Je suis dans phrase avec pseudo");
|
||||
List<String> phraseAvecNom = new ArrayList<String>();
|
||||
List aleatoirejoueurs = TroisJoueurAleatoire(toutlesjoueurs);
|
||||
phraseAvecNom.add(ChoixJoueurAleatoire(toutlesjoueurs) + " dois boire " + Gorgeesaleatoire(2, 4)+ " Gorgées");
|
||||
phraseAvecNom.add(ChoixJoueurAleatoire((toutlesjoueurs))+ " est le vieux briscard ! Interdiction de montrer tes dents pendant 5 manches");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0) + " et "+ aleatoirejoueurs.get(1) +" liser le premier SMS qui s'affiche quand on tape désolé dans la barre de recherche. Refusez pour 5 gorgées");
|
||||
phraseAvecNom.add( "A tour de role, vous avez exactement 3 secondes pour donner un mot en rapport avec le mots dit precedemment. Le joueur qui perd boit "+ Gorgeesaleatoire(2, 4) + " Gorgées! "+ aleatoirejoueurs.get(2)+" tu commences en choissisant un mot.");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+ " defie "+ aleatoirejoueurs.get(1) + " au chifoumi ! Le joueur qui gagne distribue 5 Gorgées");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+ " a toi de juger : entre "+aleatoirejoueurs.get(1)+ " et "+ aleatoirejoueurs.get(2) + " qui stresse le plus pour un rien selon toi? Cette personne se detendra en buvant " + Gorgeesaleatoire(3, 5 ) + " Gorgées");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" est dans le futur ! Tu dois parler au futur pendant 4 tours Une gorgées a chaque manque.");
|
||||
phraseAvecNom.add("Les joueurs de Counter Strike peuvent distribuer" + GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" tu bois autant de gorgées que tu as d'années d'études après le BAC");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" et "+aleatoirejoueurs.get(1)+" ferment leurs yeux ! Ils/Elles doivent deviner la couleur des yeux de l'autre. Si ils/elles se trompent, c'est "+GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" est manchot ! Il/Elle ne peut plus utiliser ses doigts durant 3 tours . Si il/elle s'en sert, il/elle devra boire autant de gorgées qu'il/elle a utilisé de doigts");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" et "+ aleatoirejoueurs.get(1)+" , si vous êtes ensemble dans la vraie vie, vous pouvez distribuer 2 gorgées , autrement buvez-les");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+", donne le nombre d'habitant du Tadjikistant ( à 1 000 000 près) ou boit "+GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" a la tourette ! A chaque fois que tu bois une gorgée, tu dois CRIER une insulte. C'est un stade avancé, ça dure 3 tours");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+", donne la couleur préférée de "+aleatoirejoueurs.get(1)+" si tu te trompes, c'est 2 gorgées");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" à l'oeil de serpent pendant 5 tours ! Dès qu'un joueur te regarde dans les yeux, il/elle boit. Si personne ne t'as regardé tu bois"+GorgeesaleatoireAmeliorer(5, 9));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" et "+ aleatoirejoueurs.get(1)+"se mesurent ! Le plus petit peut bois"+GorgeesaleatoireAmeliorer(3, 5));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" doit terminer toutes ses phrases par - C'est clair pendant 7 tours");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" distribue"+GorgeesaleatoireAmeliorer(2,5)+" à la personne que tu trouves la mieux foutue");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" distribue"+GorgeesaleatoireAmeliorer(2,5)+" à qui tu veux.");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" et "+aleatoirejoueurs.get(1)+" se défient au 'je te tiens, tu me tiens', le premier qui rit sera une tapette, et devra boire"+GorgeesaleatoireAmeliorer(4,6));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" et "+aleatoirejoueurs.get(1)+"n'ont plus le droit d'utiliser leur téléphone jusqu'à la fin du jeu ! A chaque manque c'est"+GorgeesaleatoireAmeliorer(1,3));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" et "+aleatoirejoueurs.get(1)+ "racontent une anecdote, celui/celle qui sort la plus banale boit "+GorgeesaleatoireAmeliorer(3, 6));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+", pour"+GorgeesaleatoireAmeliorer(2,4)+", a qui est ce slogan? Y a pas plus fort. (Vigor)");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+", Vrai ou faux? L'eau est bleu car elle reflète le ciel? (Non) Si tu as repondu faux tu devras boire : "+GorgeesaleatoireAmeliorer(2,4));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+", Si on te dit Marco? ... Si tu as dis Polo tu bois "+GorgeesaleatoireAmeliorer(1,3));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+", Boire un café fait baisser le taux d'alcool? "+GorgeesaleatoireAmeliorer(5, 8)+"en jeu (FAUX)");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" est l'aigris pendant 5tours ! Dès que tu souris ou rigoles, tu bois "+GorgeesaleatoireAmeliorer(2,3));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" fait un geste, le suivant répète et en ajoute un. Le perdant boit"+GorgeesaleatoireAmeliorer(3,5));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+", "+aleatoirejoueurs.get(2)+" et "+aleatoirejoueurs.get(1)+" vont désigner quelqu'un qui doit terminer son verre ");
|
||||
phraseAvecNom.add("Récitez l'alphabet en énonçant une lettre à tour de rôle. Si "+aleatoirejoueurs.get(0)+" finit son verre avant, cul sec pour tout le monde !");
|
||||
phraseAvecNom.add("Si"+aleatoirejoueurs.get(0)+" arrive a finir son verre en moins de 5 secondes, il/elle peut distribuer"+ GorgeesaleatoireAmeliorer(5, 8));
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" et "+ aleatoirejoueurs.get(1)+"sont lies, si l'un boit alors l'autre aussi, et ce pendant 5 tours");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+", "+aleatoirejoueurs.get(2)+" et "+ aleatoirejoueurs.get(1)+"sont lies, si l'un boit alors les autres aussi, et ce pendant 5 tours");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" dit un mot, la personne suivante le répète et en ajoute un nouveau, ainsi de suite jusqu'a ce que quelqu'un se trompe. Le perdant boit autant de gorgées qu'il y a eu de personne avant lui");
|
||||
phraseAvecNom.add(aleatoirejoueurs.get(0)+" doit choisir un mot que tout le monde devra dire à chaque fois qu'une personne boit.");
|
||||
//phraseAvecNom.add(aleatoirejoueurs.get(0)+"");
|
||||
//phraseAvecNom.add(aleatoirejoueurs.get(0)+"");
|
||||
//phraseAvecNom.add(aleatoirejoueurs.get(0)+"");
|
||||
//Affichage :
|
||||
TextView textView1 = (TextView) findViewById(R.id.textView1);
|
||||
textView1.setText(Nbaleatoirelist(phraseAvecNom));
|
||||
}
|
||||
public void PhraseSansNom(){
|
||||
//System.out.println("Je suis dans phrase sans pseudo");
|
||||
List<String> phraseSansNom = new ArrayList<String>();
|
||||
//Ajout de defis
|
||||
phraseSansNom.add("Tout le monde boit "+ Gorgeesaleatoire(1, 2)+" gorgée(s)");
|
||||
phraseSansNom.add("Quand l'heure affichera un multiple de 10 (22h, 22h10 ...) le premier a crier \"merde j'ai oublié mon chat\" distribura " + Gorgeesaleatoire(10, 12)+ " Gorgées");
|
||||
phraseSansNom.add("Ceux qui ont dansé aujourd'hui boivent 4 gorgées");
|
||||
phraseSansNom.add("Bois "+ Gorgeesaleatoire(2, 6)+ " Gorgées si tu n'as pas ton veritable nom sur insta");
|
||||
phraseSansNom.add("Bois "+ Gorgeesaleatoire(2, 3)+ " Gorgées si tu a des photos sur insta.");
|
||||
phraseSansNom.add("Plutôt ne plus avoir de mains ou de jambes? les perdants boivent "+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Celles/Ceux qui ont habité dans plus de 3 villes boivent "+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Vive la poésie ! Nos phrases doivent rimer sous peine d'une gorgée");
|
||||
phraseSansNom.add("Elisez le joueur le moins drôle d'entre vous, ce dernier boit" + GorgeesaleatoireAmeliorer(1,4 ));
|
||||
phraseSansNom.add("Elisez le joueur le plus drôle d'entre vous, ce dernier distribue" + GorgeesaleatoireAmeliorer(1,4 ));
|
||||
phraseSansNom.add("La dernière personne à avoir vomi en soirée distribue" + GorgeesaleatoireAmeliorer(2,4));
|
||||
phraseSansNom.add("Les filles peuvent distribuer"+ GorgeesaleatoireAmeliorer(1, 2));
|
||||
phraseSansNom.add("Les garçons peuvent distribuer"+ GorgeesaleatoireAmeliorer(1, 2));
|
||||
phraseSansNom.add("Toutes celles (ou ceux) qui ont du verni à ongles boivent"+GorgeesaleatoireAmeliorer(1,2));
|
||||
phraseSansNom.add("Tous les joueurs célibataires boivent"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Tous ceux qui ont des lunettes boivent"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Le premier joueur qui arrive à mettre son doigt dans le nez d'un autre joueur peut distribuer"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Tous ceux qui ont déjà triché à un examen boivent "+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Plutôt avoir un tapis volant, ou un frigo qui se remplit tout seul ? Votez tous en même temps. La minorité boit "+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Les couples trinquer ensemble "+ GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Le/La plus radin(e) boit"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Le mec qui a le plus gros ventre à bière boit"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Tous ceux qui se sont déjà fait exclure de cours boivent"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Tous ceux qui ont des frères et soeurs boivent"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Celles et ceux qui ont un Windows phone peuvent distribuer"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Celles/Ceux qui se sont déjà battus boivent"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Celui/Celle qui pèse le plus lourd boit "+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Pour se décoincer, le/la plus timide boit"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Le/La plus jeune boit"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Plutôt avoir du temps ou de l'argent ? Votez tous en même temps. La minorité boit"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Celles/Ceux qui ont fait des études de L boivent"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Le premier joueur qui en embrasse un autre sur la bouche pourra distribuer"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Celles et ceux qui joue de la guitare peuvent distribuer"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Celles et ceux qui joue du piano peuvent distribuer"+GorgeesaleatoireAmeliorer(1,4));
|
||||
phraseSansNom.add("Les gens qui se sont masturbés aujourd'hui peuvent distribuer"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Celui ou celle a la meilleure place boit"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Celles et ceux qui n'ont jamais trompé leur partenaire (c'est bien) peuvent distribuer"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Celui/Celle avec les vêtements les plus moches boit"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Celui/Celle qui a les cheveux les plus longs boit"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("On doit doser son Alcool les yeux fermés"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Plutôt série ou film ? Votez tous en même temps. La minorité boit"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Elisez le plus débile d'entre vous, ce dernier boit"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Le premier qui donne un film de - Christopher Nolan - pourra distribuer"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Le premier qui donne un film avec Christian Clavier pourra boire"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Les végans boivent "+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("La fille la plus maquillé boit"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Celles/Ceux qui ont déjà appelé leur partenaire par le prénom de leurs ex boivent"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("La première personne qui désigne le plus jeune peut distribuer"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Plutôt avoir des connaissances illimitées ou dirigier le monde ? Votez tous en même temps. La minorité boit"+GorgeesaleatoireAmeliorer(1, 4));
|
||||
phraseSansNom.add("Plutôt n'avoir aucun ami ou ne plus pouvoir utiliser d'appareil électronique ? Votez tous en même temps. La minorité boit"+ GorgeesaleatoireAmeliorer(2, 5));
|
||||
phraseSansNom.add("Plutot vaincre le patrikaka ou la polution dans le monde? Votez tous en meme temps. La minorité boit"+GorgeesaleatoireAmeliorer(1, 2));
|
||||
phraseSansNom.add("Jeu du LUTIN : Jusqu'a la fin du jeu. Vous devez enlever le lutin de votre verre pour pouvoir boire et le remettre ensuite sinon vous devait reboire");
|
||||
phraseSansNom.add("Celles et ceux qui boivent de la Vodka peuvent distribuer "+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Les joueurs qui ont un A dans leur prénom boivent "+GorgeesaleatoireAmeliorer(3,5));
|
||||
phraseSansNom.add("Les joueurs qui ont un P dans le prénom distribue"+GorgeesaleatoireAmeliorer(1, 3));
|
||||
phraseSansNom.add("Le premier joueur à ramener un objet rouge (pas de vêtements) peut distribuer"+GorgeesaleatoireAmeliorer(3,5));
|
||||
phraseSansNom.add("Le premier joueur qui dévoile un de ses secrets et que personne autour ne sait peut distribuer"+ GorgeesaleatoireAmeliorer(3, 6));
|
||||
phraseSansNom.add("Chaque joueur doit lire à haute voix le dernier SMS qu'il a reçu. Si il/elle refuse, c'est"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Le joueur avec le plus gros cul boit"+ GorgeesaleatoireAmeliorer(2, 6));
|
||||
phraseSansNom.add("Celles/Ceux qui ont moins de 20ans boivent"+ GorgeesaleatoireAmeliorer(2, 7));
|
||||
phraseSansNom.add("Celui ou celle avec le plus gros appetit sexuel boit"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Ceux/Celles qui fumes boivent "+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Celles et ceux qui ont au moins un BAC +3 peuvent distribuer"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Le premier joueur à se lever peut donner"+ GorgeesaleatoireAmeliorer(6, 7));
|
||||
phraseSansNom.add("Celles et ceux qui n'ont jamais fait de strip tease boivent"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Le premier joueur à enlever un vêtements pourra distribuer"+ GorgeesaleatoireAmeliorer(5, 7));
|
||||
phraseSansNom.add("Jeu des peaux ! Triez vous du joueur le plus bronzé au joueur le moins bronzé. Le plus bronzé prend 1 gorgée, le second 2 gorgées, etc.");
|
||||
phraseSansNom.add("Tous ceux qui ont déjà uriné dans une piscine boivent"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Celui/Celle avec le plus d'amis sur Facebook boit"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Celui/Celle avec le nom de famille le plus compliqué boit"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Les joueurs qui n'ont pas encore distribué de gorgées boivent"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Plutôt avoir du pouvoir ou de la connaissance ? Votez tous en même temps. La minorité boit"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("le plus gros dalleux avec les filles boit"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Le premier joueur à donner l'heure pourra distribuer"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Celles et ceux qui ont déjà dépenser plus de 2000 euros en un achat peuvent distribuer"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Le mec le moins courageux boit "+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
phraseSansNom.add("Celles/Ceux qui rentre chez eux à la fin de la soirée boivent"+ GorgeesaleatoireAmeliorer(8, 12));
|
||||
phraseSansNom.add("Il est désormais interdit de se tutoyer");
|
||||
phraseSansNom.add("Toutes les règles existantes sont annulées");
|
||||
phraseSansNom.add("Celles et ceux dont le jour d'anniversaire est un nombre impair boivent"+ GorgeesaleatoireAmeliorer(2, 4));
|
||||
//phraseSansNom.add("");
|
||||
//phraseSansNom.add("");
|
||||
//phraseSansNom.add("");
|
||||
//phraseSansNom.add("");
|
||||
//phraseSansNom.add("");
|
||||
//phraseSansNom.add("");
|
||||
//phraseSansNom.add("");
|
||||
//phraseSansNom.add("");
|
||||
//phraseSansNom.add("");*/
|
||||
|
||||
|
||||
//
|
||||
|
||||
//Affichage :
|
||||
TextView textView1 = (TextView) findViewById(R.id.textView1);
|
||||
//textView1.setText(Nbaleatoirelist(phraseSansNom));
|
||||
//}
|
||||
|
||||
public int Gorgeesaleatoire(int Min, int Max){
|
||||
int offset = ajoutGorgees;
|
||||
int nbgorgées;
|
||||
Random rand = new Random();
|
||||
if (Min == 1 && Max == 2){
|
||||
nbgorgées = rand.nextInt(Max + Min);
|
||||
}else {
|
||||
nbgorgées = Min+rand.nextInt(Max - Min);
|
||||
}
|
||||
if(nbgorgées == 0){
|
||||
nbgorgées = 1;
|
||||
}
|
||||
nbgorgées = nbgorgées + offset;
|
||||
return nbgorgées;
|
||||
}
|
||||
public String GorgeesaleatoireAmeliorer(int Min, int Max){
|
||||
int offset = ajoutGorgees;
|
||||
int nbgorgées;
|
||||
Random rand = new Random();
|
||||
if (Min == 1 && Max == 2){
|
||||
nbgorgées = rand.nextInt(Max + Min);
|
||||
}else {
|
||||
nbgorgées = Min+rand.nextInt(Max - Min);
|
||||
}
|
||||
if(nbgorgées == 0){
|
||||
nbgorgées = 1;
|
||||
}
|
||||
nbgorgées = nbgorgées + offset;
|
||||
String debut;
|
||||
|
||||
String nbgorgéesstr;
|
||||
String nbgorgéesstr1;
|
||||
debut = " ";
|
||||
nbgorgéesstr1 = " Gorgée(s)";
|
||||
nbgorgéesstr = debut + Integer.toString(nbgorgées) + nbgorgéesstr1;
|
||||
return nbgorgéesstr;
|
||||
}
|
||||
|
||||
public String Nbaleatoirelist(List list){
|
||||
Random rand = new Random();
|
||||
String phrase = (String) list.get(rand.nextInt(list.size()));
|
||||
return phrase;
|
||||
}
|
||||
public int Nbaleatoire(){
|
||||
int Max = 100;
|
||||
int Min = 0;
|
||||
Random rand = new Random();
|
||||
int nbaleatoire = rand.nextInt(Max - Min);
|
||||
return nbaleatoire;
|
||||
}
|
||||
public boolean JoueurOuPas(){
|
||||
boolean TrueFalse;
|
||||
int nbaleatoire = Nbaleatoire();
|
||||
int pourcentage = 40;
|
||||
//System.out.println(nbaleatoire);
|
||||
if(nbaleatoire >= pourcentage){
|
||||
TrueFalse = false;}
|
||||
else{
|
||||
TrueFalse = true;
|
||||
}
|
||||
//System.out.println(TrueFalse);
|
||||
return TrueFalse;
|
||||
}
|
||||
public List TroisJoueurAleatoire(List toutlesjoueurs){
|
||||
List<String> listJoueur = new ArrayList<String>();
|
||||
while (true){
|
||||
Random rand = new Random();
|
||||
String joueur1 = (String) toutlesjoueurs.get(rand.nextInt(toutlesjoueurs.size()));
|
||||
String joueur2 = (String) toutlesjoueurs.get(rand.nextInt(toutlesjoueurs.size()));
|
||||
String joueur3 = (String) toutlesjoueurs.get(rand.nextInt(toutlesjoueurs.size()));
|
||||
if(joueur1 == joueur2 ){
|
||||
}else{
|
||||
if (joueur1 == joueur3){
|
||||
}else {
|
||||
if (joueur2 == joueur3) {
|
||||
}else{
|
||||
listJoueur.add(joueur1);
|
||||
listJoueur.add(joueur2);
|
||||
listJoueur.add(joueur3);
|
||||
return listJoueur;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String ChoixJoueurAleatoire( List toutlesjoueurs){
|
||||
//System.out.println(inttoutlesjoueurs);
|
||||
Random rand = new Random();
|
||||
String joueur = (String) toutlesjoueurs.get(rand.nextInt(toutlesjoueurs.size()));
|
||||
//System.out.println(joueur);
|
||||
//int nbaleatoire = rand.nextInt(max -min + 1 ) + min;
|
||||
//int nbaleatoire2 = nbaleatoire - 1;
|
||||
//if(nbaleatoire2 == -1 ){
|
||||
// nbaleatoire2 = 0;
|
||||
//}
|
||||
//System.out.println( "nb aleatoire " + nbaleatoire) ;
|
||||
//joueur = (String) toutlesjoueurs.get(nbaleatoire2);
|
||||
//System.out.println(joueur);
|
||||
return joueur ;
|
||||
|
||||
}
|
||||
public void OnClickButton1(View v){
|
||||
finish();
|
||||
startActivity(getIntent());
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
// Votre code pour gérer les modifications d'orientation ici
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
String J1S, J2S, J3S;
|
||||
private int offset;
|
||||
private List<String> toutlesjoueurs;
|
||||
private TextInputEditText J1;
|
||||
private TextInputEditText J2;
|
||||
private TextInputEditText J3;
|
||||
private List<TextInputEditText> editTextList = new ArrayList<>();
|
||||
private List<View> playerRowList = new ArrayList<>(); // Liste des lignes de joueurs pour suppression
|
||||
private TextView playerCountText;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
// Récupérer le TextView du compteur
|
||||
playerCountText = findViewById(R.id.playerCountText);
|
||||
|
||||
// Initialiser les 3 champs statiques et ajouter les listeners
|
||||
J1 = findViewById(R.id.J1);
|
||||
J2 = findViewById(R.id.J2);
|
||||
J3 = findViewById(R.id.J3);
|
||||
|
||||
// Ajouter un TextWatcher à chaque champ pour mettre à jour le compteur
|
||||
TextWatcher playerCountWatcher = new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
updatePlayerCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {}
|
||||
};
|
||||
|
||||
if (J1 != null) J1.addTextChangedListener(playerCountWatcher);
|
||||
if (J2 != null) J2.addTextChangedListener(playerCountWatcher);
|
||||
if (J3 != null) J3.addTextChangedListener(playerCountWatcher);
|
||||
|
||||
// Mise à jour initiale
|
||||
updatePlayerCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour le compteur de joueurs en temps réel
|
||||
*/
|
||||
private void updatePlayerCount() {
|
||||
int count = 0;
|
||||
if (J1 != null && J1.getText() != null && !J1.getText().toString().isEmpty()) count++;
|
||||
if (J2 != null && J2.getText() != null && !J2.getText().toString().isEmpty()) count++;
|
||||
if (J3 != null && J3.getText() != null && !J3.getText().toString().isEmpty()) count++;
|
||||
|
||||
// Compter les champs dynamiques
|
||||
for (TextInputEditText edit : editTextList) {
|
||||
if (edit != null && edit.getText() != null && !edit.getText().toString().isEmpty()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerCountText != null) {
|
||||
playerCountText.setText("Joueurs: " + count + " / min. 3");
|
||||
}
|
||||
}
|
||||
|
||||
public void onClickButton1(View view) {
|
||||
LinearLayout nameEntryLayout = findViewById(R.id.nameEntryLayout);
|
||||
|
||||
// Créer un conteneur pour la ligne de joueur (EditText + Bouton supprimer)
|
||||
FrameLayout playerRow = new FrameLayout(this);
|
||||
LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
rowParams.setMargins(0, 8, 0, 8);
|
||||
playerRow.setLayoutParams(rowParams);
|
||||
|
||||
// Créer un nouveau TextInputLayout
|
||||
com.google.android.material.textfield.TextInputLayout textInputLayout = new com.google.android.material.textfield.TextInputLayout(this);
|
||||
FrameLayout.LayoutParams textInputParams = new FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
textInputParams.setMargins(0, 0, 60, 0); // Laisser de la place pour le bouton supprimer
|
||||
textInputLayout.setLayoutParams(textInputParams);
|
||||
textInputLayout.setBoxBackgroundMode(com.google.android.material.textfield.TextInputLayout.BOX_BACKGROUND_OUTLINE);
|
||||
textInputLayout.setHint("Nom");
|
||||
|
||||
// Appliquer les couleurs du thème pour la cohérence
|
||||
int primaryColor = androidx.core.content.ContextCompat.getColor(this, R.color.primary);
|
||||
int hintColor = androidx.core.content.ContextCompat.getColor(this, R.color.text_hint);
|
||||
textInputLayout.setBoxStrokeColor(primaryColor);
|
||||
textInputLayout.setDefaultHintTextColor(androidx.core.content.ContextCompat.getColorStateList(this, R.color.text_hint));
|
||||
|
||||
// Créer un nouveau TextInputEditText
|
||||
TextInputEditText newEditText = new TextInputEditText(this);
|
||||
newEditText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
newEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
|
||||
newEditText.setMaxLines(1);
|
||||
newEditText.setTextSize(16);
|
||||
newEditText.setTextColor(androidx.core.content.ContextCompat.getColor(this, R.color.text_primary));
|
||||
newEditText.setHintTextColor(androidx.core.content.ContextCompat.getColor(this, R.color.text_hint));
|
||||
|
||||
// Ajouter un TextWatcher pour mettre à jour le compteur en temps réel
|
||||
newEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
updatePlayerCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {}
|
||||
});
|
||||
|
||||
// Ajouter l'EditText au TextInputLayout
|
||||
textInputLayout.addView(newEditText);
|
||||
|
||||
// Créer le bouton de suppression
|
||||
ImageButton deleteButton = new ImageButton(this);
|
||||
FrameLayout.LayoutParams buttonParams = new FrameLayout.LayoutParams(
|
||||
(int) (48 * getResources().getDisplayMetrics().density),
|
||||
(int) (48 * getResources().getDisplayMetrics().density)
|
||||
);
|
||||
buttonParams.setMargins(0, 4, 8, 4);
|
||||
buttonParams.gravity = android.view.Gravity.END | android.view.Gravity.CENTER_VERTICAL;
|
||||
deleteButton.setLayoutParams(buttonParams);
|
||||
deleteButton.setBackgroundResource(android.R.drawable.ic_menu_delete);
|
||||
int errorColor = androidx.core.content.ContextCompat.getColor(this, R.color.error);
|
||||
deleteButton.setColorFilter(errorColor);
|
||||
deleteButton.setScaleType(ImageButton.ScaleType.CENTER_INSIDE);
|
||||
deleteButton.setContentDescription("Supprimer ce joueur");
|
||||
|
||||
// Configuration du bouton de suppression avec animation
|
||||
deleteButton.setOnClickListener(v -> removePlayerRow(playerRow, newEditText));
|
||||
|
||||
// Ajouter les éléments au conteneur
|
||||
playerRow.addView(textInputLayout);
|
||||
playerRow.addView(deleteButton);
|
||||
|
||||
// Ajouter à la liste et au layout avec animation
|
||||
editTextList.add(newEditText);
|
||||
playerRowList.add(playerRow);
|
||||
nameEntryLayout.addView(playerRow);
|
||||
|
||||
// Animation d'apparition
|
||||
BoideloAnimationUtils.popIn(playerRow, 300);
|
||||
BoideloAnimationUtils.triggerHapticFeedback(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime une ligne de joueur avec animation
|
||||
*/
|
||||
private void removePlayerRow(View playerRow, TextInputEditText editText) {
|
||||
BoideloAnimationUtils.triggerHapticFeedback(this);
|
||||
|
||||
// Animation de suppression
|
||||
BoideloAnimationUtils.slideOutToRemove(playerRow, 300, () -> {
|
||||
// Retirer de la liste et du layout après l'animation
|
||||
editTextList.remove(editText);
|
||||
playerRowList.remove(playerRow);
|
||||
ViewGroup parent = (ViewGroup) playerRow.getParent();
|
||||
if (parent != null) {
|
||||
parent.removeView(playerRow);
|
||||
}
|
||||
// Mettre à jour le compteur après suppression
|
||||
updatePlayerCount();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void onClickButtonStart(View view) {
|
||||
// Récupérer les 3 premiers champs de saisie
|
||||
J1 = findViewById(R.id.J1);
|
||||
if (J1 != null && J1.getText() != null) {
|
||||
J1S = J1.getText().toString();
|
||||
} else {
|
||||
J1S = "";
|
||||
}
|
||||
|
||||
J2 = findViewById(R.id.J2);
|
||||
if (J2 != null && J2.getText() != null) {
|
||||
J2S = J2.getText().toString();
|
||||
} else {
|
||||
J2S = "";
|
||||
}
|
||||
|
||||
J3 = findViewById(R.id.J3);
|
||||
if (J3 != null && J3.getText() != null) {
|
||||
J3S = J3.getText().toString();
|
||||
} else {
|
||||
J3S = "";
|
||||
}
|
||||
|
||||
// Creation d'une liste avec tt les j et verif si elle est completé
|
||||
toutlesjoueurs = new ArrayList<>();
|
||||
if (!J1S.isEmpty()) {
|
||||
toutlesjoueurs.add(J1S);
|
||||
}
|
||||
if (!J2S.isEmpty()) {
|
||||
toutlesjoueurs.add(J2S);
|
||||
}
|
||||
if (!J3S.isEmpty()) {
|
||||
toutlesjoueurs.add(J3S);
|
||||
}
|
||||
|
||||
// Ajouter les champs dynamiques
|
||||
int nbnom = editTextList.size();
|
||||
for (int i = 0; i < nbnom; i++) {
|
||||
TextInputEditText editText = editTextList.get(i);
|
||||
if (editText != null && editText.getText() != null) {
|
||||
String nom = editText.getText().toString();
|
||||
if (!nom.isEmpty()) {
|
||||
toutlesjoueurs.add(nom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
openParametres();
|
||||
}
|
||||
|
||||
public void openParametres(){
|
||||
//enregistrement des joueurs dans les shared preferences Joueurs
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("Joueurs", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
|
||||
editor.putString("J1", J1S != null ? J1S : "");
|
||||
editor.putString("J2", J2S != null ? J2S : "");
|
||||
editor.putString("J3", J3S != null ? J3S : "");
|
||||
|
||||
for (int i = 0; i < editTextList.size(); i++) {
|
||||
TextInputEditText editText = editTextList.get(i);
|
||||
if (editText != null && editText.getText() != null) {
|
||||
String nom = editText.getText().toString();
|
||||
editor.putString("J" + (i + 4), nom);
|
||||
}
|
||||
}
|
||||
|
||||
editor.apply();
|
||||
//Lancement de l'activité (Jeux_parametres)
|
||||
|
||||
Intent intent = new Intent(this, JeuxParametres.class);
|
||||
//Regarde si le pseudo est vide et envoie a l'activité jeux
|
||||
if (toutlesjoueurs.isEmpty()){
|
||||
Context context = getApplicationContext();
|
||||
CharSequence text = "Merci de rentrer des joueurs";
|
||||
int duration = Toast.LENGTH_SHORT;
|
||||
|
||||
Toast toast = Toast.makeText(context, text, duration);
|
||||
toast.show();
|
||||
}
|
||||
else {
|
||||
if (toutlesjoueurs.size() >= 3) {
|
||||
intent.putStringArrayListExtra("EXTRA_LIST_JOUEUR", (ArrayList<String>) toutlesjoueurs);
|
||||
intent.putExtra("EXTRA_OFFSET", offset);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Context context = getApplicationContext();
|
||||
CharSequence text = "La partie ne peux pas commencer avec moins de 3 joueurs";
|
||||
int duration = Toast.LENGTH_SHORT;
|
||||
Toast toast = Toast.makeText(context, text, duration);
|
||||
toast.show();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Question {
|
||||
private int id;
|
||||
private String question;
|
||||
private int gorger;
|
||||
private boolean distribution;
|
||||
private List<String> variante;
|
||||
private boolean recois;
|
||||
private boolean manches;
|
||||
private String arret; // mise à jour du type de données
|
||||
private int manchesRestantes; // pour le nombre de manches restantes
|
||||
private String arretMessage; // pour le message d'arrêt
|
||||
private String arretMessageManche; // pour le message d'arrêt pour les manches
|
||||
|
||||
// Constructeur par défaut
|
||||
public Question() {
|
||||
}
|
||||
|
||||
// Getters et setters pour tous les champs
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getQuestion() {
|
||||
return question;
|
||||
}
|
||||
|
||||
public void setQuestion(String question) {
|
||||
this.question = question;
|
||||
}
|
||||
|
||||
public int getGorger() {
|
||||
return gorger;
|
||||
}
|
||||
|
||||
public void setGorger(int gorger) {
|
||||
this.gorger = gorger;
|
||||
}
|
||||
|
||||
public boolean isDistribution() {
|
||||
return distribution;
|
||||
}
|
||||
|
||||
public void setDistribution(boolean distribution) {
|
||||
this.distribution = distribution;
|
||||
}
|
||||
|
||||
public List<String> getVariante() {
|
||||
return variante;
|
||||
}
|
||||
|
||||
public void setVariante(List<String> variante) {
|
||||
this.variante = variante;
|
||||
}
|
||||
|
||||
public boolean isRecois() {
|
||||
return recois;
|
||||
}
|
||||
|
||||
public void setRecois(boolean recois) {
|
||||
this.recois = recois;
|
||||
}
|
||||
|
||||
public boolean isManches() {
|
||||
return manches;
|
||||
}
|
||||
|
||||
public void setManches(boolean manches) {
|
||||
this.manches = manches;
|
||||
}
|
||||
|
||||
public String getArret() {
|
||||
return arret;
|
||||
}
|
||||
|
||||
public void setArret(String arret) {
|
||||
this.arret = arret;
|
||||
}
|
||||
|
||||
public int getManchesRestantes() {
|
||||
return manchesRestantes;
|
||||
}
|
||||
|
||||
public void setManchesRestantes(int manchesRestantes) {
|
||||
this.manchesRestantes = manchesRestantes;
|
||||
}
|
||||
|
||||
public String getArretMessage() {
|
||||
return arretMessage;
|
||||
}
|
||||
|
||||
public void setArretMessage(String arretMessage) {
|
||||
this.arretMessage = arretMessage;
|
||||
}
|
||||
public String getArretMessageManche() {
|
||||
return arretMessageManche;
|
||||
}
|
||||
|
||||
public void setArretMessageManche(String arretMessageManche) {
|
||||
this.arretMessageManche = arretMessageManche;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Questions {
|
||||
private String version;
|
||||
private List<Question> questions;
|
||||
|
||||
// Getters et setters pour chaque champ
|
||||
public List<Question> getQuestions() {
|
||||
return questions;
|
||||
}
|
||||
|
||||
// autres getters et setters...
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.example.boidelov3;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.SoundPool;
|
||||
|
||||
/**
|
||||
* Gestionnaire des effets sonores de l'application
|
||||
*/
|
||||
public class SoundManager {
|
||||
private static SoundManager instance;
|
||||
private SoundPool soundPool;
|
||||
private boolean soundEnabled = true;
|
||||
|
||||
// IDs des sons
|
||||
private int soundClick;
|
||||
private int soundSuccess;
|
||||
private int soundError;
|
||||
private int soundNext;
|
||||
private int soundManche;
|
||||
|
||||
/**
|
||||
* Obtient l'instance unique du SoundManager
|
||||
*/
|
||||
public static synchronized SoundManager getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = new SoundManager(context);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructeur privé
|
||||
*/
|
||||
private SoundManager(Context context) {
|
||||
AudioAttributes audioAttributes = new AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_GAME)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.build();
|
||||
|
||||
soundPool = new SoundPool.Builder()
|
||||
.setMaxStreams(5)
|
||||
.setAudioAttributes(audioAttributes)
|
||||
.build();
|
||||
|
||||
// Charger les sons (pour l'instant, on utilise des sons système)
|
||||
// TODO: Ajouter des fichiers audio personnalisés dans res/raw/
|
||||
// soundClick = soundPool.load(context, R.raw.click, 1);
|
||||
// soundSuccess = soundPool.load(context, R.raw.success, 1);
|
||||
// etc.
|
||||
}
|
||||
|
||||
/**
|
||||
* Joue le son de clic
|
||||
*/
|
||||
public void playClick() {
|
||||
if (soundEnabled && soundPool != null) {
|
||||
// Son de clic par défaut
|
||||
// Pour l'instant, feedback haptique uniquement
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Joue le son de succès
|
||||
*/
|
||||
public void playSuccess() {
|
||||
if (soundEnabled && soundPool != null) {
|
||||
// Son de succès par défaut
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Joue le son d'erreur
|
||||
*/
|
||||
public void playError() {
|
||||
if (soundEnabled && soundPool != null) {
|
||||
// Son d'erreur par défaut
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Joue le son de transition (question suivante)
|
||||
*/
|
||||
public void playNext() {
|
||||
if (soundEnabled && soundPool != null) {
|
||||
// Son de transition par défaut
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Joue le son de manche
|
||||
*/
|
||||
public void playManche() {
|
||||
if (soundEnabled && soundPool != null) {
|
||||
// Son de manche par défaut
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Active ou désactive les sons
|
||||
*/
|
||||
public void setSoundEnabled(boolean enabled) {
|
||||
this.soundEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne l'état des sons
|
||||
*/
|
||||
public boolean isSoundEnabled() {
|
||||
return soundEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Libère les ressources
|
||||
*/
|
||||
public void release() {
|
||||
if (soundPool != null) {
|
||||
soundPool.release();
|
||||
soundPool = null;
|
||||
}
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user