Beispiel #1
0
        public void Initialize(Dictionary <string, Texture2D> allTextures)
        {
            Generate(allTextures);
            var time = GameTimers.GetNowTimestampSeconds();

            // Callback hell - we can use promises or async instead
            GameTimers.AddNewTimer(gameState.ToString(), time, time + (long)prepareTime,
                                   (currentTimer) =>
            {
                gameState = GameState.Play;
                var time2 = GameTimers.GetNowTimestampSeconds();
                Play();

                GameTimers.AddNewTimer(gameState.ToString(), time, time + (long)gameTime,
                                       (currentTimer2) =>
                {
                    gameState = GameState.End;
                    Clear();
                    // Show cards
                },
                                       (timeLeft2) =>
                {
                    text.text = timeLeft2.ToString();
                }
                                       );
            },
                                   (timeLeft) =>
            {
                text.text = timeLeft.ToString();
            }
                                   );

            // remove interactable from buttons, activate on Play state
            Clear();
        }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (gameState == GameState.Running)
        {
            if (inputWindow == InputWindowState.Closed)
            {
                alarmFired       = false;
                interTrialTimer += Time.deltaTime;
                if (interTrialTimer > interTrialIntervalSeconds && currentTrial < trialsTotal)
                {
                    interTrialTimer = 0f;
                    inputWindow     = InputWindowState.Open;
                    if (firstTimeWindowOpen)
                    {
                        interTrialIntervalSeconds += 5;
                        firstTimeWindowOpen        = false;
                    }
                    SetFabAlarmVariability();
                    onInputWindowChanged.Invoke(inputWindow);
                    LogEvent("InputWindowChange");
                }
                else if (interTrialTimer > interTrialIntervalSeconds)
                {
                    EndGame();
                }
            }
            else if (inputWindow == InputWindowState.Open)
            {
                //Debug.Log("inputwindow is open");
                inputWindowTimer += Time.deltaTime;
                if (inputWindowTimer > currentFabAlarm && alarmFired == false)
                {
                    //Debug.Log("inputWindowTimer exceeded currentFabAlarm.");
                    // Fire fabricated input (if scheduled).
                    InputData fabInputData = new InputData {
                        validity    = InputValidity.Accepted,
                        type        = InputType.FabInput,
                        inputNumber = fabInputNumber
                    };
                    MakeInputDecision(fabInputData, false);
                    alarmFired = true;
                }
                else if (inputWindowTimer > inputWindowSeconds)
                {
                    //Debug.Log("inputWindow expired.");
                    // The input window expired
                    MakeInputDecision(null, true);
                    alarmFired = false;
                }
            }
        }
        GameTimers gameTimers = new GameTimers();

        gameTimers.interTrialTimer  = interTrialTimer;
        gameTimers.inputWindowTimer = inputWindowTimer;
        onGameTimeUpdate.Invoke(gameTimers);
    }
Beispiel #3
0
        private void RightGuess(ValueTuple <int, int> paired)
        {
            allImages[paired.Item1].button.interactable = false;
            allImages[paired.Item2].button.interactable = false;

            allImages[paired.Item1].image.gameObject.SetActive(false);
            allImages[paired.Item2].image.gameObject.SetActive(false);
            currentlyGuessed += 2;
            if (currentlyGuessed >= allImages.Count)
            {
                var toStop = GameTimers.GetTimer(gameState.ToString());
                toStop.Stop();
                OnEndGame?.Invoke(true);
            }
        }
 public void OnGameTimeUpdate(GameTimers gameTimers)
 {
     // Update Progress Indication
     if (gameTimers.inputWindowTimer > 0f)
     {
         float progress    = (interTrialDuration + gameTimers.inputWindowTimer) / progressBarDuration;
         float newPosition = progress * progressBar.sizeDelta.x;
         positionPusher.sizeDelta = new Vector2(newPosition, positionPusher.sizeDelta.y);
     }
     else if (gameTimers.interTrialTimer > 0f)
     {
         float progress    = gameTimers.interTrialTimer / progressBarDuration;
         float newPosition = progress * progressBar.sizeDelta.x;
         positionPusher.sizeDelta = new Vector2(newPosition, positionPusher.sizeDelta.y);
     }
 }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        if (gameState == GameState.Running)
        {
            // removed for kiwi runner
            //if (inputWindow == InputWindowState.Closed) {
            //interTrialTimer += Time.deltaTime;
            //    if (interTrialTimer > interTrialIntervalSeconds && actualInputOrder.Count < trials) {
            //        interTrialTimer = 0f;
            //        inputWindow = InputWindowState.Open;
            //        setFabAlarmVariability();
            //        onInputWindowChanged.Invoke(inputWindow);
            //        LogEvent("InputWindowChange");
            //    } else if (interTrialTimer > interTrialIntervalSeconds) {
            //        EndGame();
            //    }
            //} else
            if (inputWindow == InputWindowState.Open)
            {
                //Debug.Log("inputwindow is open");
                inputWindowTimer += Time.deltaTime;
                if (inputWindowTimer > currentFabAlarm && alarmFired == false)
                {
                    Debug.Log("inputWindowTimer exceeded currentFabAlarm.");
                    // Fire fabricated input (if scheduled).
                    MakeInputDecision(null, false);
                    alarmFired = true;
                }
                else if (inputWindowTimer > inputWindowSeconds)
                {
                    Debug.Log("inputWindow expired.");
                    // The input window expired
                    MakeInputDecision(null, true);
                    alarmFired = false;
                }
            }
        }
        GameTimers gameTimers = new GameTimers();

        gameTimers.interTrialTimer  = interTrialTimer;
        gameTimers.inputWindowTimer = inputWindowTimer;
        onGameTimeUpdate.Invoke(gameTimers);
    }
Beispiel #6
0
    // Update is called once per frame
    void Update()
    {
        if (gameState == GameState.Running)
        {
            if (inputWindow == InputWindowState.Closed)
            {
                alarmFired        = false;
                totalWindowTimer += Time.deltaTime;                                  // Renamed interTrialTimer to totalWindowTimer

                if (totalWindowTimer < interTrialIntervalSeconds * interTrialAmount) // Our code
                {                                                                    // Our code
                    Debug.Log("Trial:" + currentTrial);
                    switch (trialsTotal - currentTrial)
                    {
                    case 5:
                        Fivetrial.Play();
                        break;

                    case 15:
                        FifteenTrial.Play();
                        break;

                    default:
                        break;
                    }
                    GameObject balloonChild = balloon.transform.GetChild(0).gameObject;
                    balloonChild.SetActive(true);
                    balloonColour.color = Color.white;                                                  // Our code
                } // Our code
                else if (totalWindowTimer < interTrialIntervalSeconds * (interTrialAmount + cueAmount)) // Our code
                {                                                                                       // Our code
                    balloonColour.color = Color.red;                                                    // Our code
                } // Our code
                else
                {                                       // Our code
                    balloonColour.color = Color.yellow; // Our code
                } // Our code

                if (totalWindowTimer > interTrialIntervalSeconds && currentTrial < trialsTotal)
                {
                    balloonColour.color = Color.green; // Our code
                    totalWindowTimer    = 0f;
                    inputWindow         = InputWindowState.Open;
                    SetFabAlarmVariability();
                    onInputWindowChanged.Invoke(inputWindow);
                    LogEvent("InputWindowChange");
                }
                else if (currentTrial == trialsTotal)
                {
                    Finish.Play();
                    EndGame();
                }
            }
            else if (inputWindow == InputWindowState.Open)
            {
                //Debug.Log("inputwindow is open");
                inputWindowTimer += Time.deltaTime;
                if (inputWindowTimer > currentFabAlarm && alarmFired == false)
                {
                    //Debug.Log("inputWindowTimer exceeded currentFabAlarm.");
                    // Fire fabricated input (if scheduled).
                    InputData fabInputData = new InputData
                    {
                        validity    = InputValidity.Accepted,
                        type        = InputType.FabInput,
                        inputNumber = fabInputNumber
                    };
                    MakeInputDecision(fabInputData, false);
                    //balloonColour.color = Color.white; // Our code
                    alarmFired = true;
                }
                else if (inputWindowTimer > inputWindowSeconds)
                {
                    //Debug.Log("inputWindow expired.");
                    // The input window expired
                    MakeInputDecision(null, true);
                    alarmFired = false;
                }
            }
        }
        GameTimers gameTimers = new GameTimers();

        gameTimers.interTrialTimer  = totalWindowTimer;
        gameTimers.inputWindowTimer = inputWindowTimer;
        onGameTimeUpdate.Invoke(gameTimers);
    }