fix: correction de 16 bugs confirmés par double vérification IA
Bugs corrigés: - #1: saveGameStats() utilise currentQuestionIndex au lieu de totalQuestionsAsked - #3: Papelito - empêche un joueur de voter pour lui-même - #4: totalRoundsPlayed remplace playersWhoVoted.size() pour compter les rounds - #6: Null check sur toutlesjoueurs dans BoideloClassicGameActivity - #7: Standardisation de la clé PLAYER_STATS dans Jeux.java - #8: try-with-resources pour InputStream dans Jeux et QuestionRepository - #9: try-finally avec response.close() dans OpenAIService - #10: synchronized sur toutes les méthodes SoundGenerator - #12: MediaType.get() remplace MediaType.parse() (OkHttp 4.x) - #13: getSerializableExtra version-aware pour API 33+ - #15: Game89 - shuffle séquentiel des défis sans répétition - #17: Null check sur question.getQuestion() dans detectCategory - #18: Tracking des questions posées dans BoideloClassicGameActivity - #22: Suppression du SoundManager root stub en doublon - #29: stopMessage utilise questionText au lieu de question.getQuestion() - #30: Null check sur stopid dans Jeux.java
This commit is contained in:
@@ -83,11 +83,8 @@ public class EndGameActivity extends AppCompatActivity {
|
|||||||
playersCount = getIntent().getIntExtra("EXTRA_PLAYERS_COUNT", 0);
|
playersCount = getIntent().getIntExtra("EXTRA_PLAYERS_COUNT", 0);
|
||||||
players = getIntent().getStringArrayListExtra("EXTRA_PLAYERS");
|
players = getIntent().getStringArrayListExtra("EXTRA_PLAYERS");
|
||||||
|
|
||||||
// Essayer avec les deux clés possibles (PLAYER_STATS ou EXTRA_PLAYER_STATS)
|
// Récupérer les statistiques des joueurs
|
||||||
playerStatsList = getIntent().getParcelableArrayListExtra("PLAYER_STATS");
|
playerStatsList = getIntent().getParcelableArrayListExtra("PLAYER_STATS");
|
||||||
if (playerStatsList == null) {
|
|
||||||
playerStatsList = getIntent().getParcelableArrayListExtra("EXTRA_PLAYER_STATS");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si pas de données, utiliser les SharedPreferences
|
// Si pas de données, utiliser les SharedPreferences
|
||||||
if (questionsPlayed == 0) {
|
if (questionsPlayed == 0) {
|
||||||
|
|||||||
@@ -209,15 +209,15 @@ public class Jeux extends AppCompatActivity {
|
|||||||
*/
|
*/
|
||||||
private void loadQuestions() {
|
private void loadQuestions() {
|
||||||
try {
|
try {
|
||||||
InputStream is = getAssets().open("question.json");
|
try (InputStream is = getAssets().open("question.json")) {
|
||||||
int size = is.available();
|
int size = is.available();
|
||||||
byte[] buffer = new byte[size];
|
byte[] buffer = new byte[size];
|
||||||
is.read(buffer);
|
is.read(buffer);
|
||||||
is.close();
|
|
||||||
String json = new String(buffer, "UTF-8");
|
String json = new String(buffer, "UTF-8");
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
questions = gson.fromJson(json, Questions.class);
|
questions = gson.fromJson(json, Questions.class);
|
||||||
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
String operation = "Chargement du fichier question.json depuis les assets";
|
String operation = "Chargement du fichier question.json depuis les assets";
|
||||||
String details = "Impossible de lire ou de parser le fichier de questions";
|
String details = "Impossible de lire ou de parser le fichier de questions";
|
||||||
@@ -640,7 +640,7 @@ public class Jeux extends AppCompatActivity {
|
|||||||
|
|
||||||
// Passer les statistiques des joueurs
|
// Passer les statistiques des joueurs
|
||||||
ArrayList<PlayerStats> playerStatsList = new ArrayList<>(playerStatsMap.values());
|
ArrayList<PlayerStats> playerStatsList = new ArrayList<>(playerStatsMap.values());
|
||||||
intent.putParcelableArrayListExtra("EXTRA_PLAYER_STATS", playerStatsList);
|
intent.putParcelableArrayListExtra("PLAYER_STATS", playerStatsList);
|
||||||
|
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
||||||
@@ -958,6 +958,7 @@ public class Jeux extends AppCompatActivity {
|
|||||||
question.setManchesRestantes(nbaleatoiremanches);
|
question.setManchesRestantes(nbaleatoiremanches);
|
||||||
|
|
||||||
String stopid = getArretById(question.getId());
|
String stopid = getArretById(question.getId());
|
||||||
|
if (stopid == null) stopid = "Le défi est terminé !";
|
||||||
question.setArretMessageManche("Fin de défi!\n" + stopid);
|
question.setArretMessageManche("Fin de défi!\n" + stopid);
|
||||||
questionsAvecManches.add(question);
|
questionsAvecManches.add(question);
|
||||||
|
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ public class JeuxParametres extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Request request = requestBuilder
|
Request request = requestBuilder
|
||||||
.post(okhttp3.RequestBody.create(jsonBody, okhttp3.MediaType.parse("application/json")))
|
.post(okhttp3.RequestBody.create(jsonBody, okhttp3.MediaType.get("application/json")))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Exécuter la requête de test
|
// Exécuter la requête de test
|
||||||
|
|||||||
@@ -279,6 +279,7 @@ public class OpenAIService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call call, Response response) throws IOException {
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
try {
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
mainHandler.post(() -> callback.onError("Erreur API " + provider.getDisplayName() + ": " + response.code()));
|
mainHandler.post(() -> callback.onError("Erreur API " + provider.getDisplayName() + ": " + response.code()));
|
||||||
return;
|
return;
|
||||||
@@ -288,6 +289,9 @@ public class OpenAIService {
|
|||||||
String generatedQuestion = parseResponse(responseData, responseParser);
|
String generatedQuestion = parseResponse(responseData, responseParser);
|
||||||
|
|
||||||
mainHandler.post(() -> callback.onSuccess(generatedQuestion));
|
mainHandler.post(() -> callback.onSuccess(generatedQuestion));
|
||||||
|
} finally {
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -51,7 +51,12 @@ public class QuestionCategory {
|
|||||||
return Category.CLASSIQUE;
|
return Category.CLASSIQUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
String questionText = question.getQuestion().toLowerCase();
|
String text = question.getQuestion();
|
||||||
|
if (text == null) {
|
||||||
|
return Category.CLASSIQUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
String questionText = text.toLowerCase();
|
||||||
|
|
||||||
// 1. CALIENTE - Priorité haute
|
// 1. CALIENTE - Priorité haute
|
||||||
if (question.isCaliente()) {
|
if (question.isCaliente()) {
|
||||||
|
|||||||
@@ -46,10 +46,9 @@ public class QuestionRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream is = context.getAssets().open("question.json");
|
try (InputStream is = context.getAssets().open("question.json")) {
|
||||||
byte[] buffer = new byte[is.available()];
|
byte[] buffer = new byte[is.available()];
|
||||||
is.read(buffer);
|
is.read(buffer);
|
||||||
is.close();
|
|
||||||
|
|
||||||
String json = new String(buffer, "UTF-8");
|
String json = new String(buffer, "UTF-8");
|
||||||
cachedQuestions = gson.fromJson(json, Questions.class);
|
cachedQuestions = gson.fromJson(json, Questions.class);
|
||||||
@@ -60,6 +59,7 @@ public class QuestionRepository {
|
|||||||
|
|
||||||
Log.d(TAG, "Chargé " + cachedQuestions.getQuestions().size() + " questions");
|
Log.d(TAG, "Chargé " + cachedQuestions.getQuestions().size() + " questions");
|
||||||
return Result.success(cachedQuestions);
|
return Result.success(cachedQuestions);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "Erreur de chargement des questions", e);
|
Log.e(TAG, "Erreur de chargement des questions", e);
|
||||||
|
|||||||
+36
-5
@@ -26,11 +26,14 @@ import com.example.boidelov3.game.GameEngine;
|
|||||||
import com.example.boidelov3.Question;
|
import com.example.boidelov3.Question;
|
||||||
import com.example.boidelov3.Questions;
|
import com.example.boidelov3.Questions;
|
||||||
import com.example.boidelov3.utils.ErrorHandler;
|
import com.example.boidelov3.utils.ErrorHandler;
|
||||||
|
import android.widget.Toast;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BoideloClassicGameActivity - Activité principale du jeu Boidelo Classic
|
* BoideloClassicGameActivity - Activité principale du jeu Boidelo Classic
|
||||||
@@ -73,6 +76,9 @@ public class BoideloClassicGameActivity extends AppCompatActivity {
|
|||||||
// Random
|
// Random
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
|
// Track asked question indices to avoid repeats
|
||||||
|
private Set<Integer> askedQuestionIndices = new HashSet<>();
|
||||||
|
|
||||||
// Game Settings
|
// Game Settings
|
||||||
private int nombreQuestions = 20;
|
private int nombreQuestions = 20;
|
||||||
private int ajoutGorgees = 1;
|
private int ajoutGorgees = 1;
|
||||||
@@ -83,7 +89,6 @@ public class BoideloClassicGameActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
// Game State
|
// Game State
|
||||||
private int currentQuestionIndex = 0;
|
private int currentQuestionIndex = 0;
|
||||||
private int totalQuestionsAsked = 0;
|
|
||||||
private String currentQuestionText = "";
|
private String currentQuestionText = "";
|
||||||
private boolean isMancheActive = false;
|
private boolean isMancheActive = false;
|
||||||
private boolean isFinishingGame = false;
|
private boolean isFinishingGame = false;
|
||||||
@@ -111,6 +116,13 @@ public class BoideloClassicGameActivity extends AppCompatActivity {
|
|||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
toutlesjoueurs = intent.getStringArrayListExtra("PLAYERS");
|
toutlesjoueurs = intent.getStringArrayListExtra("PLAYERS");
|
||||||
|
|
||||||
|
// Vérifier que la liste des joueurs est valide
|
||||||
|
if (toutlesjoueurs == null || toutlesjoueurs.isEmpty()) {
|
||||||
|
Toast.makeText(this, "Erreur: liste des joueurs manquante", Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Récupérer les paramètres de jeu
|
// Récupérer les paramètres de jeu
|
||||||
if (intent.hasExtra("EXTRA_NOMBRE_QUESTIONS")) {
|
if (intent.hasExtra("EXTRA_NOMBRE_QUESTIONS")) {
|
||||||
nombreQuestions = intent.getIntExtra("EXTRA_NOMBRE_QUESTIONS", 20);
|
nombreQuestions = intent.getIntExtra("EXTRA_NOMBRE_QUESTIONS", 20);
|
||||||
@@ -367,8 +379,26 @@ public class BoideloClassicGameActivity extends AppCompatActivity {
|
|||||||
int maxAttempts = questions.size(); // Éviter boucle infinie
|
int maxAttempts = questions.size(); // Éviter boucle infinie
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
|
|
||||||
|
// Collect unasked indices
|
||||||
|
List<Integer> availableIndices = new ArrayList<>();
|
||||||
|
for (int i = 0; i < questions.size(); i++) {
|
||||||
|
if (!askedQuestionIndices.contains(i)) {
|
||||||
|
availableIndices.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If all questions have been asked, reset tracking
|
||||||
|
if (availableIndices.isEmpty()) {
|
||||||
|
askedQuestionIndices.clear();
|
||||||
|
for (int i = 0; i < questions.size(); i++) {
|
||||||
|
availableIndices.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (attempts < maxAttempts) {
|
while (attempts < maxAttempts) {
|
||||||
Question question = questions.get(random.nextInt(questions.size()));
|
int idx = random.nextInt(availableIndices.size());
|
||||||
|
int questionIndex = availableIndices.get(idx);
|
||||||
|
Question question = questions.get(questionIndex);
|
||||||
|
|
||||||
// Si un défi est en cours, éviter les questions avec <manches>
|
// Si un défi est en cours, éviter les questions avec <manches>
|
||||||
if (hasActiveDefi && question.getQuestion().contains("<manches>")) {
|
if (hasActiveDefi && question.getQuestion().contains("<manches>")) {
|
||||||
@@ -376,6 +406,7 @@ public class BoideloClassicGameActivity extends AppCompatActivity {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
askedQuestionIndices.add(questionIndex);
|
||||||
return question;
|
return question;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -794,7 +825,7 @@ public class BoideloClassicGameActivity extends AppCompatActivity {
|
|||||||
question.setManchesRestantes(nbaleatoiremanches);
|
question.setManchesRestantes(nbaleatoiremanches);
|
||||||
|
|
||||||
// Définir le message de fin de défi
|
// Définir le message de fin de défi
|
||||||
String stopMessage = "Fin de défi!\n" + question.getQuestion();
|
String stopMessage = "Fin de défi!\n" + questionText;
|
||||||
question.setArretMessageManche(stopMessage);
|
question.setArretMessageManche(stopMessage);
|
||||||
|
|
||||||
questionsAvecManches.add(question);
|
questionsAvecManches.add(question);
|
||||||
@@ -983,7 +1014,7 @@ public class BoideloClassicGameActivity extends AppCompatActivity {
|
|||||||
private void saveGameStats() {
|
private void saveGameStats() {
|
||||||
if (questionRepository != null && playerStatsMap != null) {
|
if (questionRepository != null && playerStatsMap != null) {
|
||||||
// Calculer le total des questions posées
|
// Calculer le total des questions posées
|
||||||
int totalQuestionsPlayed = totalQuestionsAsked;
|
int totalQuestionsPlayed = currentQuestionIndex;
|
||||||
int playersCount = toutlesjoueurs != null ? toutlesjoueurs.size() : 0;
|
int playersCount = toutlesjoueurs != null ? toutlesjoueurs.size() : 0;
|
||||||
|
|
||||||
// Sauvegarder dans SharedPreferences via le repository
|
// Sauvegarder dans SharedPreferences via le repository
|
||||||
@@ -1000,7 +1031,7 @@ public class BoideloClassicGameActivity extends AppCompatActivity {
|
|||||||
*/
|
*/
|
||||||
private void resetAskedQuestions() {
|
private void resetAskedQuestions() {
|
||||||
currentQuestionIndex = 0;
|
currentQuestionIndex = 0;
|
||||||
totalQuestionsAsked = 0;
|
askedQuestionIndices.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -394,7 +394,7 @@ public class BoideloClassicParamsActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Request request = requestBuilder
|
Request request = requestBuilder
|
||||||
.post(okhttp3.RequestBody.create(jsonBody, okhttp3.MediaType.parse("application/json")))
|
.post(okhttp3.RequestBody.create(jsonBody, okhttp3.MediaType.get("application/json")))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Exécuter la requête de test
|
// Exécuter la requête de test
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.boidelov3.games.game89;
|
package com.example.boidelov3.games.game89;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -10,11 +11,21 @@ import java.util.Random;
|
|||||||
public class Game89ChallengeManager {
|
public class Game89ChallengeManager {
|
||||||
private final Random random;
|
private final Random random;
|
||||||
private final List<Challenge> availableChallenges;
|
private final List<Challenge> availableChallenges;
|
||||||
|
private int currentIndex = 0;
|
||||||
|
|
||||||
public Game89ChallengeManager() {
|
public Game89ChallengeManager() {
|
||||||
this.random = new Random();
|
this.random = new Random();
|
||||||
this.availableChallenges = new ArrayList<>();
|
this.availableChallenges = new ArrayList<>();
|
||||||
initializeChallenges();
|
initializeChallenges();
|
||||||
|
shuffleChallenges();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mélange la liste des défis disponibles
|
||||||
|
*/
|
||||||
|
private void shuffleChallenges() {
|
||||||
|
Collections.shuffle(availableChallenges, random);
|
||||||
|
currentIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,14 +97,16 @@ public class Game89ChallengeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne un défi aléatoire
|
* Retourne le prochain défi (sans répétition tant que tous n'ont pas été utilisés)
|
||||||
*/
|
*/
|
||||||
public Challenge getRandomChallenge() {
|
public Challenge getRandomChallenge() {
|
||||||
if (availableChallenges.isEmpty()) {
|
if (availableChallenges.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int index = random.nextInt(availableChallenges.size());
|
if (currentIndex >= availableChallenges.size()) {
|
||||||
return availableChallenges.get(index);
|
shuffleChallenges();
|
||||||
|
}
|
||||||
|
return availableChallenges.get(currentIndex++);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ public class PapelitoGameActivity extends AppCompatActivity {
|
|||||||
private int currentPlayerViewIndex;
|
private int currentPlayerViewIndex;
|
||||||
private boolean hasShownWordToPlayer;
|
private boolean hasShownWordToPlayer;
|
||||||
private List<String> playersWhoVoted;
|
private List<String> playersWhoVoted;
|
||||||
|
private int currentVoterIndex = 0;
|
||||||
|
private int totalRoundsPlayed = 0;
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
private static final int DEFAULT_DISCUSSION_TIME = 60; // 60 secondes
|
private static final int DEFAULT_DISCUSSION_TIME = 60; // 60 secondes
|
||||||
@@ -303,6 +305,8 @@ public class PapelitoGameActivity extends AppCompatActivity {
|
|||||||
game.setGameState(PapelitoGame.GameState.VOTING);
|
game.setGameState(PapelitoGame.GameState.VOTING);
|
||||||
game.resetVotes();
|
game.resetVotes();
|
||||||
playersWhoVoted.clear();
|
playersWhoVoted.clear();
|
||||||
|
currentVoterIndex = 0;
|
||||||
|
totalRoundsPlayed++;
|
||||||
|
|
||||||
updateUIForVoting();
|
updateUIForVoting();
|
||||||
showVotingDialog();
|
showVotingDialog();
|
||||||
@@ -329,7 +333,9 @@ public class PapelitoGameActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
|
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
|
||||||
builder.setTitle("Vote pour éliminer");
|
// Determine current voter name for dialog title
|
||||||
|
String currentVoterName = alivePlayers.get(currentVoterIndex).getName();
|
||||||
|
builder.setTitle("Vote de " + currentVoterName + " - Qui voulez-vous éliminer?");
|
||||||
|
|
||||||
// Créer le layout personnalisé
|
// Créer le layout personnalisé
|
||||||
LinearLayout layout = new LinearLayout(this);
|
LinearLayout layout = new LinearLayout(this);
|
||||||
@@ -345,7 +351,13 @@ public class PapelitoGameActivity extends AppCompatActivity {
|
|||||||
GridLayout playerGrid = new GridLayout(this);
|
GridLayout playerGrid = new GridLayout(this);
|
||||||
playerGrid.setColumnCount(2);
|
playerGrid.setColumnCount(2);
|
||||||
|
|
||||||
for (PapelitoPlayer player : alivePlayers) {
|
for (int i = 0; i < alivePlayers.size(); i++) {
|
||||||
|
PapelitoPlayer player = alivePlayers.get(i);
|
||||||
|
// Skip the current voter so they can't vote for themselves
|
||||||
|
if (i == currentVoterIndex) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
MaterialButton playerButton = new MaterialButton(this);
|
MaterialButton playerButton = new MaterialButton(this);
|
||||||
playerButton.setText(player.getName());
|
playerButton.setText(player.getName());
|
||||||
playerButton.setLayoutParams(new LinearLayout.LayoutParams(
|
playerButton.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
@@ -380,6 +392,7 @@ public class PapelitoGameActivity extends AppCompatActivity {
|
|||||||
// Enregistrer le vote (simplifié : on ne track pas QUI a voté)
|
// Enregistrer le vote (simplifié : on ne track pas QUI a voté)
|
||||||
votedPlayer.addVote();
|
votedPlayer.addVote();
|
||||||
playersWhoVoted.add("vote");
|
playersWhoVoted.add("vote");
|
||||||
|
currentVoterIndex++;
|
||||||
|
|
||||||
Toast.makeText(this,
|
Toast.makeText(this,
|
||||||
"Vote enregistré pour " + votedPlayer.getName(),
|
"Vote enregistré pour " + votedPlayer.getName(),
|
||||||
@@ -509,7 +522,7 @@ public class PapelitoGameActivity extends AppCompatActivity {
|
|||||||
intent.putExtra(PapelitoResultActivity.EXTRA_WINNING_TEAM, game.getWinningTeam());
|
intent.putExtra(PapelitoResultActivity.EXTRA_WINNING_TEAM, game.getWinningTeam());
|
||||||
intent.putExtra(PapelitoResultActivity.EXTRA_CIVIL_WORD, game.getCurrentCivilWord());
|
intent.putExtra(PapelitoResultActivity.EXTRA_CIVIL_WORD, game.getCurrentCivilWord());
|
||||||
intent.putExtra(PapelitoResultActivity.EXTRA_UNDERCOVER_WORD, game.getCurrentUndercoverWord());
|
intent.putExtra(PapelitoResultActivity.EXTRA_UNDERCOVER_WORD, game.getCurrentUndercoverWord());
|
||||||
intent.putExtra(PapelitoResultActivity.EXTRA_TOTAL_ROUNDS, playersWhoVoted.size());
|
intent.putExtra(PapelitoResultActivity.EXTRA_TOTAL_ROUNDS, totalRoundsPlayed);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.boidelov3.games.papelito;
|
package com.example.boidelov3.games.papelito;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -46,9 +47,22 @@ public class PapelitoResultActivity extends AppCompatActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_papelito_result);
|
setContentView(R.layout.activity_papelito_result);
|
||||||
|
|
||||||
// Récupérer les données
|
// Récupérer les données (compatibilité API 33+)
|
||||||
|
ArrayList<PapelitoPlayer> players;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
players = getIntent().getSerializableExtra(EXTRA_PLAYERS, ArrayList.class);
|
||||||
|
} else {
|
||||||
players = (ArrayList<PapelitoPlayer>) getIntent().getSerializableExtra(EXTRA_PLAYERS);
|
players = (ArrayList<PapelitoPlayer>) getIntent().getSerializableExtra(EXTRA_PLAYERS);
|
||||||
|
}
|
||||||
|
this.players = players;
|
||||||
|
|
||||||
|
PapelitoPlayer.Role winningTeam;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
winningTeam = getIntent().getSerializableExtra(EXTRA_WINNING_TEAM, PapelitoPlayer.Role.class);
|
||||||
|
} else {
|
||||||
winningTeam = (PapelitoPlayer.Role) getIntent().getSerializableExtra(EXTRA_WINNING_TEAM);
|
winningTeam = (PapelitoPlayer.Role) getIntent().getSerializableExtra(EXTRA_WINNING_TEAM);
|
||||||
|
}
|
||||||
|
this.winningTeam = winningTeam;
|
||||||
civilWord = getIntent().getStringExtra(EXTRA_CIVIL_WORD);
|
civilWord = getIntent().getStringExtra(EXTRA_CIVIL_WORD);
|
||||||
undercoverWord = getIntent().getStringExtra(EXTRA_UNDERCOVER_WORD);
|
undercoverWord = getIntent().getStringExtra(EXTRA_UNDERCOVER_WORD);
|
||||||
totalRounds = getIntent().getIntExtra(EXTRA_TOTAL_ROUNDS, 0);
|
totalRounds = getIntent().getIntExtra(EXTRA_TOTAL_ROUNDS, 0);
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.example.boidelov3.rules;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
public class RuleDetailActivity extends Activity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
// TODO: Implement rule detail screen
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.example.boidelov3.rules;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
public class RulesListActivity extends Activity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
// TODO: Implement rules list screen
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,8 +26,8 @@ public class SoundGenerator {
|
|||||||
/**
|
/**
|
||||||
* Son de clic - court et léger
|
* Son de clic - court et léger
|
||||||
*/
|
*/
|
||||||
public void playClick() {
|
public synchronized void playClick() {
|
||||||
if (isMuted) return;
|
if (isMuted || toneGenerator == null) return;
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
toneGenerator.startTone(
|
toneGenerator.startTone(
|
||||||
@@ -43,8 +43,8 @@ public class SoundGenerator {
|
|||||||
/**
|
/**
|
||||||
* Son de succès - mélange ascendant
|
* Son de succès - mélange ascendant
|
||||||
*/
|
*/
|
||||||
public void playSuccess() {
|
public synchronized void playSuccess() {
|
||||||
if (isMuted) return;
|
if (isMuted || toneGenerator == null) return;
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(0);
|
Thread.sleep(0);
|
||||||
@@ -66,8 +66,8 @@ public class SoundGenerator {
|
|||||||
/**
|
/**
|
||||||
* Son de manche - dramatique pour annoncer un défi
|
* Son de manche - dramatique pour annoncer un défi
|
||||||
*/
|
*/
|
||||||
public void playManche() {
|
public synchronized void playManche() {
|
||||||
if (isMuted) return;
|
if (isMuted || toneGenerator == null) return;
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
// Premier ton grave
|
// Premier ton grave
|
||||||
@@ -90,8 +90,8 @@ public class SoundGenerator {
|
|||||||
/**
|
/**
|
||||||
* Son de fin - célébration
|
* Son de fin - célébration
|
||||||
*/
|
*/
|
||||||
public void playFin() {
|
public synchronized void playFin() {
|
||||||
if (isMuted) return;
|
if (isMuted || toneGenerator == null) return;
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
// Séquence festive
|
// Séquence festive
|
||||||
@@ -118,14 +118,14 @@ public class SoundGenerator {
|
|||||||
/**
|
/**
|
||||||
* Activer/Désactiver le son
|
* Activer/Désactiver le son
|
||||||
*/
|
*/
|
||||||
public void setMuted(boolean muted) {
|
public synchronized void setMuted(boolean muted) {
|
||||||
this.isMuted = muted;
|
this.isMuted = muted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Libérer les ressources
|
* Libérer les ressources
|
||||||
*/
|
*/
|
||||||
public void release() {
|
public synchronized void release() {
|
||||||
if (toneGenerator != null) {
|
if (toneGenerator != null) {
|
||||||
toneGenerator.release();
|
toneGenerator.release();
|
||||||
toneGenerator = null;
|
toneGenerator = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user