示例#1
0
    //finds and fills an empty Box with given index
    public void FillEmptyBox(Box.Index index)
    {
        int boxNum     = 0;
        int tryCounter = 30;

        do
        {
            tryCounter--;
            boxNum      = Random.Range(0, boxes.Length);
            _currentBox = boxes[boxNum].GetComponent <Box>();
        } while (_currentBox.index != Box.Index.EMPTY || (ConflictWithKey(_currentBox, index) && tryCounter >= 0));
        _currentBox.index = index;
    }
示例#2
0
    public void ReplacePowerUp(Box.Index keyIndex)
    {
        int boxNum     = 0;
        int tryCounter = 30;

        do
        {
            boxNum      = Random.Range(0, boxes.Length);
            _currentBox = boxes[boxNum].GetComponent <Box>();
            tryCounter--;
        } while (_currentBox.index == Box.Index.KEY_BLUE || _currentBox.index == Box.Index.KEY_GREEN ||
                 _currentBox.index == Box.Index.KEY_RED || _currentBox.index == Box.Index.KEY_YELLOW ||
                 (!ConflictWithKey(_currentBox, keyIndex) && tryCounter >= 0));
        _currentBox.index = keyIndex;
    }
示例#3
0
    public bool ConflictWithKey(Box box, Box.Index index)
    {
        if (index == Box.Index.KEY_BLUE && box.quarter == Colors.BLUE)
        {
            return(true);
        }
        else if (index == Box.Index.KEY_GREEN && box.quarter == Colors.GREEN)
        {
            return(true);
        }
        else if (index == Box.Index.KEY_RED && box.quarter == Colors.RED)
        {
            return(true);
        }
        else if (index == Box.Index.KEY_YELLOW && box.quarter == Colors.YELLOW)
        {
            return(true);
        }

        return(false);
    }
示例#4
0
    //Gets an index of a new powerUp taking into account the chance of each powerUp
    public Box.Index FindPowerUpIndex()
    {
        float randIndex = Random.Range(0f, 1f);

        Box.Index boxIndex = Box.Index.EMPTY;

        for (int i = 0; i < powerUpChance.Length; i++)
        {
            float countChance = 0;
            for (int j = 0; j < i; j++)
            {
                countChance += powerUpChance[j];
            }
            if (randIndex >= countChance && randIndex < countChance + powerUpChance[i])
            {
                boxIndex = (Box.Index)i;
            }
        }

        return(boxIndex);
    }
示例#5
0
 public void SetPowerUpIcon(Box.Index index)
 {
     currentPowerupIcon.sprite = powerupIcons[((int)index)];
 }