예제 #1
0
        public void AddLife(int x, int y)
        {
            var newLife = new LifeInstance(x, y);

            if (!AllLife.Add(newLife))
            {
                throw new InvalidOperationException($"Life {newLife} already exists");
            }
        }
예제 #2
0
        public int GetNumberOfNeighbours(LifeInstance life)
        {
            int numberOfNeighbours = 0;

            var neighbouringCells = life.GetNeighbouringCells();

            foreach (var cell in neighbouringCells)
            {
                if (AllLife.Contains(cell))
                {
                    numberOfNeighbours++;
                }
            }

            return(numberOfNeighbours);
        }
예제 #3
0
    /// <summary>
    /// 盤面作るよー
    /// </summary>
    public void Create(AllLife _earth)
    {
        float      _param  = 0.3f;
        Transform  _parent = this.gameObject.transform;
        GameObject _copy   = Resources.Load(BUTTON_OBJ_PATH) as GameObject;

        _obj_pos = BUTTON_INIT_POS;
        for (int i = 0; i < _earth.Life.Size; i++)
        {
            _obj_pos = new Vector3(BUTTON_INIT_POS.x, _obj_pos.y, 0);
            for (int j = 0; j < _earth.Life.Size; j++)
            {
                _earth.Life.isLive[i, j] = false;
                GameObject _origin = Object.Instantiate(_copy, Vector3.zero, Quaternion.identity) as GameObject;
                _origin.transform.SetParent(_parent);
                _origin.transform.localPosition = _obj_pos;
                _origin.name = i + "x" + j;
                _obj_pos    += new Vector3(_param, 0, 0);
            }
            _obj_pos += new Vector3(0, -_param, 0);
        }
    }
예제 #4
0
 private void Start()
 {
     _earth = AllLife.Instance;
     _maker = AllLifeMaker.Instance;
     _maker.Create(_earth);
 }