Пример #1
0
        void AddHakoRandom()
        {
            Vector2Int[] _candi    = new Vector2Int[Data.Size.x * Data.Size.y];
            int          _maxCount = 0;

            int[] _typeCount = new int[] { 0, 0, 0, 0, 0, 0 };
            // 出現位置は:まず、外周以外にランダム。
            for (int x = 1; x < Data.Size.x - 1; x++)
            {
                for (int y = 1; y < Data.Size.y - 1; y++)
                {
                    if (HakoManaer.Instance.Map[x, y] < 0)
                    {
                        _candi[_maxCount] = new Vector2Int(x, y);
                        _maxCount++;
                    }
                    else
                    {
                        _typeCount[(int)HakoManaer.Instance.Hakos[HakoManaer.Instance.Map[x, y]].Type]++;
                    }
                }
            }
            // 出現位置は:つぎに、外周にランダム。
            if (_maxCount <= 0)
            {
                Vector2Int _start = Vector2Int.zero;
                for (int i = 0; i < 4; i++)
                {
                    Vector2Int _dir = HakoManaer.Instance.DirVector(InputManager.GetIntToDir(i));
                    int        _max = i % 2 == 0?Data.Size.y - 1:Data.Size.x - 1;
                    for (int j = 0; j < _max; j++)
                    {
                        Vector2Int _target = _start + _dir * j;
                        if (HakoManaer.Instance.Map[_target.x, _target.y] < 0)
                        {
                            _candi[_maxCount] = _target;
                            _maxCount++;
                        }
                        else
                        {
                            _typeCount[(int)HakoManaer.Instance.Hakos[HakoManaer.Instance.Map[_target.x, _target.y]].Type]++;
                        }
                    }
                    _start += _dir * _max;
                }
            }
            if (_maxCount > 0)
            {
                HakoType _type       = 0;
                int      _typeRandom = 0;
                for (int i = 1; i < 5; i++)
                {
                    _typeRandom += (Data.MaxHakos - _typeCount[i]);
                }
                _typeRandom = Random.Range(0, _typeRandom - 1);
                for (int i = 1; i < 5; i++)
                {
                    _typeRandom -= (Data.MaxHakos - _typeCount[i]);
                    if (_typeRandom < 0)
                    {
                        _type = HakoManaer.Instance.GetIntToType(i);
                        break;
                    }
                }
                Vector2Int _pos = _candi[Random.Range(0, _maxCount)];
                HakoManaer.Instance.AddHako(_type, _pos, 1.0f / Data.AppearTimes[Level]);
            }
        }
Пример #2
0
        public override void HakoUpdate()
        {
            int _hakoCount    = 0;
            int _appearNumber = -1;

            for (int x = 0; x < Data.Size.x; x++)
            {
                for (int y = 0; y < Data.Size.y; y++)
                {
                    if (HakoManaer.Instance.Map[x, y] > 0)
                    {
                        _hakoCount++;
                        if (HakoManaer.Instance.Hakos[HakoManaer.Instance.Map[x, y]].IsGhost)
                        {
                            _appearNumber = HakoManaer.Instance.Map[x, y];
                        }
                    }
                }
            }
            // 場の箱が2以下の時、出現中のブロックの出現速度を上げる。
            if (_hakoCount < 3 && _appearNumber > 0)
            {
                HakoManaer.Instance.Hakos[_appearNumber].AppearSpeed = 3;
            }

            if (_hakoCount < 2)
            {
                AddHakoRandom();
            }

            if (_appearNumber < 0)
            {
                AddHakoRandom();
            }

            // ゲームオーバー?
            bool _isBrank = false;

            for (int i = 0; i < Data.Size.x; i++)
            {
                if (HakoManaer.Instance.Map[i, HakoManaer.Instance.Hakos[0].Position.y] < 0 ||
                    HakoManaer.Instance.Hakos[HakoManaer.Instance.Map[i, HakoManaer.Instance.Hakos[0].Position.y]].IsGhost)
                {
                    _isBrank = true;
                    break;
                }
            }
            for (int i = 0; i < Data.Size.y; i++)
            {
                if (HakoManaer.Instance.Map[HakoManaer.Instance.Hakos[0].Position.x, i] < 0 ||
                    HakoManaer.Instance.Hakos[HakoManaer.Instance.Map[HakoManaer.Instance.Hakos[0].Position.x, i]].IsGhost)
                {
                    _isBrank = true;
                    break;
                }
            }

            // 必殺技(笑)
            if (!_isBrank)
            {
                for (int i = 0; i < 4; i++)
                {
                    Vector2Int _target = HakoManaer.Instance.Hakos[0].Position + HakoManaer.Instance.DirVector(InputManager.GetIntToDir(i));
                    if (_target.x >= 0 && _target.y >= 0 && _target.x < Data.Size.x && _target.y < Data.Size.y &&
                        HakoManaer.Instance.MoveHako(_target, InputManager.GetIntToDir(i)))
                    {
                        _isBrank = true; Combo = 0;
                    }
                }
            }

            if (!_isBrank)
            {
                GamePlaying = false;
                Result      = true;
            }
        }