From 8acd62de5a3cfa9bfb13f83d96ac0d93ec72339d Mon Sep 17 00:00:00 2001 From: Mia Kelley-Lanser Date: Thu, 17 Oct 2024 23:39:39 -0400 Subject: [PATCH] Made red when incorrect, adjusted interval times --- Assets/Scripts/ReactionTest.cs | 34 ++++++++++++++++++++++++++++------ Assets/Scripts/TimedTest.cs | 10 +++++++++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/ReactionTest.cs b/Assets/Scripts/ReactionTest.cs index 10edd8a..769a039 100644 --- a/Assets/Scripts/ReactionTest.cs +++ b/Assets/Scripts/ReactionTest.cs @@ -14,33 +14,41 @@ public enum Reaction_curDirection { RIGHT, } - protected int minWaitTime = 2; - protected int maxWaitTime = 3; + protected int minWaitTime = 1; + protected int maxWaitTime = 5; protected float intervalTimer = 0f; protected bool intervalTimerRunning = true; protected Reaction_curDirection curDirection = Reaction_curDirection.NONE; + Color normalColor; + Color wrongColor = new Color(100f, 0f, 0f, 100f); + + protected bool acceptingInput = false; + public override void UpdateTest() { base.UpdateTest(); if (curDirection == Reaction_curDirection.NONE) { if (intervalTimer <= 0) { showArrow(); + acceptingInput = true; startShowTime(); intervalTimer = Random.Range(minWaitTime, maxWaitTime); } else { intervalTimer -= Time.deltaTime; } - } else { + } else if (acceptingInput) { if (Keyboard.current.leftArrowKey.wasPressedThisFrame) { + acceptingInput = false; if (curDirection == Reaction_curDirection.LEFT) { correctAnswerGiven(); } else { wrongAnswerGiven(); } } else if (Keyboard.current.rightArrowKey.wasPressedThisFrame) { + acceptingInput = false; if (curDirection == Reaction_curDirection.RIGHT) { correctAnswerGiven(); } else { @@ -53,6 +61,8 @@ public override void UpdateTest() { public override void InitializeTest() { base.InitializeTest(); + normalColor = curTimerColor; + leftArrow.gameObject.SetActive(false); rightArrow.gameObject.SetActive(false); } @@ -89,16 +99,28 @@ protected void hideArrow() { } protected void correctAnswerGiven() { - Debug.Log("Correct"); + pauseTimer(); + StartCoroutine(delayHideArrowCorrect(1.0f)); + } + + protected void wrongAnswerGiven() { + pauseTimer(); + setTimerColor(wrongColor); + StartCoroutine(delayHideArrowWrong(1.0f)); + } + + protected IEnumerator delayHideArrowCorrect(float seconds) { + yield return new WaitForSeconds(seconds); pauseSaveResetHideTime(); hideArrow(); intervalTimer = Random.Range(minWaitTime, maxWaitTime); } - protected void wrongAnswerGiven() { - Debug.Log("Wrong"); + protected IEnumerator delayHideArrowWrong(float seconds) { + yield return new WaitForSeconds(seconds); pauseResetHideTime(); hideArrow(); intervalTimer = Random.Range(minWaitTime, maxWaitTime); + setTimerColor(normalColor); } } diff --git a/Assets/Scripts/TimedTest.cs b/Assets/Scripts/TimedTest.cs index 1765319..3717fd4 100644 --- a/Assets/Scripts/TimedTest.cs +++ b/Assets/Scripts/TimedTest.cs @@ -13,7 +13,9 @@ public class TimedTest : Test private Canvas canvas; - private GameObject timerText; + protected GameObject timerText; + + protected Color curTimerColor; public TimedTest() : base() { @@ -38,6 +40,7 @@ public override void InitializeTest() { timerText.AddComponent().alignment = TextAlignment.Left; timerText.GetComponent().SetParent(canvas.GetComponent()); timerText.GetComponent().anchoredPosition = new Vector3(0, 0, 0); + curTimerColor = timerText.GetComponent().color; } // destroy timer text and return the lowest time as score @@ -51,6 +54,11 @@ public override float EndTest() { return lowestScore; } + protected void setTimerColor(Color color) { + timerText.GetComponent().color = color; + curTimerColor = color; + } + protected void pauseTimer() { timerPaused = true; }