예제 #1
0
    public int UpdateTestPattern(float deltaTime)

    /**
     * Return -1 if pattern is complete
     * Return 1...N for active block
     * 0 if no block is highlighted
     */
    {
        if (currentPatternState == PatternState.ActiveDisplay)
        {
            if (displayOn.IsComplete(deltaTime))
            {
                displayOff.Reset();
                currentPatternState = PatternState.PatternInterval;
                return(0);
            }
            else
            {
                return(testPattern.GetActivePatternListItem());
            }
        }
        else
        {
            if (displayOff.IsComplete(deltaTime))
            {
                testPattern.StepPattern();

                if (testPattern.IsComplete(testIterationCounter))
                {
                    return(-1);
                }
                else
                {
                    displayOn.Reset();
                    currentPatternState = PatternState.ActiveDisplay;
                    return(0);
                }
            }
            else
            {
                return(0);
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        float deltaTime = Time.deltaTime;

        if (isHighlighted)
        {
            this.SetMaterial(highlightMat);
        }
        else
        {
            this.SetMaterial(defaultMat);
        }

        if (onTime != null && onTime.IsComplete(deltaTime))
        {
            UnityEngine.Debug.Log("Delta Time: " + deltaTime.ToString());
            isHighlighted = false;
            onTime        = null;
        }
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        checkIfUserQuit();

        if (currentState == GameState.DisplayTestPattern)
        {
            //Pattern display

            //Set all cube materials to default
            foreach (var tempBlock in blockList)
            {
                tempBlock.setHighlighted(false);
            }

            //Update Test Pattern State in Test Manager
            //Some time has passed
            int blockNumber = currentTest.UpdateTestPattern(Time.deltaTime); //Update userInput is the other function
            //UnityEngine.Debug.Log("Block ID: " + blockNumber.ToString());

            if (blockNumber > 0)
            {
                blockList[blockNumber - 1].setHighlighted(true);
            }
            else if (blockNumber == -1)
            {
                UnityEngine.Debug.Log("Pattern ended. Ready for user input.");
                currentState = GameState.GetUserInput;
                //testPattern.setInputCheckVar();
            }
        }

        if (currentState == GameState.GetUserInput)
        {
            if (Input.GetMouseButtonDown(0))
            {
                //Adding collision code in Main Manager as game specific information is needed to complete this
                var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                RaycastHit hit;

                if (Physics.Raycast(ray, out hit))
                {
                    //UnityEngine.Debug.Log(hit.collider.gameObject.name);
                    int collidedObject;

                    onHighlightTimer = new CountDownTimer(currentTest.GetUserInputDisplayTime(), "User Timer");

                    switch (hit.collider.gameObject.name)
                    {
                    case "Cube1":
                        collidedObject = 1;
                        blockList[collidedObject - 1].setHighlighted(onHighlightTimer);
                        break;

                    case "Cube2":
                        collidedObject = 2;
                        blockList[collidedObject - 1].setHighlighted(onHighlightTimer);
                        break;

                    case "Cube3":
                        collidedObject = 3;
                        blockList[collidedObject - 1].setHighlighted(onHighlightTimer);
                        break;

                    case "Cube4":
                        collidedObject = 4;
                        blockList[collidedObject - 1].setHighlighted(onHighlightTimer);
                        break;

                    default:
                        collidedObject = 0;
                        break;
                    }

                    pass = currentTest.UserClicked(collidedObject);
                }
            }

            if (onHighlightTimer != null && onHighlightTimer.IsComplete())
            {
                onHighlightTimer = null;

                if (pass)
                {
                    if (currentTest.UserComplete())
                    {
                        UnityEngine.Debug.Log("Win. Next iteration.");
                        testIntervalTimer = new CountDownTimer(2.0f, "TEST-INTERVAL");
                    }
                }
                else
                {
                    UnityEngine.Debug.Log("Lose. Restart?");
                    currentState = GameState.ResultFail;
                }
            }

            if (testIntervalTimer != null && testIntervalTimer.IsComplete(Time.deltaTime))
            {
                currentTest.NextTest();
                currentState      = GameState.DisplayTestPattern;
                testIntervalTimer = null;
                //currentState = GameState.ResultWin;
            }
        }
    }