Beispiel #1
0
        public Cell(short _id, bool active, CellsType _type, bool _isLinear, byte _level, byte _slope, short _interactiveObjId, short _layer_object_1_num, short _layer_object_2_num, Map _map)
        {
            Id     = _id;
            Active = active;
            Type   = _type;

            Layer_object_1_num = _layer_object_1_num;
            Layer_object_2_num = _layer_object_2_num;

            IsLinear           = _isLinear;
            Layer_ground_level = _level;
            Layer_ground_slope = _slope;

            if (_interactiveObjId != -1)
            {
                InteractiveObject = new InteractiveObject(_interactiveObjId, this);
                _map.Interactives.TryAdd(Id, InteractiveObject);
            }

            byte Width    = _map.Width;
            int  _calcul1 = Id / ((Width * 2) - 1);
            int  _calcul2 = Id - (_calcul1 * ((Width * 2) - 1));
            int  _calcul3 = _calcul2 % Width;

            Y = _calcul1 - _calcul3;
            X = (Id - ((Width - 1) * Y)) / Width;
        }
 /// <summary>
 /// Constructor para cuando inicializamos una celda en un mundo
 /// </summary>
 public Cell(int x, int y, CellsType _value, float _probability_alive = 0.4f)
 {
     this.value             = _value;
     this.cellInfo          = new CellInfo(x, y);
     this.probability_alive = _probability_alive;
     this.color             = this.value == CellsType.dead ? Color.black : Color.white;
 }
Beispiel #3
0
    private ArrayList FindCells(CellsType toFind)
    {
        ArrayList searchingCells = new ArrayList();

        GameObject[] allCells = GameObject.FindGameObjectsWithTag("Cell");
        foreach (GameObject cell in allCells)
        {
            if (toFind == CellsType.empty && cell.GetComponent <Cell>().filled == false)
            {
                searchingCells.Add(cell);
            }
            else if (toFind == CellsType.filled && cell.GetComponent <Cell>().filled == true)
            {
                searchingCells.Add(cell);
            }
        }
        return(searchingCells);
    }
Beispiel #4
0
    /// <summary>
    /// A partir de un celda se obtiene una region
    /// </summary>
    /// <param name="tablero">Mapa donde se buscará la región</param>
    /// <param name="cell">Celda raiz</param>
    /// <returns></returns>
    private List <Cell> GetRegionTiles(Tablero _tablero, Cell _cell)
    {
        List <Cell> room = new List <Cell>();

        Queue <Cell> queue = new Queue <Cell>();

        _cell.cellInfo.isInRoom = true;
        queue.Enqueue(_cell);

        while (queue.Count > 0)
        {
            Cell cell = queue.Dequeue();
            room.Add(cell);
            CellsType cellType = cell.value;

            int radioVecinos = _tablero.radioVecino;

            for (int x = cell.cellInfo.x - radioVecinos; x <= cell.cellInfo.x + radioVecinos; x++)
            {
                for (int y = cell.cellInfo.y - radioVecinos; y <= cell.cellInfo.y + radioVecinos; y++)
                {
                    int NeighborX = x;
                    int NeighborY = y;

                    if (
                        (NeighborX >= 0 && NeighborX < _tablero.world_cell.GetLength(0)) &&
                        (NeighborY >= 0 && NeighborY < _tablero.world_cell.GetLength(1)) &&
                        (NeighborX == cell.cellInfo.x || NeighborY == cell.cellInfo.y)
                        )
                    {
                        if (_tablero[NeighborX, NeighborY].value == cellType && !_tablero[NeighborX, NeighborY].cellInfo.isInRoom)
                        {
                            _tablero[NeighborX, NeighborY].cellInfo.isInRoom = true;
                            queue.Enqueue(_tablero[NeighborX, NeighborY]);
                        }
                    }
                }
            }
        }

        return(room);
    }
Beispiel #5
0
        public Cell DecompressCell(string celldatas, short cellid)
        {
            byte[] cellinfo = new byte[celldatas.Length];

            for (int i = 0; i < celldatas.Length; i++)
            {
                cellinfo[i] = Convert.ToByte(Hash.GetHash(celldatas[i]));
            }

            CellsType type               = (CellsType)((cellinfo[2] & 56) >> 3);
            bool      isActive           = (cellinfo[0] & 32) >> 5 != 0;
            bool      isLinear           = (cellinfo[0] & 1) != 1;
            bool      containInteractive = ((cellinfo[7] & 2) >> 1) != 0;
            short     layer_object_2_num = Convert.ToInt16(((cellinfo[0] & 2) << 12) + ((cellinfo[7] & 1) << 12) + (cellinfo[8] << 6) + cellinfo[9]);
            short     layer_object_1_num = Convert.ToInt16(((cellinfo[0] & 4) << 11) + ((cellinfo[4] & 1) << 12) + (cellinfo[5] << 6) + cellinfo[6]);
            byte      level              = Convert.ToByte(cellinfo[1] & 15);
            byte      slope              = Convert.ToByte((cellinfo[4] & 60) >> 2);

            return(new Cell(cellid, isActive, type, isLinear, level, slope, containInteractive ? layer_object_2_num : Convert.ToInt16(-1), layer_object_1_num, layer_object_2_num, this));
        }