Example #1
0
    public SlotSprite GetRandomType()
    {
        int        rand = Random.Range(1, Library.Count);
        SlotSprite ss   = Library[rand];

        return(ss);
    }
Example #2
0
    public void RefreshGameBoard()
    {
        //Clear Previous Item Lineup
        LineUpList.Clear();

        //Build New Item Lineup
        while (LineUpList.Count < RowCount)
        {
            SlotSprite ss = DSpriteLibrary.instance.GetRandomType();
            if (LineUpList.Count == 0)
            {
                LineUpList.Add(ss.spriteName, ss);
            }
            else
            {
                if (!LineUpList.ContainsKey(ss.spriteName))
                {
                    LineUpList.Add(ss.spriteName, ss);
                }
            }
        }

        //Create a list of items based on the types generated
        BuildFreshGameItemList(LineUpList);

        //Shuffle the list to randomise the content
        ShuffledItemList(GameItemList);

        //Extract Slot Positions (to allow index interation)
        List <Vector3Int> slotIndexes = new List <Vector3Int>();

        foreach (Vector3Int slotPosition in SlotList.Keys)
        {
            slotIndexes.Add(slotPosition);
        }

        //Give all Items a slot position
        if (slotIndexes.Count != GameItemList.Count)
        {
            Debug.LogError("Amount of items doesn't match board slots.");
        }
        else
        {
            for (int i = 0; i < slotIndexes.Count; i++)
            {
                GameItemList[i].ItemSlotLocation = slotIndexes[i];
            }
        }

        //Set Gameboard Items to UI
        foreach (Item item in GameItemList)
        {
            if (!SlotList.ContainsKey(item.ItemSlotLocation))
            {
                Debug.LogError("Item has incompatible slot location:" + item.ItemSlotLocation);
            }
            else
            {
                SlotList[item.ItemSlotLocation].GetComponent <Image>().sprite = item.ItemIcon;
            }
        }
    }