コード例 #1
0
ファイル: CrosswordGrid.cs プロジェクト: AleKuv55/ActionWords
    /// <summary>
    /// Opens the word starting from [x,y] cell to the end.
    /// </summary>
    /// <param name="x">X of the first cell of a word in a grid.</param>
    /// <param name="y">Y of the first cell of a word in a grid.</param>
    /// <param name="direction">Tells whether to open vertically or horizontally.</param>
    public void OpenWord(int x, int y, CWword.Direction direction)
    {
        Debug.Log("Opening word at " + x + ", " + y);
        CWCell nextCell = _cells[x, y];

        while (nextCell != null)
        {
            nextCell.OpenLetter();
            if (direction == CWword.Direction.vertical)
            {
                if (++x > _cells.GetUpperBound(0))
                {
                    break;
                }
            }
            else
            {
                if (++y > _cells.GetUpperBound(1))
                {
                    break;
                }
            }
            nextCell = _cells[x, y];
            Debug.Log("Next cell (" + x + ", " + y + ") is null: " + (nextCell == null));
            if (null != nextCell)
            {
                Debug.Log("Letter is " + nextCell.GetHiddenLetter());
            }
        }
    }
コード例 #2
0
ファイル: CellPool.cs プロジェクト: AleKuv55/ActionWords
    public CWCell GetCell()
    {
        CWCell cell = _cells[0];

        _cells.RemoveAt(0);
        return(cell);
    }
コード例 #3
0
ファイル: CrosswordGrid.cs プロジェクト: AleKuv55/ActionWords
    /// <summary>
    /// Gets necessary ammount of CWCells from pool to accuratly place them on scene,
    /// creating a crossvord field.
    /// </summary>
    /// <param name="scheme">The scheme of a crossword</param>
    public void BuildCrossword(char[,] scheme, char emptySymbol)
    {
        _scheme      = scheme;
        _emptySymbol = emptySymbol;
        int n = scheme.GetUpperBound(0) + 1;
        int m = scheme.GetUpperBound(1) + 1;

        CalculateUnitLength(n, m);
        _cells = new CWCell[n, m];

        float vertiOffset  = +_unitLength * (n - 1) * (CELL_SIZE_ON_SPACE + 1) / 2;
        float horizOffset0 = -_unitLength * (m - 1) * (CELL_SIZE_ON_SPACE + 1) / 2;
        float horizOffset  = horizOffset0;

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (scheme[i, j] != _emptySymbol)
                {
                    CWCell cell = _cellPool.GetCell();
                    cell.SetHiddenLetter(scheme[i, j])
                    .SetSize(_unitLength * CELL_SIZE_ON_SPACE)
                    .TakePlace(transform, relativePosition: new Vector3(horizOffset,
                                                                        vertiOffset));
                    _cells[i, j] = cell;

                    char a = cell.GetHiddenLetter();
                    Debug.Log(i + ", " + j + ": " + a);
                }
                horizOffset += _unitLength * (CELL_SIZE_ON_SPACE + 1);
            }
            vertiOffset -= _unitLength * (CELL_SIZE_ON_SPACE + 1);
            horizOffset  = horizOffset0;
        }
    }
コード例 #4
0
ファイル: CellPool.cs プロジェクト: AleKuv55/ActionWords
 public void StoreCell(CWCell cell)
 {
     _cells.Add(cell);
     cell.transform.SetParent(transform, false);
     cell.transform.localPosition = Vector3.zero;
 }