Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertMa123 committed Oct 21, 2024
2 parents 5a8fb06 + 8acd62d commit 1bcd2fe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
34 changes: 28 additions & 6 deletions Assets/Scripts/ReactionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -53,6 +61,8 @@ public override void UpdateTest() {
public override void InitializeTest() {
base.InitializeTest();

normalColor = curTimerColor;

leftArrow.gameObject.SetActive(false);
rightArrow.gameObject.SetActive(false);
}
Expand Down Expand Up @@ -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);
}
}
10 changes: 9 additions & 1 deletion Assets/Scripts/TimedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class TimedTest : Test

private Canvas canvas;

private GameObject timerText;
protected GameObject timerText;

protected Color curTimerColor;

public TimedTest() : base() {

Expand All @@ -38,6 +40,7 @@ public override void InitializeTest() {
timerText.AddComponent<TextMesh>().alignment = TextAlignment.Left;
timerText.GetComponent<Transform>().SetParent(canvas.GetComponent<Transform>());
timerText.GetComponent<RectTransform>().anchoredPosition = new Vector3(0, 0, 0);
curTimerColor = timerText.GetComponent<TextMeshProUGUI>().color;
}

// destroy timer text and return the lowest time as score
Expand All @@ -51,6 +54,11 @@ public override float EndTest() {
return lowestScore;
}

protected void setTimerColor(Color color) {
timerText.GetComponent<TextMeshProUGUI>().color = color;
curTimerColor = color;
}

protected void pauseTimer() {
timerPaused = true;
}
Expand Down

0 comments on commit 1bcd2fe

Please sign in to comment.