Commit c7279f62 authored by mohamed20047's avatar mohamed20047

add best streak. and handle its UI in result menu

parent 173a851c
...@@ -154,7 +154,7 @@ namespace com.al_arcade.cs ...@@ -154,7 +154,7 @@ namespace com.al_arcade.cs
protected override void BeginGameplay() protected override void BeginGameplay()
{ {
_currentIndex = _score = _streak = _correctCount = _wrongCount = 0; _currentIndex = _score = _streak = _correctCount = _wrongCount = _bestStreak = 0;
_deltaChangeInSize = 0; _deltaChangeInSize = 0;
_timeLeft = CsPrefabBuilder.Instance.startTime; // CS uses its own start time _timeLeft = CsPrefabBuilder.Instance.startTime; // CS uses its own start time
_timerRunning = true; _timerRunning = true;
...@@ -225,6 +225,7 @@ namespace com.al_arcade.cs ...@@ -225,6 +225,7 @@ namespace com.al_arcade.cs
AdjustTimer(-CsPrefabBuilder.Instance.wrongAnswerPenaltyTime); AdjustTimer(-CsPrefabBuilder.Instance.wrongAnswerPenaltyTime);
_wrongClicks++; _wrongClicks++;
_wordClickLocked = true; _wordClickLocked = true;
_streak = 0; // reset streak when click on worng word
wordButton.ShakeWrong(); wordButton.ShakeWrong();
SSAudioManager.Instance?.PlayWrongBeep(); SSAudioManager.Instance?.PlayWrongBeep();
StartCoroutine(UnlockAfterCooldown()); StartCoroutine(UnlockAfterCooldown());
...@@ -323,6 +324,7 @@ namespace com.al_arcade.cs ...@@ -323,6 +324,7 @@ namespace com.al_arcade.cs
_state = CsGameState.Feedback; _state = CsGameState.Feedback;
_correctCount++; _correctCount++;
_streak++; _streak++;
if (_streak > _bestStreak) _bestStreak = _streak;
_deltaChangeInSize++; _deltaChangeInSize++;
AdjustTimer(CsPrefabBuilder.Instance.correctAnswerBonusTime); AdjustTimer(CsPrefabBuilder.Instance.correctAnswerBonusTime);
...@@ -415,7 +417,7 @@ namespace com.al_arcade.cs ...@@ -415,7 +417,7 @@ namespace com.al_arcade.cs
StartCoroutine(DelayedAction(0.7f, () => SSAudioManager.Instance.PlayCheer())); // shared helper StartCoroutine(DelayedAction(0.7f, () => SSAudioManager.Instance.PlayCheer())); // shared helper
yield return new WaitForSeconds(1f); yield return new WaitForSeconds(1f);
uiManager?.ShowResults(_score, _correctCount, _wrongClicks, _questions.Length, _streak); uiManager?.ShowResults(_score, _correctCount, _wrongClicks, _questions.Length, _bestStreak);
onGameComplete?.Invoke(_score); onGameComplete?.Invoke(_score);
ClearWordButtons(); ClearWordButtons();
...@@ -423,7 +425,7 @@ namespace com.al_arcade.cs ...@@ -423,7 +425,7 @@ namespace com.al_arcade.cs
protected override IEnumerator NoChallengeLoseSequence() protected override IEnumerator NoChallengeLoseSequence()
{ {
uiManager?.ShowResults(_score, _correctCount, _wrongClicks, _questions.Length, _streak, false); uiManager?.ShowResults(_score, _correctCount, _wrongClicks, _questions.Length, _bestStreak, false);
yield return null; yield return null;
} }
......
...@@ -476,12 +476,13 @@ namespace com.al_arcade.cs ...@@ -476,12 +476,13 @@ namespace com.al_arcade.cs
_resultsUI.alpha = 0; _resultsUI.alpha = 0;
float pct = total > 0 ? (float)correct / total * 100f : 0; float pct = total > 0 ? (float)correct / total * 100f : 0;
if (_resultTitle != null) //if (_resultTitle != null)
_resultTitle.Text = win ? pct >= 70 ? "أحسنت!" : "عمل جيد!" : "حظ اوفر"; // _resultTitle.Text = win ? pct >= 70 ? "أحسنت!" : "عمل جيد!" : "حظ اوفر";
if (_resultScore != null) _resultScore.Text = score.ToString("N0"); //if (_resultScore != null) _resultScore.Text = score.ToString("N0");
if (_resultStats != null) if (_resultStats != null)
_resultStats.Text = $"صحيح: {correct} | " + _resultStats.Text = $"صحيح: {correct} | " +
$"المحاولات الخاطئة: {wrong} "; $"المحاولات الخاطئة: {wrong} | " +
$"أعلى سلسلة: {bestStreak}";
var seq = DOTween.Sequence(); var seq = DOTween.Sequence();
seq.Append(_resultsUI.DOFade(1f, 0.5f)); seq.Append(_resultsUI.DOFade(1f, 0.5f));
......
...@@ -43,7 +43,7 @@ namespace com.al_arcade.mcq ...@@ -43,7 +43,7 @@ namespace com.al_arcade.mcq
public McqGameState State => _state; public McqGameState State => _state;
private McqQuestion[] _questions; private McqQuestion[] _questions;
private int _bestStreak;
private List<McqGateController> _activeGates = new(); private List<McqGateController> _activeGates = new();
private int _correctGateIndex = -1; private int _correctGateIndex = -1;
private int _selectedGateIndex = -1; private int _selectedGateIndex = -1;
...@@ -224,7 +224,6 @@ namespace com.al_arcade.mcq ...@@ -224,7 +224,6 @@ namespace com.al_arcade.mcq
{ {
ResetBaseState(); ResetBaseState();
_state = McqGameState.Idle; _state = McqGameState.Idle;
_bestStreak = 0;
_isTicking = false; _isTicking = false;
// ✅ NEW: reset delta on full reset // ✅ NEW: reset delta on full reset
_deltaChangeInSize = 0; _deltaChangeInSize = 0;
...@@ -651,7 +650,7 @@ namespace com.al_arcade.mcq ...@@ -651,7 +650,7 @@ namespace com.al_arcade.mcq
yield return new WaitForSeconds(0.5f); yield return new WaitForSeconds(0.5f);
if (uiManager != null) if (uiManager != null)
uiManager.ShowResults(_score, _correctCount, _wrongCount, uiManager.ShowResults(_score, _correctCount, _wrongCount,
_bestStreak, _questions.Length, true); _questions.Length, _bestStreak, true);
onGameComplete?.Invoke(_score); onGameComplete?.Invoke(_score);
} }
...@@ -676,11 +675,9 @@ namespace com.al_arcade.mcq ...@@ -676,11 +675,9 @@ namespace com.al_arcade.mcq
yield return new WaitForSeconds(0.5f); yield return new WaitForSeconds(0.5f);
if (uiManager != null) if (uiManager != null)
uiManager.ShowResults(_score, _correctCount, _wrongCount, uiManager.ShowResults(_score, _correctCount, _wrongCount,
_bestStreak, _questions.Length, false); _questions.Length, _bestStreak, false);
onGameOver?.Invoke(); onGameOver?.Invoke();
} }
public int BestStreak => _bestStreak;
public int TotalQuestions => _questions?.Length ?? 0; public int TotalQuestions => _questions?.Length ?? 0;
} }
} }
\ No newline at end of file
...@@ -294,11 +294,12 @@ namespace com.al_arcade.mcq ...@@ -294,11 +294,12 @@ namespace com.al_arcade.mcq
_resultsUI.gameObject.SetActive(true); _resultsUI.gameObject.SetActive(true);
_resultsUI.alpha = 0; _resultsUI.alpha = 0;
if (_resultTitle != null) _resultTitle.Text = win ? "أحسنت!" : "حظ أوفر!"; //if (_resultTitle != null) _resultTitle.Text = win ? "أحسنت!" : "حظ أوفر!";
if (_resultScore != null) _resultScore.Text = score.ToString("N0"); //if (_resultScore != null) _resultScore.Text = score.ToString("N0");
if (_resultStats != null) if (_resultStats != null)
_resultStats.Text = $"صحيح: {correct} | " + _resultStats.Text = $"صحيح: {correct} | " +
$"المحاولات الخاطئة: {wrong} " ; $"المحاولات الخاطئة: {wrong} | " +
$"أعلى سلسلة: {bestStreak}"; ;
if (_winIcon != null) _winIcon.SetActive(win); if (_winIcon != null) _winIcon.SetActive(win);
if (_loseIcon != null) _loseIcon.SetActive(!win); if (_loseIcon != null) _loseIcon.SetActive(!win);
......
...@@ -30,6 +30,7 @@ namespace com.al_arcade.shared ...@@ -30,6 +30,7 @@ namespace com.al_arcade.shared
// ─── Shared runtime state ──────────────────────────────────────────── // ─── Shared runtime state ────────────────────────────────────────────
protected int _score; protected int _score;
protected int _streak; protected int _streak;
protected int _bestStreak;
protected int _correctCount; protected int _correctCount;
protected int _wrongCount; protected int _wrongCount;
protected int _currentIndex; protected int _currentIndex;
...@@ -219,7 +220,7 @@ namespace com.al_arcade.shared ...@@ -219,7 +220,7 @@ namespace com.al_arcade.shared
protected void ResetBaseState() protected void ResetBaseState()
{ {
StopAllCoroutines(); StopAllCoroutines();
_score = _streak = _correctCount = _wrongCount = _currentIndex = _totalAsked = 0; _score = _streak = _correctCount = _wrongCount = _currentIndex = _totalAsked =_bestStreak= 0;
_timeLeft = 0f; _timeLeft = 0f;
_timerRunning = false; _timerRunning = false;
} }
......
...@@ -99,7 +99,7 @@ namespace com.al_arcade.tf ...@@ -99,7 +99,7 @@ namespace com.al_arcade.tf
protected override void BeginGameplay() protected override void BeginGameplay()
{ {
_progress = 0; _progress = 0;
_currentIndex = _score = _streak = _correctCount = _wrongCount = _totalAsked = 0; _currentIndex = _score = _streak = _correctCount = _wrongCount = _totalAsked = _bestStreak = 0;
_state = TfGameState.Playing; _state = TfGameState.Playing;
if (uiManager != null) if (uiManager != null)
...@@ -199,6 +199,7 @@ namespace com.al_arcade.tf ...@@ -199,6 +199,7 @@ namespace com.al_arcade.tf
{ {
_correctCount++; _correctCount++;
_streak++; _streak++;
if (_streak > _bestStreak) _bestStreak = _streak;
_progress++; _progress++;
int points = CalculateStreakScore(); int points = CalculateStreakScore();
_score += points; _score += points;
...@@ -212,7 +213,7 @@ namespace com.al_arcade.tf ...@@ -212,7 +213,7 @@ namespace com.al_arcade.tf
if (handController != null) handController.PlayCorrectFeedback(playerSaidTrue); if (handController != null) handController.PlayCorrectFeedback(playerSaidTrue);
if (productionLine != null) yield return productionLine.MoveForward(stepDistance); if (productionLine != null) yield return productionLine.MoveForward(stepDistance);
if (questionScreen != null) questionScreen.ShowFeedback(true, _streak); //if (questionScreen != null) questionScreen.ShowFeedback(true, _streak);
if (uiManager != null) uiManager.ShowFeedback($"ممتاز!", true); if (uiManager != null) uiManager.ShowFeedback($"ممتاز!", true);
...@@ -239,7 +240,7 @@ namespace com.al_arcade.tf ...@@ -239,7 +240,7 @@ namespace com.al_arcade.tf
if (handController != null) handController.PlayWrongFeedback(playerSaidTrue); if (handController != null) handController.PlayWrongFeedback(playerSaidTrue);
if (productionLine != null) yield return productionLine.MoveBackward(stepDistance); if (productionLine != null) yield return productionLine.MoveBackward(stepDistance);
if (questionScreen != null) questionScreen.ShowFeedback(false, 0); //if (questionScreen != null) questionScreen.ShowFeedback(false, 0);
if (uiManager != null) uiManager.ShowFeedback("حاول مرة أخرى", false); if (uiManager != null) uiManager.ShowFeedback("حاول مرة أخرى", false);
...@@ -305,7 +306,7 @@ namespace com.al_arcade.tf ...@@ -305,7 +306,7 @@ namespace com.al_arcade.tf
protected override IEnumerator NoChallengeLoseSequence() protected override IEnumerator NoChallengeLoseSequence()
{ {
yield return new WaitForSeconds(1f); yield return new WaitForSeconds(1f);
uiManager?.ShowResults(_score, _correctCount, _wrongCount,_questions.Length, _streak, false); uiManager?.ShowResults(_score, _correctCount, _wrongCount,_questions.Length, _bestStreak, false);
onGameOver?.Invoke(); onGameOver?.Invoke();
} }
...@@ -327,7 +328,7 @@ namespace com.al_arcade.tf ...@@ -327,7 +328,7 @@ namespace com.al_arcade.tf
protected override IEnumerator NoChallengeVictorySequence() protected override IEnumerator NoChallengeVictorySequence()
{ {
yield return new WaitForSeconds(1.5f); yield return new WaitForSeconds(1.5f);
uiManager?.ShowResults(_score, _correctCount, _wrongCount,_questions.Length ,_streak); uiManager?.ShowResults(_score, _correctCount, _wrongCount,_questions.Length ,_bestStreak);
onGameComplete?.Invoke(); onGameComplete?.Invoke();
} }
......
...@@ -234,11 +234,12 @@ namespace com.al_arcade.tf ...@@ -234,11 +234,12 @@ namespace com.al_arcade.tf
_resultsUI.gameObject.SetActive(true); _resultsUI.gameObject.SetActive(true);
_resultsUI.alpha = 0; _resultsUI.alpha = 0;
if (_resultTitle != null) _resultTitle.Text = win ? "نجحت المهمة" : "حاول مجدداً"; //if (_resultTitle != null) _resultTitle.Text = win ? "نجحت المهمة" : "حاول مجدداً";
if (_resultScore != null) _resultScore.Text = score.ToString("N0"); //if (_resultScore != null) _resultScore.Text = score.ToString("N0");
if (_resultStats != null) if (_resultStats != null)
_resultStats.Text = $"صحيح: {correct} | " + _resultStats.Text = $"صحيح: {correct} | " +
$"المحاولات الخاطئة: {wrong} " ; $"المحاولات الخاطئة: {wrong} | " +
$"أعلى سلسلة: {bestStreak}"; ;
var seq = DOTween.Sequence(); var seq = DOTween.Sequence();
seq.Append(_resultsUI.DOFade(1, 0.4f)); seq.Append(_resultsUI.DOFade(1, 0.4f));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment