Exemple #1
0
    public int GetHighScore(MenuCountryScript.CountryName country, string level)
    {
        //find the correct level
        XmlElement levelNode = GetLevel(country, level);

        //return the highest score attained on the level
        return(Convert.ToInt32(levelNode.GetAttribute("Score")));
    }
Exemple #2
0
    public bool IsLevelComplete(MenuCountryScript.CountryName country, string level)
    {
        //find the correct level
        XmlElement levelNode = GetLevel(country, level);

        //return true if the level is complete
        return(levelNode.GetAttribute("Complete").ToUpper() == "TRUE");
    }
Exemple #3
0
    //get the number of levels in a specified country
    public int GetNumberOfLevels(MenuCountryScript.CountryName country)
    {
        //iterate through each level group to find the correct country
        foreach (XmlNode node in saveFile.DocumentElement.ChildNodes)
        {
            //if this is the correct country
            if (node.Name == country.ToString())
            {
                return(node.ChildNodes.Count);
            }
        }

        return(0);
    }
Exemple #4
0
    public void SetLevelComplete(MenuCountryScript.CountryName country, string level, int score)
    {
        //find the correct level
        XmlElement levelNode = GetLevel(country, level);

        //if the new score is higher than the old score, replace the old score
        int oldScore = Convert.ToInt32(levelNode.GetAttribute("Score"));

        if (oldScore < score)
        {
            levelNode.SetAttribute("Score", score.ToString());
        }

        //set the level as complete
        levelNode.SetAttribute("Complete", "true");

        //save the file
        saveFile.Save(savePath);
    }
Exemple #5
0
    private XmlElement GetLevel(MenuCountryScript.CountryName country, string level)
    {
        //iterate through each level group to find the correct country
        foreach (XmlNode node in saveFile.DocumentElement.ChildNodes)
        {
            //if this is the correct country
            if (node.Name == country.ToString())
            {
                //iterate through each level to find the correct one
                foreach (XmlElement levelNode in node.ChildNodes)
                {
                    //if this is the correct level
                    if (levelNode.Name == level)
                    {
                        return(levelNode);
                    }
                }
            }
        }

        //return null if the element wasn't found
        return(null);
    }
Exemple #6
0
    //return a value between 0.0 and 1.0 based on how many levels are complete in a country
    public float GetProgress(MenuCountryScript.CountryName country)
    {
        int completedLevels = 0;

        //iterate through each level group to find the correct country
        foreach (XmlNode node in saveFile.DocumentElement.ChildNodes)
        {
            //if this is the correct country
            if (node.Name == country.ToString())
            {
                foreach (XmlNode level in node.ChildNodes)
                {
                    if (IsLevelComplete(country, level.Name))
                    {
                        completedLevels++;
                    }
                }
                break;
            }
        }

        return((float)completedLevels / (float)GetNumberOfLevels(country));
    }
Exemple #7
0
    // Update is called once per frame
    void Update()
    {
        //if the level selection popup is not shown
        if (!showLevelWindow)
        {
            //check if the mouse has been moved
            bool mouseMoved = (previousMousePosition != Input.mousePosition);

            //if the mouse has been moved
            if (mouseMoved)
            {
                bool selectedChanged = false;

                //get the colliders at the mouse
                Collider2D[] points = Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition));

                //iterate through the colliders
                Collider2D country = null;
                foreach (Collider2D point in points)
                {
                    //if the collider is a country
                    if (point.tag == "Country")
                    {
                        //if this country is different from the selected one, select that country
                        country = point;
                        if (point.GetComponent <MenuCountryScript>().countryName != selectedCountry)
                        {
                            selectedCountry = point.GetComponent <MenuCountryScript>().countryName;
                            selectedChanged = true;
                        }

                        //break out of the loop
                        break;
                    }
                }

                //if a country is selected
                if (country)
                {
                    MenuCountryScript countryScript = country.gameObject.GetComponent <MenuCountryScript>();

                    //if the selection has changed, create a new cursor
                    if (selectedChanged)
                    {
                        CursorScript.CreateNewCursor(countryScript.cursorPoint, cursorPrefab);
                        selectedChanged = false;
                    }
                }
                else
                {
                    //if no country is selected, remove the cursor and set the selected country to none
                    CursorScript.RemoveCursors();
                    selectedCountry = MenuCountryScript.CountryName.NONE;
                }
            }

            //if the mouse has been clicked
            if (Input.GetMouseButtonDown(0) && selectedCountry != MenuCountryScript.CountryName.NONE)
            {
                //open the level selection pop up
                switch (selectedCountry)
                {
                case MenuCountryScript.CountryName.USA:
                    showLevelWindow = true;
                    break;

                case MenuCountryScript.CountryName.RUSSIA:
                    showLevelWindow = true;
                    break;

                default:
                    break;
                }
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (Input.mousePosition.x > windowRect.x + windowRect.size.x ||
                    Input.mousePosition.x < windowRect.x ||
                    Input.mousePosition.y > windowRect.y + windowRect.size.y ||
                    Input.mousePosition.y < windowRect.y)
                {
                    showLevelWindow = false;
                }
            }
        }

        //set the previous mouse position
        previousMousePosition = Input.mousePosition;
    }