Esempio n. 1
0
 public void Init(int _x, int _y, GameManager _gameManager, SweetType _type)
 {
     x           = _x;
     y           = _y;
     gameManager = _gameManager;
     type        = _type;
 }
Esempio n. 2
0
    //清除全部完成匹配的甜品
    private bool ClearAllMatchedSweet()
    {
        bool needRefill = false;//是否重新填充

        //遍历场景是否存在可清除的甜品
        for (int y = 0; y < yRow; y++)
        {
            for (int x = 0; x < xColumn; x++)
            {
                if (sweets[x, y].CanClear())
                {
                    List <GameSweet> matchList = MatchSweets(sweets[x, y], x, y);                  //用一个列表去接收匹配成功的返回来的甜品列表
                    if (matchList != null)
                    {                                                                              //如果不为空则遍历列表中的每一个甜品对象进行清除
                        SweetType specialSweetsType = SweetType.COUNT;                             //定义一个特殊类型的甜品
                        GameSweet randomSweet       = matchList[Random.Range(0, matchList.Count)]; //随机一个匹配成功之后的糖果选定一个,即3个选一个
                        int       specialSweetX     = randomSweet.X;
                        int       specialSweetY     = randomSweet.Y;


                        if (matchList.Count == 4)
                        {
                            //随机出一个(生成)行消除或者列消除的特殊甜品
                            specialSweetsType = (SweetType)Random.Range((int)SweetType.ROW_CLEAR, (int)SweetType.COLUMN_CLEAR + 1);
                        }
                        else if (matchList.Count >= 5)//大于4就产生彩虹糖
                        {
                            //随机出一个(生成)行消除或者列消除的特殊甜品
                            specialSweetsType = SweetType.RAINBOWCANDY;
                        }


                        for (int i = 0; i < matchList.Count; i++)
                        {
                            if (ClearSweet(matchList[i].X, matchList[i].Y))
                            {
                                needRefill = true;//是否重新填充
                            }
                        }

                        if (specialSweetsType != SweetType.COUNT)
                        {                                                                                         //有问题,需要填充,没有为true,还是昨晚想到的那个
                            //Destroy(sweets[specialSweetX, specialSweetY]);
                            GameSweet newSweet = CreateNewSweet(specialSweetX, specialSweetY, specialSweetsType); //生成特殊甜品对象

                            if (specialSweetsType == SweetType.ROW_CLEAR || specialSweetsType == SweetType.COLUMN_CLEAR && matchList[0].CanColor() && newSweet.CanColor())
                            {
                                newSweet.ColoredComponent.SetColor(matchList[0].ColoredComponent.Color);
                            }
                            if (specialSweetsType == SweetType.RAINBOWCANDY && newSweet.CanColor())
                            {
                                newSweet.ColoredComponent.SetColor(ColorType.COLORS);
                            }
                        }
                    }
                }
            }
        }
        return(needRefill);
    }
Esempio n. 3
0
    //在指定位置创建一个指定类型的甜品
    public GameSweet CreatNewSweet(int x, int y, SweetType type)
    {
        GameObject newSweet = Instantiate(sweetDict[type], CorrectPosition(x, y), Quaternion.identity);

        newSweet.transform.SetParent(spawner);
        sweets[x, y] = newSweet.GetComponent <GameSweet>();
        sweets[x, y].Init(x, y, this, type);
        return(sweets[x, y]);
    }
Esempio n. 4
0
    //清除完成匹配的元素
    public bool ClearAllMatchSweet()
    {
        bool needReFill = false;

        for (int y = 0; y < yRow; y++)
        {
            for (int x = 0; x < xColumn; x++)
            {
                if (sweets[x, y].CanClear())
                {
                    // 返回的需要删除的元素列表
                    List <GameSweet> matchList = MatchSweets(sweets[x, y], x, y);
                    if (matchList != null)
                    {
                        // Debug.Log("消除列表长度="+matchList.Count);
                        SweetType specialSweetType = SweetType.COUNT;
                        //在随机一个消除位置生成一个行消除或者列消除
                        GameSweet birthSpecialSweet = matchList[Random.Range(0, matchList.Count)];
                        int       specialX          = birthSpecialSweet.X;
                        int       specialY          = birthSpecialSweet.Y;
                        if (matchList.Count == 4)
                        {
                            // Debug.Log("开始产生特殊物品!!!!!!!!!!!!!!!");
                            //随机一个行消除或者列消除
                            specialSweetType = (SweetType)Random.Range((int)SweetType.ROW_CLEAR, (int)SweetType.RAINBOWCANDY);
                        }

                        for (int i = 0; i < matchList.Count; i++)
                        {
                            //if (matchList[i] == null)
                            //    continue;
                            if (ClearSweet(matchList[i].X, matchList[i].Y))
                            {
                                needReFill = true;
                            }
                        }

                        if (specialSweetType != SweetType.COUNT)
                        {
                            //Debug.Log("开始产生特殊物品");
                            Destroy(sweets[specialX, specialY]);
                            GameSweet newSweet = CreatNewSweet(specialX, specialY, specialSweetType);
                            if (specialSweetType == SweetType.ROW_CLEAR || specialSweetType == SweetType.COLUMN_CLEAR && newSweet.CanMove() && matchList[0].CanColor())
                            {
                                //newSweet.ColorComponent.SetColor(matchList[0].ColorComponent.Color);
                            }
                            else
                            {
                            }
                        }
                    }
                }
            }
        }
        return(needReFill);
    }
Esempio n. 5
0
    //产生甜品的方法
    public GameSweet CreateNewSweet(int x, int y, SweetType type)
    {
        GameObject newSweet = Instantiate(sweetPrefabDic[type], CorrectPosition(x, y), Quaternion.identity) as GameObject;

        newSweet.transform.parent = transform;

        sweets[x, y] = newSweet.GetComponent <GameSweet>();
        sweets[x, y].Init(x, y, this, type);

        return(sweets[x, y]);
    }
Esempio n. 6
0
    //产生甜品的方法
    public GameSweet CreatNewSweet(int x, int y, SweetType type)
    {
        GameObject newSweet = Instantiate(sweetPrefabDict[type], CorrectPosition(x, y), Quaternion.identity);

        //设置父节点
        newSweet.transform.parent = transform;
        //将其添加进存储的数组里面
        sweets[x, y] = newSweet.GetComponent <GameSweet>();
        //初始化
        sweets[x, y].Init(x, y, this, type);
        return(sweets[x, y]);
    }
Esempio n. 7
0
    public GameSweet CreateNewSweet(int x, int y, SweetType type)
    {
        Debug.Log("x 的值:" + x + "   y的值:" + y + "    type" + type);
        GameObject newSweet = Instantiate(sweetPrefabDic[type], CorrectPos(x, y), Quaternion.identity);

        newSweet.transform.SetParent(transform);

        sweets[x, y] = newSweet.GetComponent <GameSweet>();
        sweets[x, y].Init(x, y, this, type);

        return(sweets[x, y]);
    }
Esempio n. 8
0
    //清楚全部完成匹配的方法
    private bool ClearAllMatchedSweet()
    {
        bool needRefill = false;

        for (int y = 0; y < yRow; y++)
        {
            for (int x = 0; x < xColum; x++)
            {
                if (sweets[x, y].CanClear())
                {
                    List <GameSweet> matchList = MatchSweets(sweets[x, y], x, y);
                    if (matchList != null)
                    {
                        SweetType specialSweetsType = SweetType.COUNT;
                        GameSweet randomSweet       = matchList[Random.Range(0, matchList.Count)];
                        int       specialSweetX     = randomSweet.X;
                        int       specialSweetY     = randomSweet.Y;
                        if (matchList.Count == 4)
                        {
                            specialSweetsType = (SweetType)Random.Range((int)SweetType.ROW_CLEAR, (int)SweetType.COLUMN_CLEAR);
                        }
                        // else if (matchList.Count >= 5)
                        //     specialSweetsType = SweetType.RAINBOWCANDY;

                        for (int i = 0; i < matchList.Count; i++)
                        {
                            if (ClearSweet(matchList[i].X, matchList[i].Y))
                            {
                                needRefill = true;
                            }
                        }
                        if (specialSweetsType != SweetType.COUNT)
                        {
                            Destroy(sweets[specialSweetX, specialSweetY]);
                            GameSweet newSweet = CreateNewSweet(specialSweetX, specialSweetY, specialSweetsType);
                            if (specialSweetsType == SweetType.ROW_CLEAR || specialSweetsType == SweetType.COLUMN_CLEAR &&
                                newSweet.CanColor() && matchList[0].CanColor())
                            {
                                newSweet.ColoredComponent.SetColor(matchList[0].ColoredComponent.Color);
                            }
                            //加上彩虹糖的特殊类型的产生
                            else if (specialSweetsType == SweetType.RAINBOWCANDY && newSweet.CanColor())
                            {
                                newSweet.ColoredComponent.SetColor(ColorSweet.ColorType.ANY);
                            }
                        }
                    }
                }
            }
        }
        return(needRefill);
    }
Esempio n. 9
0
    /// <summary>
    /// 清除游戏中所有的符合清除条件的甜品 以及在清除时判断是否能生成特殊功能的甜品
    /// </summary>
    /// <returns></returns>
    public bool ClearAllMatchSweet()
    {
        bool needReFill = false;//是否需要再次填充

        for (int y = 0; y < yRow; y++)
        {
            for (int x = 0; x < xColumn; x++)
            {
                if (sweets[x, y].CanClear())//如果该位置可以被消除
                {
                    List <GameSweet> matchedSweets = MatchSweets(sweets[x, y], x, y);
                    if (matchedSweets != null)
                    {
                        SweetType specialSweetype = SweetType.COUNT;//该类型表示特殊甜品的类型:行消除列消除彩虹糖等甜品(匹配到的甜品数量大于4时才生成特殊甜品)
                        GameSweet speciaSweet     = matchedSweets[Random.Range(0, matchedSweets.Count)];
                        int       specialSweetX   = speciaSweet.X;
                        int       specialSweetY   = speciaSweet.Y;
                        if (matchedSweets.Count == 4)//如果为4个,则随机生成行消除甜品或列消除甜品
                        {
                            specialSweetype = (SweetType)Random.Range((int)SweetType.ROW_CLEAR, (int)SweetType.COLUMN_CLEAR);
                        }
                        else if (matchedSweets.Count >= 5)//如股票大于等于5个,则生成彩虹糖
                        {
                            specialSweetype = SweetType.RAINBOWCANDY;
                        }
                        for (int i = 0; i < matchedSweets.Count; i++)
                        {
                            if (ClearSweet(matchedSweets[i].X, matchedSweets[i].Y))
                            {
                                needReFill = true;
                            }
                        }
                        if (specialSweetype != SweetType.COUNT)
                        {
                            Destroy(sweets[specialSweetX, specialSweetY]);
                            GameSweet newSweet = CreatNewSweet(specialSweetX, specialSweetY, specialSweetype);
                            if (specialSweetype == SweetType.COLUMN_CLEAR || specialSweetype == SweetType.ROW_CLEAR && newSweet.CanColor() && matchedSweets[0].CanColor())
                            {
                                newSweet.ColorSweetComponent.SetColor(matchedSweets[0].ColorSweetComponent.Color);
                            }
                            //彩虹糖的产生
                            else if (specialSweetype == SweetType.RAINBOWCANDY && newSweet.CanColor())
                            {
                                newSweet.ColorSweetComponent.SetColor(ColorSweet.ColorType.ANY);
                            }
                        }
                    }
                }
            }
        }
        return(needReFill);
    }
Esempio n. 10
0
 public Sweet(string name, string manufacturer, SweetType sweetType) : base(name, manufacturer)
 {
     this.sweetType = sweetType;
 }