public void Init()
    {
        block_Type = Block_Type.None;

        blockID = -1;

        colorID = -1;

        durability = 1;

        Ice_durability = 1;

        isFilled = false;

        isCopyFilled = false;

        Save_block_sprite = null;

        blockImage.sprite = null;
        blockImage.color  = new Color(1, 1, 1, 0);

        Img_CheckOne.gameObject.SetActive(false);
        Img_IceBlock.gameObject.SetActive(false);
        Img_GameOver.gameObject.SetActive(false);
        txtCounter.gameObject.SetActive(false);
        Boom_Counter.gameObject.SetActive(false);
    }
Exemple #2
0
    public HintInfo Hint()
    {
        for (int i = 0; i < (int)Dir.Max; ++i)
        {
            Point nearPoint = Get_Point().Get_NearPoint((Dir)i);
            if (null == nearPoint)
            {
                continue;
            }

            // 이전 블럭 임시 저장
            Block      before     = nearPoint.Get_Block();
            Block_Type beforeType = before._type;

            before._type = _type;

            List <Block> explosive = Helper.Get_Explosive(before); // 타입이 바뀐 그 블럭은 터질 수 있나?

            before._type = beforeType;

            if (explosive.Count != 0 && !explosive.Contains(this)) // 힌트 성공!
            {
                HintInfo hint = new HintInfo();
                hint.explosive = explosive;
                hint.moveDir   = (Dir)i;
                hint.moveBlock = this;

                //explosive.Add(this);

                return(hint);
            }
        }

        return(null);
    }
    public void Balloon_clear()
    {
        block_Type = Block_Type.None;

        if (colorID != -1)
        {
            //gen block panel

            GameObject effect = ObjectPool.Spawn(UIManager.Instance.explosion[2], transform, transform.position);
            effect.transform.localScale    = Vector3.one;
            effect.transform.localPosition = Vector3.zero;
        }
        blockImage.transform.localScale = Vector3.one;
        blockImage.sprite = null;
        blockImage.color  = new Color(0, 0, 0, 0);

        GamePlay.instance.Set_Mission_Block(11);


        blockID = -1;
        colorID = -1;

        isFilled          = false;
        isCopyFilled      = false;
        Save_block_sprite = null;
    }
 // constructor
 public Block(Block_Type type, int x, int y, int z, Chunk chunk, int chunk_x, int chunk_y, int chunk_z, Tile tile)
 {
     // init properties
     this.type       = type;
     this.x          = x;
     this.y          = y;
     this.z          = z;
     this.chunk      = chunk;
     this.block_size = chunk.world.block_size;
     this.chunk_x    = chunk_x;
     this.chunk_y    = chunk_y;
     this.chunk_z    = chunk_z;
     this.tile       = tile;
 }
    public Block GetBlock(Block_Type type)
    {
        Block block = null;

        if (_parent[(int)type].childCount > 0)
        {
            block = _parent[(int)type].GetChild(0).GetComponent <Block>();
        }

        if (null == block)
        {
            block = (Instantiate(Resources.Load($"{blockPath}{(int)type}"), _parent[(int)type]) as GameObject).GetComponent <Block>();
        }

        block.SetActivate(true);

        return(block);
    }
    /// <summary>
    /// 폭탄 아이템
    /// </summary>
    public void Boom_Item()
    {
        durability -= 1;
        //Ice_durability -= 1;


        if (block_Type.Equals(Block_Type.ice))
        {
            Debug.Log("아이스 삭제 " + Ice_durability);

            if (Ice_durability <= 0)
            {
            }
            else
            {
                if (durability <= 0)
                {
                    //gen block panel

                    blockImage.transform.localScale = Vector3.one;
                    blockImage.sprite = null;
                    blockImage.color  = new Color(0, 0, 0, 0);

                    blockID = -1;

                    isFilled          = false;
                    isCopyFilled      = false;
                    Save_block_sprite = null;
                }

                Img_IceBlock.gameObject.SetActive(true);
            }
        }
        else
        {
            if (durability <= 0)
            {
                if (colorID != -1 && colorID != 9)
                {
                    //gen block panel

                    GameObject effect = ObjectPool.Spawn(UIManager.Instance.explosion[colorID - 1], transform, transform.position);
                    effect.transform.localScale    = Vector3.one;
                    effect.transform.localPosition = Vector3.zero;
                }


                block_Type = Block_Type.None;


                blockImage.transform.localScale = Vector3.one;
                blockImage.sprite = null;
                blockImage.color  = new Color(0, 0, 0, 0);



                blockID = -1;
                colorID = -1;

                isFilled          = false;
                isCopyFilled      = false;
                Save_block_sprite = null;
            }
            else
            {
                ReturnBlockImg();
            }
        }

        Set_durability_Txt();
    }
    /// <summary>
    /// 부서진 블럭
    /// </summary>
    public void ClearBlock(int block)
    {
        if (block_Type == Block_Type.boom)
        {
            durability = 0;
            block_Type = Block_Type.None;
        }
        else if (block_Type == Block_Type.balloon)
        {
            ReturnBlockImg();
            return;
        }

        Check_Balloon();

        durability     -= 1;
        Ice_durability -= 1;


        if (block_Type.Equals(Block_Type.ice))
        {
            Debug.Log("아이스 삭제 " + Ice_durability);

            if (Ice_durability <= 0)
            {
                Debug.Log("아이스 삭제");
                Img_IceBlock.gameObject.SetActive(false);
                block_Type = Block_Type.None;

                GameObject effect = ObjectPool.Spawn(UIManager.Instance.explosion[block], transform, transform.position);
                effect.transform.localScale    = Vector3.one;
                effect.transform.localPosition = Vector3.zero;
            }
            else
            {
                Img_IceBlock.gameObject.SetActive(true);
            }
        }
        else
        {
            if (durability <= 0)
            {
                block_Type = Block_Type.None;
            }
        }


        if (durability <= 0)
        {
            //gen block panel
            if (colorID != -1)
            {
                //gen block panel

                GameObject effect = ObjectPool.Spawn(UIManager.Instance.explosion[block], transform, transform.position);
                effect.transform.localScale    = Vector3.one;
                effect.transform.localPosition = Vector3.zero;
            }
            blockImage.transform.localScale = Vector3.one;
            blockImage.sprite = null;
            blockImage.color  = new Color(0, 0, 0, 0);



            blockID = -1;
            colorID = -1;

            isFilled          = false;
            isCopyFilled      = false;
            Save_block_sprite = null;
        }
        else
        {
            ReturnBlockImg();
        }

        Set_durability_Txt();
    }
    /// <summary>
    /// 블럭 이미지 및 상태 세팅
    /// </summary>
    /// <param name="sprite">Sprite.</param>
    /// <param name="_blockID">Block I.</param>
    public void SetBlockImage(Sprite sprite, int _blockID, int _colorID, int Hp = 0)
    {
        colorID = _colorID;

        if (block_Type.Equals(Block_Type.None))
        {
            Set_TxtColor(colorID);
        }

        switch (colorID)
        {
        default:

            //blockImage.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);

            if (block_Type.Equals(Block_Type.None))
            {
                block_Type = Block_Type.Basic;
            }

            durability        = 1 + Hp;
            blockID           = _blockID;
            isFilled          = true;
            isCopyFilled      = true;
            Save_block_sprite = sprite;
            blockImage.sprite = sprite;
            blockImage.color  = new Color(1, 1, 1, 1);
            txtCounter.gameObject.SetActive(false);

            LeanTween.scale(blockImage.gameObject, Vector3.one, 0.2f);

            break;

        case (int)Block_Type.durability:

            break;

        case (int)Block_Type.ice:
            block_Type = Block_Type.ice;

            blockImage.sprite = null;

            Ice_durability = 1 + Hp;
            isFilled       = false;
            Img_IceBlock.gameObject.SetActive(true);
            blockImage.color = new Color(0, 0, 0, 0);

            break;

        case (int)Block_Type.noBreak:

            block_Type = Block_Type.noBreak;

            durability        = 9999;
            blockID           = _blockID;
            isFilled          = true;
            isCopyFilled      = true;
            Save_block_sprite = sprite;
            blockImage.sprite = sprite;
            blockImage.color  = new Color(1, 1, 1, 1);
            txtCounter.gameObject.SetActive(false);

            break;

        case (int)Block_Type.boom:

            block_Type = Block_Type.boom;

            durability        = 1 + Hp;
            blockID           = _blockID;
            isFilled          = true;
            isCopyFilled      = true;
            Save_block_sprite = sprite;
            blockImage.sprite = sprite;
            blockImage.color  = new Color(1, 1, 1, 1);
            Boom_Counter.gameObject.SetActive(true);

            break;

        case (int)Block_Type.balloon:

            block_Type = Block_Type.balloon;

            durability        = 1 + Hp;
            blockID           = _blockID;
            isFilled          = true;
            isCopyFilled      = true;
            Save_block_sprite = sprite;
            blockImage.sprite = sprite;
            blockImage.color  = new Color(1, 1, 1, 1);
            txtCounter.gameObject.SetActive(false);

            break;
        }

        Set_durability_Txt();
    }
Exemple #9
0
    public static List <Block> Get_Explosive(Block block) // 특정 방향으로 3-Match, 4-Match
    {
        Block_Type type = block._type;

        List <Block> explodes = new List <Block>();

        if (Is_SpecialBlock(type))
        {
            return(explodes);
        }

        for (int i = 0; i < (int)Dir.Max; ++i)
        {
            // 3-Match
            List <Block> candidates = new List <Block>();

            Match_3((Dir)i, block, ref candidates);

            if (candidates.Count >= 3)
            {
                explodes.AddRange(candidates);
            }
        }

        // 4-Match
        {
            Match_4(block, ref explodes);
        }

        return(explodes);

        void Match_3(Dir dir, Block _block, ref List <Block> candidates)
        {
            candidates.Add(_block);

            Point nearPoint = _block.Get_Point().Get_NearPoint(dir);

            if (null == nearPoint) // 해당 방향으로 블럭 x
            {
                return;
            }

            Block nearBlock = nearPoint.Get_Block();

            if (null == nearBlock)
            {
                return;
            }

            if (nearBlock._type == type) // 같은 타입!
            {
                Match_3(dir, nearBlock, ref candidates);
            }
            else
            {
                return;
            }
        }

        void Match_4(Block _block, ref List <Block> candidates)
        {
            for (int i = 0; i < _match4.Count; ++i)
            {
                List <Block> blocks = new List <Block>();

                Find_4(_match4[i], 0, _block, ref blocks);

                if (blocks.Count >= 3) // 4_match 가 성공하면, 주변에 맞닿은 모든 블럭도 포함이 된다
                {
                    Find_All(_block, ref candidates);
                }
            }

            void Find_4(List <Dir> dirs, int idx, Block standardBlock, ref List <Block> blocks)
            {
                if (dirs.Count <= idx)
                {
                    return;
                }

                Dir dir = dirs[idx];

                Point nearPoint = standardBlock.Get_Point().Get_NearPoint(dir);

                if (null == nearPoint) // 해당 방향으로 블럭 x
                {
                    return;
                }

                Block nearBlock = nearPoint.Get_Block();

                if (nearBlock._type != type)
                {
                    return;
                }

                blocks.Add(nearBlock);

                Find_4(dirs, idx + 1, nearBlock, ref blocks);
            }

            void Find_All(Block startBlock, ref List <Block> blocks)
            {
                blocks.Add(startBlock);

                for (int i = 0; i < (int)Dir.Max; ++i)
                {
                    Point nearPoint = _block.Get_Point().Get_NearPoint((Dir)i);

                    if (null == nearPoint)
                    {
                        continue;
                    }

                    Block nearBlock = nearPoint.Get_Block();
                    if (nearBlock._type != type)
                    {
                        continue;
                    }

                    if (blocks.Contains(nearBlock))
                    {
                        continue;
                    }

                    blocks.Add(startBlock);

                    Find_All(nearBlock, ref blocks);
                }
            }
        }

        bool Check_Same(Block standardBlock, Dir dir)
        {
            Point nearPoint = standardBlock.Get_Point().Get_NearPoint(dir);

            if (null == nearPoint)
            {
                return(false);
            }

            return(nearPoint.Get_Block()._type == type);
        }
    }
Exemple #10
0
 public static bool Is_SpecialBlock(Block_Type type)
 {
     return(type == Block_Type.Spin || type == Block_Type.BombBlock);
 }
Exemple #11
0
 public void Spawn_Block(Block_Type type)
 {
     Set_Block(BlockManager.instance.GetBlock(type));
     _block.Set_Pos(_Tr.position).SetParent(_trBlock);
 }