Esempio n. 1
0
    public void DrawHighScores()
    {
        int counter = 0;        // Counter jsou jen sudá čísla

        // sudý = skóre
        // lichý (sudý + 1) = jméno

        System.Collections.Generic.SortedList <float, string> sortedHighscoreList = new System.Collections.Generic.SortedList <float, string>();

        while (PlayerPrefs.HasKey(counter.ToString()))                  // Načtu všechny hodnoty z PlayerPrefs do SortedList<float = score, string = name>
        {
            string playerName  = PlayerPrefs.GetString((counter + 1).ToString());
            float  playerScore = PlayerPrefs.GetFloat(counter.ToString());
            while (sortedHighscoreList.ContainsKey(playerScore))
            {
                playerScore++;                                          // Pokud by již skóre existovalo, pro jednoduchost mu přičtu+1 abych nemusel řešit složitě sort
            }
            sortedHighscoreList.Add(playerScore, playerName);
            counter += 2;
        }

        leaderboardText.text = "";

        for (int i = sortedHighscoreList.Count - 1; i >= 0; i--)
        {
            string playerName  = sortedHighscoreList.Values[i];
            float  playerScore = sortedHighscoreList.Keys[i];
            leaderboardText.text += sortedHighscoreList.Count - i + ". " + playerName + ": " + playerScore + "\r\n";
        }
    }
Esempio n. 2
0
    public Vector2 moveTowardsPlace(Vector2 targetPos)
    {
        var sortedMoveToList = new System.Collections.Generic.SortedList <float, Vector2>();

        if ((targetPos - position).magnitude < sight)
        {
            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    Vector2 tempMove = new Vector2(x, y);

                    if (!GameMap.Instance.wallDictionary.ContainsKey(position + tempMove))                      //  xxx
                    {                                                                                           //  x_x  -> vybere nejbližsí možnost z okolí
                        float distance = (targetPos - (position + tempMove)).magnitude;                         //  xxx     -> teoreticky by se dalo něco ušetřit
                        if (!sortedMoveToList.ContainsKey(distance))                                            // Pokud v listu ještě není hodnota o stejné vzdálenosti
                        {
                            if (restrictedToDiagonalMovementOnly)                                               // Neozkoušeno!
                            {
                                if ((Mathf.Abs(x) + Mathf.Abs(y)) < 2)                                          // Jen pokud je |x| nebo |y|
                                {
                                    sortedMoveToList.Add(distance, tempMove);
                                }
                            }
                            else
                            {
                                sortedMoveToList.Add(distance, tempMove);
                            }
                        }
                    }
                }
            }

            if (sortedMoveToList.Count > 0)         // Pokud je v sortedListu nějaká hodnota, pak ji vyber
            {
                return(sortedMoveToList.Values[0]);
            }
            else                                    // Pokud není, tak vrať Vector2.zero
            {
                return(Vector2.zero);
            }
        }
        else
        {
            return(Vector2.zero);
        }
    }
Esempio n. 3
0
    public void AddDifficultyModifierToGroup(DifficultyModifier difficultyModifier, uint group)
    {
        System.Collections.Generic.List <DifficultyModifier> difficultyModifiers;
        if (!mDifficultyFactors.TryGetValue(group, out difficultyModifiers))
        {
            difficultyModifiers = new System.Collections.Generic.List <DifficultyModifier>();
            mDifficultyFactors.Add(group, difficultyModifiers);
        }

        difficultyModifiers.Add(difficultyModifier);

        mbDifficultyNeedsUpdating = true;
    }
Esempio n. 4
0
    // Use this for initialization
    void Start()
    {
        //Get Objects that represent Path Nodes...
        int        ChildCount = 0;
        int        LinkCount  = 0;
        GameObject lookobj;

        System.Collections.Generic.List <GameObject> links = new System.Collections.Generic.List <GameObject>();


        ChildCount = transform.childCount;

        for (int i = 0; i < ChildCount; i++)
        {
            Transform t = this.transform.GetChild(i);
            if (t.gameObject.name.ToLower().StartsWith("node"))
            {
                _nodes.Add(t.gameObject.name, t.gameObject);
            }
        }

        LinkCount = _nodes.Count;

        for (int i = 0; i < LinkCount; i++)
        {
            Vector3 pos = this.transform.position;

            pos = _nodes.Values[i].transform.position;

            GameObject o;


            if (i % 2 == 0)
            {
                o = (GameObject)Instantiate(EvenLink, pos, Quaternion.identity);
            }
            else
            {
                o = (GameObject)Instantiate(OddLink, pos, Quaternion.identity);
            }
            o.name             = (i.ToString() + "-link");
            o.transform.parent = this.transform;

            //Calc the 'look ahead'
            if (i != LinkCount - 1)
            {
                lookobj = _nodes.Values[i + 1];
            }
            else
            {
                lookobj = _nodes.Values[0];
            }

            //Set Link Orientation.
            o.transform.LookAt(lookobj.transform, o.transform.up);

            links.Add(o);
        }

        _Links = links.ToArray();
    }