Ejemplo n.º 1
0
    private void ManageStatesAfterPut(EquipmentVisual e, Cell cell)
    {
        if (CanPutEquipmentOnCell(e, cell))
        {
            int x       = cell.x;
            int y       = cell.y;
            int cols    = e.Cols;
            int rows    = e.Rows;
            int offsetX = cols / 2;
            int offsetY = rows / 2;
            for (int i = 0; i < cols; i++)
            {
                for (int j = 0; j < rows; j++)
                {
                    // The grid may not contain the current index
                    // It happens when we put ghost rows/cols to have centered equipments
                    if (GridContains(x + i - offsetX, y + j - offsetY))
                    {
                        Cell gridCell = gameMatrix[x + i - offsetX, y + j - offsetY];
                        // The cell can be null if it's an empty cell
                        if (e.Layout.GetCell(i, j) != null)
                        {
                            Cell newCell = Instantiate(e.Layout.GetCell(i, j), gridCell.transform.position, Quaternion.identity, transform);
                            gameMatrix[x + i - offsetX, y + j - offsetY] = newCell;
                            newCell.x = gridCell.x;
                            newCell.y = gridCell.y;
                            newCell.SetImage(e.Layout.GetSprite(i, j));
                            Destroy(gridCell.gameObject);

                            newCell.tempState = TempCellState.NAN;
                            CellState equipCellState = CellState.Empty;
                            equipCellState = e.GetLayoutState(i, j);

                            if (x + i <= columnCount && x + i >= 0 && y + j <= rowCount && y + j >= 0 &&
                                equipCellState != CellState.Empty)
                            {
                                if (equipCellState == CellState.Used)
                                {
                                    newCell.state = CellState.Used;
                                }
                                if (equipCellState == CellState.Open &&
                                    (gridCell.state == CellState.Inactive || gridCell.state == CellState.Open))
                                {
                                    newCell.state = CellState.Open;
                                }
                            }
                        }
                    }
                }
            }
        }
        ResetTempStates();
    }
Ejemplo n.º 2
0
    public List <Cell> FindCellsWithPatternAndCenter(EquipmentVisual e, int x, int y)
    {
        ResetTempStates();
        List <Cell> subset  = new List <Cell>();
        int         cols    = e.Cols;
        int         rows    = e.Rows;
        int         offsetX = cols / 2;
        int         offsetY = rows / 2;

        for (int i = 0; i < e.Cols; i++)
        {
            for (int j = 0; j < e.Rows; j++)
            {
                int idx = x + i - offsetX;
                int idy = y + j - offsetY;
                if (GridContains(idx, idy))
                {
                    Cell      gridCell       = gameMatrix[idx, idy];
                    CellState equipCellState = e.GetLayoutState(i, j);

                    if (idx <= columnCount && idx >= 0 && idy <= rowCount && idy >= 0 &&
                        equipCellState != CellState.Empty)
                    {
                        subset.Add(gridCell);
                        if (equipCellState == CellState.Used)
                        {
                            gridCell.tempState = gridCell.state == CellState.Open ? TempCellState.OK : TempCellState.NOK;
                        }
                        if (equipCellState == CellState.Open)
                        {
                            if (gridCell.state == CellState.Open || gridCell.state == CellState.Inactive)
                            {
                                gridCell.tempState = TempCellState.OK;
                            }
                            else
                            {
                                gridCell.tempState = TempCellState.NOK;
                            }
                        }
                    }
                }
            }
        }
        return(subset);
    }