Beispiel #1
0
    private void UpdateQueue()
    {
        if (seconds >= delay)
        {
            if (currentQueueIndex < queue.Length && queue[currentQueueIndex + 1])
            {
                queue[currentQueueIndex] = null;

                currentQueueIndex++;

                currentQueueAgent = queue[currentQueueIndex];

                if (currentQueueAgent)
                {
                    currentQueueAgent.canGo = true;
                }

                countdown = 0;
                seconds   = 0;
            }
        }

        countdown += Time.deltaTime;
        seconds    = (int)(countdown % 60);
    }
Beispiel #2
0
    public void Refresh()
    {
        currentQueueIndex = 0;
        countdown         = 0;
        seconds           = 0;

        for (int i = 0; i < queue.Length; i++)
        {
            queue[i] = null;
        }

        foreach (ParkingAgent a in agents)
        {
            a.Reset();

            a.player = this;

            queue[a.queueIndex] = a;
        }

        currentQueueAgent = queue[0];

        emptySpots.Clear();

        foreach (GameObject car in cars)
        {
            if (!car.activeSelf)
            {
                car.SetActive(true);
            }
        }

        int[] randArray = new int[cars.Length / 2];

        for (int i = 0; i < randArray.Length; i++)
        {
            randArray[i] = Random.Range(0, cars.Length);
        }

        foreach (int r in randArray)
        {
            if (cars[r].activeSelf)
            {
                cars[r].SetActive(false);
            }
        }

        foreach (GameObject car in cars)
        {
            if (!car.activeSelf)
            {
                emptySpots.Add(car.transform.position);
            }
        }

        currentQueueAgent.canGo = true;
    }
    /// <summary>
    /// Update the score of a given agent.
    /// </summary>
    /// <param name="parkingAgent">The agent to update it's score count.</param>
    public void UpdateScore(ParkingAgent parkingAgent)
    {
        if (parkingAgent.isUser)
        {
            userScore.text = parkingAgent.Score.ToString();
        }

        else
        {
            AIScore.text = parkingAgent.Score.ToString();
        }
    }
Beispiel #4
0
    private void Start()
    {
        agents = FindObjectsOfType <ParkingAgent>();
        cars   = GameObject.FindGameObjectsWithTag("Obstacle");

        foreach (ParkingAgent a in agents)
        {
            a.player = this;

            initialPositions[a.queueIndex] = a.initialPosition;

            queue[a.queueIndex] = a;
        }

        currentQueueAgent = queue[0];

        Refresh();

        StartCoroutine(UpdateStats());
    }
    /// <summary>
    /// Display the game over screen.
    /// </summary>
    /// <returns>
    /// Waits before displaying stats.
    /// </returns>
    /// <param name="user">The user agent.</param>
    /// <param name="AI">The AI agent.</param>
    public IEnumerator DisplayGameoverScreen(ParkingAgent user, ParkingAgent AI)
    {
        duringGameplay = false;

        // Wait 1 second before displaying the dark screen and the game over text
        yield return(new WaitForSecondsRealtime(1));

        gameTimer.Show(false);
        darkPanel.SetActive(true);
        gameoverDefaultText.SetActive(true);

        // Display the correct image according to the user winning status
        if (user.Score > AI.Score)
        {
            youWonImage.SetActive(true);
        }
        else
        {
            youLostImage.SetActive(true);
        }

        // Wait 1 second before displaying the game stat
        yield return(new WaitForSecondsRealtime(1));

        userTotalParkings.text = userScore.text;
        userTotalParkings.gameObject.SetActive(true);

        yield return(new WaitForSecondsRealtime(1));

        AITotalParkings.text = AIScore.text;
        AITotalParkings.gameObject.SetActive(true);

        // Wait 1 second and display the quit button
        yield return(new WaitForSecondsRealtime(1));

        quitButton.SetActive(true);
    }