Example #1
0
    public void FillTheBoard()
    {
        _drops            = new Drop[_width, _height];
        _dropsGameObjects = new GameObject[_width, _height];

        for (var i = 0; i < _width; i++)
        {
            for (var j = 0; j < _height; j++)
            {
                do
                {
                    if (_dropsGameObjects[i, j] != null)
                    {
                        Destroy(_dropsGameObjects[i, j].gameObject);
                        _drops[i, j] = null;
                    }
                    var position   = new Vector3(i, j, -1);
                    var randomDrop = Instantiate(GetRandomDrop(), position, Quaternion.identity);
                    _drops[i, j] = randomDrop.GetComponent <Drop>();
                    _drops[i, j].InitDrop(i, j, _swap);
                    _dropsGameObjects[i, j] = randomDrop;
                } while (CheckDropForInit(i, j));
            }
        }
        _swap.InitSwap(this, _tiles, _drops, _width, _height, _dropsGameObjects);
    }