Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (timeRemaining > 0)
        {
            // keeps track of time remaining in this game
            timeRemaining -= Time.deltaTime;

            int curTimeLeft = (int)Math.Round(timeRemaining, 0);

            // different ways to display the time
            if (curTimeLeft >= 10)
            {
                textTimer.text = "0:" + curTimeLeft.ToString();
            }
            else
            {
                textTimer.text = "0:0" + curTimeLeft.ToString();
            }
        }
        else
        {
            // update high score using a static function
            HighScoreHandler.updateScore(GameManager.instance.points);
            // reset time and states of UI elements
            timeRemaining         = 30;
            ButtonHandler.isStart = false;
            ButtonHandler.b.gameObject.SetActive(true);
            textTimer.gameObject.SetActive(false);
            GameManager.instance.SetScoreActiveToggle();
            GameManager.instance.points = 0;
        }
    }
 IEnumerator checkScores(HighScoreHandler h)
 {
     while (!h.ReadHighScoresFinished)
     {
         yield return(new WaitForSeconds(0.1f));
     }
     setScores(h.Result);
 }
Example #3
0
 // click the button to start the game
 void ButtonClicked()
 {
     isStart = true;
     HighScoreHandler.DisableGameOver();
     b.gameObject.SetActive(false);
     TimerHandler.upStart();
     GameManager.instance.SetScoreActiveToggle();
     TimerHandler.textTimer.gameObject.SetActive(true);
 }
 // Awake is called before Start()
 void Awake()
 {
     // set the reference to the current instance
     if (Instance == null)
     {
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
 }
Example #5
0
    void Start()
    {
        values = new List <float>();
        for (int i = 0; i < 3; i++)
        {
            values.Add(0f);
        }
        headline.text = "Statistics for " + PlayerPrefs.GetString("TspName");
        HighScoreHandler hsh = new HighScoreHandler();

#if UNITY_STANDALONE_WIN
        List <HighScoreEntry> scores = hsh.GetScores(PlayerPrefs.GetString("TspName"), HighScoreHandler.ORDER_TYPE_ASC, AntAlgorithmManager.GameName, -1);
        HandleScores(scores);
        MakeGraph();
#endif


#if UNITY_WEBGL || UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
        StartCoroutine(hsh.ScoresWebGL());
        StartCoroutine(checkScores(hsh));
#endif
    }
    void Update()
    {
        GameObject timer     = GameObject.Find("Timer");
        float      timeFloat = timer.GetComponent <TimerDisplayController>().Time;
        GameObject countdown = GameObject.Find("Countdown");

        if (timeFloat < 1.0f && !timeSet)
        {
            countdown.GetComponent <Text>().text = 3 + "";
            return;
        }
        else if (timeFloat < 2.0f && !timeSet)
        {
            countdown.GetComponent <Text>().text = 2 + "";
            return;
        }
        else if (timeFloat < 3.0f && !timeSet)
        {
            countdown.GetComponent <Text>().text = 1 + "";
            return;
        }
        else if (timeFloat > 3.0f && !timeSet)
        {
            timer.GetComponent <TimerDisplayController>().Time = 0;
            timeSet = true;
            return;
        }
        countdown.GetComponent <Text>().text = "";

        //don't rotate main camera
        Camera.main.transform.rotation = Quaternion.identity;
        if (AntAlgorithmManager.Instance.IsGameFinished)
        {
            Speed = 0;
            if (!written)
            {
                written = true;

                //double userDistance = AntAlgorithmManager.Instance.CalcOverallUserDistance();
                double bestAlgorithmDistance = AntAlgorithmManager.Instance.BestAlgorithmLength;
                int    bestAlgorithIteration = AntAlgorithmManager.Instance.BestAlgorithmIteration;
                string bestAlgoritmTour      = AntAlgorithmManager.Instance.BestAlgorithmTour;

                double bestUserDistance  = AntAlgorithmManager.Instance.BestTourLength;
                int    bestUserIteration = AntAlgorithmManager.Instance.BestItertation;
                string bestUserTour      = AntAlgorithmManager.Instance.TourToString(AntAlgorithmManager.Instance.BestTour);

                //Debug.Log("[user distance: " + userDistance);
                //AntAlgorithmManager.Instance.PrintBestTour("user best tour: ");
                GameObject time         = GameObject.Find("Timer");
                int        timeInMillis = StringOperations.GetTimeFromString(time.GetComponent <Text>().text);

                GameObject score = GameObject.Find("ScoreValueText");
                score.GetComponent <Text>().text = StringOperations.GetStringFromTime(timeInMillis);

                GameObject gameEndedCanvas = GameObject.Find("GameEndedCanvas");
                gameEndedCanvas.GetComponent <Canvas>().enabled = true;

                GameObject gameCanvas = GameObject.Find("Canvas");
                gameCanvas.GetComponent <Canvas>().enabled = false;
                Guid gid = Guid.NewGuid();
                foreach (PheromoneEntry pheromoneHistoryEntry in AntAlgorithmManager.Instance.PheromoneHistory)
                {
                    StartCoroutine(HighScoreHandler.PostPheromonesAsync(gid, pheromoneHistoryEntry.Pheromones, pheromoneHistoryEntry.Iteration, pheromoneHistoryEntry.HighestValueIndex, pheromoneHistoryEntry.PreviousChosenValueIndex));
                }
                StartCoroutine(HighScoreHandler.PostScoresAsync(gid, PlayerPrefs.GetString("PlayerName"), PlayerPrefs.GetString("TspName"), bestAlgorithmDistance, bestAlgorithIteration, bestAlgoritmTour, bestUserDistance, bestUserIteration, bestUserTour, timeInMillis, "webglnear"));
            }

            if (showLine)
            {
                lineRenderer.SetPosition(1, transform.position); // snakehead position
            }
            return;
        }

        if (Input.GetKeyUp(KeyCode.Escape))
        {
            if (escPressed)
            {
                ResumeSpeed();
                escPressed = false;
            }
            else
            {
                escPressed = true;
                tmpTime    = timer.GetComponent <TimerDisplayController>().Time;

                Speed = 0;
                GameObject gameEndedCanvas = GameObject.Find("QuitGameCanvas");
                gameEndedCanvas.GetComponent <Canvas>().enabled = true;

                GameObject gameCanvas = GameObject.Find("Canvas");
                gameCanvas.GetComponent <Canvas>().enabled = false;

                GameObject resumeGameButton = GameObject.Find("ResumeGameButton");
                resumeGameButton.GetComponent <Button>().onClick.AddListener(ResumeSpeed);
            }
        }

        if (showLine)
        {
            // set Positions of line
            lineRenderer.SetPosition(0, transform.position);                             // snakehead position
            lineRenderer.SetPosition(1, AntAlgorithmManager.Instance.GetNextPosition()); // "optimal" next position
        }
    }