Esempio n. 1
0
    /// <summary> Sets up the cells for the board </summary>
    private void CreatCells()
    {
        // Cellarrays
        Cells = new MatchCell[TileCountScale][];
        for (int i = 0; i < Cells.Length; ++i)
        {
            Cells[i] = new MatchCell[TileCountScale];
        }

        // calculate offset of tiles
        float tileOffset = TilePrefab.GetComponent <RectTransform>().sizeDelta.x * 0.5f;
        // Tile position in top left
        Vector3 topleft = new Vector3(0 - (tileOffset * (TileCountScale - 1)), 0 + (tileOffset * (TileCountScale - 1)), 0);
        // used for pos each tile
        Vector3 pos = Vector3.zero;

        for (int col = 0; col < TileCountScale; ++col)
        {
            for (int row = 0; row < TileCountScale; ++row)
            {
                // Calculate position
                pos.x = topleft.x + (col * (tileOffset * 2));
                pos.y = topleft.y - (row * (tileOffset * 2));

                Cells[col][row]          = new MatchCell();
                Cells[col][row].Cell     = new Vector2(col, row);
                Cells[col][row].Position = pos;
            }
        }
        matchingTiles = new List <MatchTile>();
    }
Esempio n. 2
0
    /// <summary> Calculates and places a single tile </summary>
    private void AddTile(MatchCell cell)
    {
        // Create object
        GameObject newTile = Instantiate(TilePrefab, PlayArea.transform);

        newTile.GetComponent <RectTransform>().localPosition = new Vector3(0, 1000, 0);
        // get refference to tile class
        MatchTile tile = newTile.GetComponent <MatchTile>();

        // Random image
        System.Random rand = new System.Random((int)DateTime.Now.Ticks);
        tile.MatchImage.sprite = Matchables[rand.Next(0, Matchables.Count)];

        tile.Transitioning = true;
        tile.game          = this;
        tile.currentCell   = cell.Cell;
        tile.SetupDelay    = 0f;
        // set position
        tile.FinalPos = cell.Position;
        cell.Tile     = tile;
    }