Beispiel #1
0
    private void tryMove()
    {
        logMoveData();
        bool[] errorsPlayer = getErrorType();
        if (!errorsPlayer[0] && !errorsPlayer[1] && !errorsPlayer[2])
        {
            if (!approximately(prevMoveDir, direction))
            {
                pathTurns++;
                prevMoveDir = direction;
            }
            string newLoc = move();
            moves++;
            countLeftRightSymmetry(newLoc);
            countTopBottomSymmetry(newLoc);
            bool[] errorsBottom = statueArrowBottom.getErrorType();

            if (errorsBottom[1])
            {
                //if there is a statue collision
                statuesCollide++;
                StartCoroutine(collisionHelper(SAB, SAT, SAB.transform.position, SAT.transform.position, 0.1f));
            }
            else if (errorsBottom[2])
            {
                //if there is a statue blocking
                statuesBlockEachOther++;
                StartCoroutine(collisionHelper(SAB, SAT, SAB.transform.position, SAT.transform.position, 0.05f));
            }
            else
            {
                bool[] errorsTop = statueArrowTop.getErrorType();
                if (!errorsBottom[0])
                {
                    //not offscreen
                    string         bottomStatuePredicted         = statueArrowBottom.getPredictedSquare();
                    IList <string> bottomStatue_squares_explored = statueArrowBottom.getSquaresExplored();
                    IList <string> topStatue_squares_explored    = statueArrowTop.getSquaresExplored();
                    if (bottomStatue_squares_explored.Contains(bottomStatuePredicted) || topStatue_squares_explored.Contains(bottomStatuePredicted))
                    {
                        num_repeated_squares_statues++;
                    }
                    else
                    {
                        squares_explored_statues++;
                    }
                    countStatueSymmetry(bottomStatuePredicted);
                    string newLocStatue = statueArrowBottom.move();
                }
                else
                {
                    // tried to move offscreen
                    statueBlockedByOffscreen++;
                }
                if (!errorsTop[0])
                {
                    // not offscreen
                    string         topStatuePredicted            = statueArrowTop.getPredictedSquare();
                    IList <string> bottomStatue_squares_explored = statueArrowBottom.getSquaresExplored();
                    IList <string> topStatue_squares_explored    = statueArrowTop.getSquaresExplored();
                    if (bottomStatue_squares_explored.Contains(topStatuePredicted) || topStatue_squares_explored.Contains(topStatuePredicted))
                    {
                        num_repeated_squares_statues++;
                    }
                    else
                    {
                        squares_explored_statues++;
                    }
                    countStatueSymmetry(topStatuePredicted);
                    string newLocStatue = statueArrowTop.move();
                }
                else
                {
                    // tried to move offscreen
                    statueBlockedByOffscreen++;
                }
            }
        }
        else if (errorsPlayer[1])
        {
            //if player collides with statue (has to be top statue)
            playerStatueCollide++;
            StartCoroutine(collisionHelper(this.gameObject, SAT, transform.position, SAT.transform.position, 0.1f));
        }
        else if (errorsPlayer[2])
        {
            //if player is blocked by a statue (could be either one)
            playerBlockedByStatue++;
            if (predictedSquare == statueArrowBottom.square)
            {
                StartCoroutine(collisionHelperOneSided(this.gameObject, SAB, transform.position, 0.05f));
            }
            else if (predictedSquare == statueArrowTop.square)
            {
                StartCoroutine(collisionHelperOneSided(this.gameObject, SAT, transform.position, 0.05f));
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!victorious)
        {
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                turnCount++;
                turnDown();
                statueArrowBottom.turnDown();
                statueArrowTop.turnUp();
            }
            else if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                turnCount++;
                turnUp();
                statueArrowBottom.turnUp();
                statueArrowTop.turnDown();
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                turnCount++;
                turnRight();
                statueArrowBottom.turnRight();
                statueArrowTop.turnLeft();
            }
            else if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                turnCount++;
                turnLeft();
                statueArrowBottom.turnLeft();
                statueArrowTop.turnRight();
            }
            else if (Input.GetMouseButtonDown(0))
            {
                logMoveData();
                bool[] errorsPlayer = getErrorType();
                if (!errorsPlayer[0] && !errorsPlayer[1] && !errorsPlayer[2])
                {
                    string newLoc = move();
                    moves++;
                    countLeftRightSymmetry(newLoc);
                    bool[] errorsBottom = statueArrowBottom.getErrorType();

                    if (errorsBottom[1])
                    {
                        //if there is a statue collision
                        sr.WriteLine(",-1,-1");
                        StartCoroutine(collisionHelper(SAB, SAT, SAB.transform.position, SAT.transform.position, 0.1f));
                    }
                    else if (errorsBottom[2])
                    {
                        //if there is a statue blocking
                        sr.WriteLine(",-1,-1");
                        StartCoroutine(collisionHelper(SAB, SAT, SAB.transform.position, SAT.transform.position, 0.05f));
                    }
                    else
                    {
                        bool[] errorsTop = statueArrowTop.getErrorType();
                        if (!errorsBottom[0])
                        {
                            //not offscreen
                            string newLocStatue = statueArrowBottom.move();
                            sr.Write("," + newLocStatue);
                        }
                        else
                        {
                            sr.Write(",-1");
                        }
                        if (!errorsTop[0])
                        {
                            // not offscreen
                            string newLocStatue = statueArrowTop.move();
                            sr.WriteLine("," + newLocStatue);
                        }
                        else
                        {
                            sr.WriteLine(",-1");
                        }
                    }
                }
                else if (errorsPlayer[1])
                {
                    //if player collides with statue (has to be top statue)
                    StartCoroutine(collisionHelper(this.gameObject, SAT, transform.position, SAT.transform.position, 0.1f));
                }
                else if (errorsPlayer[2])
                {
                    //if player is blocked by a statue (could be either one)
                    if (predictedSquare == statueArrowBottom.square)
                    {
                        StartCoroutine(collisionHelperOneSided(this.gameObject, SAB, transform.position, 0.05f));
                    }
                    else if (predictedSquare == statueArrowTop.square)
                    {
                        StartCoroutine(collisionHelperOneSided(this.gameObject, SAT, transform.position, 0.05f));
                    }
                }
            }
            else if (Input.GetKeyDown(KeyCode.R))
            {
                logEndGameData();
                reset();
            }
            else if (Input.GetKeyDown(KeyCode.Escape))
            {
                logEndGameData();
                quit();
            }
            else if (victory())
            {
                logEndGameData();
                sr.WriteLine("VICTORY\n");
                sr.Flush();
                //change later to allow player to play a new game
                displayOptions();
            }
        }
    }