Ejemplo n.º 1
0
    //重新编号
    void reOrder()
    {
        //重新编号
        float temp_x = mBegin_Pos.x;

        if (Container.Count <= this.Row_Count * this.Col_Count)
        {
            for (int col = 0; col < Col_Count; col++)
            {
                //获取根据Y坐标排序后的每一列的游戏物体,以保证游戏物体是自下而上的编号是升序的
                var query_col = (from CandyAction ca in Container where ca.mCol == col && ca.isDestroy == false select ca).OrderBy((CandyAction ca) => {
                    return(ca.gameObject.transform.position.y);
                });
                int row = 0;
                List <CandyAction> temp = query_col.ToList <CandyAction>();
                //重新编号
                for (int index = 0; index < temp.Count; index++)
                {
                    temp[index].mRow      = row;
                    temp[index].isDestroy = false;
                    temp[index].isReorder = true;
                    //temp[index].gameObject.transform.position = new Vector3(mBegin_Pos.x+col*mSep,mBegin_Pos.y+row*mSep,0f);
                    temp[index].mPos = new Vector3(mBegin_Pos.x + col * mSep, mBegin_Pos.y + row * mSep, 0f);
                    row++;
                }
                //每列编号完成,根据行号决定每列应该生成新的游戏物体的数量并重新生成新的游戏物体
                for (; row < this.Row_Count; row++)
                {
                    CandyAction new_object = getRandomGameObject(col, row);
                    Container.Add(new_object);
                    new_object.gameObject.transform.position = new Vector3(mBegin_Pos.x + col * mSep, mBegin_Pos.y + (this.Row_Count + row) * mSep, 0f);
                }
            }
        }
    }
Ejemplo n.º 2
0
    CandyAction getCandyObject(int col, int row)
    {
        var query = from CandyAction ca in Container
                    where  ca.mCol == col && ca.mRow == row
                    select ca;
        CandyAction temp_Object = query.Count() > 0 ? query.First() : null;

        return(temp_Object);
    }
Ejemplo n.º 3
0
 void apply_exchange_pos(CandyAction item)
 {
     //
     if (null != exchangeItem && item != exchangeItem && isReadyToExchange)
     {
         //列判断是否可以交换位置
         if (Mathf.Approximately(item.mPos.y, exchangeItem.mPos.y))
         {
             if (Mathf.Approximately(item.mPos.x + xOff, exchangeItem.mPos.x) || Mathf.Approximately(item.mPos.x - xOff, exchangeItem.mPos.x))
             {
                 exchangeList.Clear();                    //清空交换列表
                 //
                 exchange_pos(exchangeItem, item);        //交换位置
                 //
                 exchangeList.Add(item);
                 exchangeList.Add(exchangeItem);
                 //
                 isReadyToExchange = false;
                 SendMessage("apply_adjust_postion", exchangeList);                   //请求更新在数组中的位置
             }
             else
             {
                 exchangeItem = item;
             }
         }
         else if (Mathf.Approximately(item.mPos.x, exchangeItem.mPos.x))                 //行判断是否可以交换位置
         {
             if (Mathf.Approximately(item.mPos.y + yOff, exchangeItem.mPos.y) || Mathf.Approximately(item.mPos.y - yOff, exchangeItem.mPos.y))
             {
                 exchangeList.Clear();                    //清空交换列表
                 //
                 exchange_pos(exchangeItem, item);        //交换位置
                 //
                 exchangeList.Add(item);
                 exchangeList.Add(exchangeItem);
                 //
                 isReadyToExchange = false;
                 SendMessage("apply_adjust_postion", exchangeList);                   //请求更新在数组中的位置
             }
             else
             {
                 exchangeItem = item;
             }
         }
         else
         {
             exchangeItem = item;
         }
     }
     else
     {
         exchangeItem = item;
     }
 }
Ejemplo n.º 4
0
 void reset_pos()
 {
     if (exchangeList.Count == 2)
     {
         CandyAction item0 = exchangeList [0] as CandyAction;
         CandyAction item1 = exchangeList[1] as CandyAction;
         //
         exchange_pos(item0, item1);
         //
         SendMessage("apply_adjust_postion_0", exchangeList);           //请求更新在数组中的位置
         //
         isReadyToExchange = true;
     }
 }
Ejemplo n.º 5
0
    /// <summary>
    /// 获取随机糖果
    /// </summary>
    /// <returns>The random game object.</returns>
    private CandyAction getRandomGameObject(int col, int row)
    {
        GameObject result = null;
        //Random.seed = Mathf.FloorToInt (Time.time)+Random.Range(0,1000);
        int index = Random.Range(0, 5);

        switch (index)
        {
        case 0: {
            result = Instantiate(candy1) as GameObject;
            break;
        }

        case 1: {
            result = Instantiate(candy2) as GameObject;
            break;
        }

        case 2: {
            result = Instantiate(candy3) as GameObject;
            break;
        }

        case 3: {
            result = Instantiate(candy4) as GameObject;
            break;
        }

        case 4: {
            result = Instantiate(candy5) as GameObject;
            break;
        }

        default: break;
        }
        CandyAction ca = null;

        if (null != result)
        {
            ca           = result.GetComponent(typeof(CandyAction)) as CandyAction;
            ca.mIndex    = index;
            ca.mPos      = new Vector3(mBegin_Pos.x + col * mSep, mBegin_Pos.y + row * mSep, 0);
            ca.mRow      = row;
            ca.mCol      = col;
            ca.isDestroy = false;
        }
        return(ca);
    }
Ejemplo n.º 6
0
    //
    void exchange_pos(CandyAction item0,CandyAction item1)
    {
        //item0.mPos = item1.transform.position;
        //item1.mPos = item0.transform.position;

        Vector3 temp_pos = item0.mPos;
        item0.mPos = item1.mPos;
        item1.mPos = temp_pos;
        //
        int temp_row = item0.mRow;
        int temp_col = item0.mCol;
        //
        item0.mCol = item1.mCol;
        item0.mRow = item1.mRow;
        //
        item1.mRow = temp_row;
        item1.mCol = temp_col;
    }
Ejemplo n.º 7
0
    void checkMatch()
    {
        var query_destroyed = from CandyAction item in Container where item.isDestroy == true select item;
        var query_reorder   = from CandyAction item in Container where item.isReorder == true select item;

        if (query_destroyed.Count() == 0 && Container.Count == this.Row_Count * this.Col_Count && query_reorder.Count() == this.Row_Count * this.Col_Count)
        {
            for (int index = 0; index < Container.Count; index++)
            {
                //获取左边邻居
                CandyAction leftObject = getCandyObject(Container[index].mCol - 1, Container[index].mRow);
                //获取右边邻居
                CandyAction rightObject = getCandyObject(Container[index].mCol + 1, Container[index].mRow);
                //获取上邻居
                CandyAction topObject = getCandyObject(Container[index].mCol, Container[index].mRow + 1);
                //获取下邻居
                CandyAction bottomObject = getCandyObject(Container[index].mCol, Container[index].mRow - 1);
                //判断是否应该被销毁
                //左右邻居
                if (null != leftObject && leftObject.mIndex == Container[index].mIndex)
                {
                    if (null != rightObject && rightObject.mIndex == Container[index].mIndex)
                    {
                        Container[index].isDestroy = true;
                        leftObject.isDestroy       = true;
                        rightObject.isDestroy      = true;
                    }
                }
                //上下邻居
                if (null != topObject && topObject.mIndex == Container[index].mIndex)
                {
                    if (null != bottomObject && bottomObject.mIndex == Container[index].mIndex)
                    {
                        Container[index].isDestroy = true;
                        topObject.isDestroy        = true;
                        bottomObject.isDestroy     = true;
                    }
                }
            }
        }
        readyToDestroy = true;
        readyToAdd     = false;
    }
Ejemplo n.º 8
0
    void apply_exchange_pos(CandyAction item)
    {
        //
        if (null != exchangeItem && item != exchangeItem && isReadyToExchange) {
            //列判断是否可以交换位置
            if (Mathf.Approximately (item.mPos.y, exchangeItem.mPos.y)) {
                if (Mathf.Approximately (item.mPos.x + xOff, exchangeItem.mPos.x) || Mathf.Approximately (item.mPos.x - xOff, exchangeItem.mPos.x)) {
                    exchangeList.Clear();//清空交换列表
                    //
                    exchange_pos(exchangeItem,item);//交换位置
                    //
                    exchangeList.Add (item);
                    exchangeList.Add (exchangeItem);
                    //
                    isReadyToExchange = false;
                    SendMessage("apply_adjust_postion",exchangeList);//请求更新在数组中的位置

                } else {
                    exchangeItem = item;
                }

            } else if (Mathf.Approximately (item.mPos.x, exchangeItem.mPos.x)) {//行判断是否可以交换位置
                if (Mathf.Approximately (item.mPos.y + yOff, exchangeItem.mPos.y) || Mathf.Approximately (item.mPos.y - yOff, exchangeItem.mPos.y)) {
                    exchangeList.Clear();//清空交换列表
                    //
                    exchange_pos(exchangeItem,item);//交换位置
                    //
                    exchangeList.Add (item);
                    exchangeList.Add (exchangeItem);
                    //
                    isReadyToExchange = false;
                    SendMessage("apply_adjust_postion",exchangeList);//请求更新在数组中的位置
                } else {
                    exchangeItem = item;
                }
            } else {
                exchangeItem = item;
            }
        } else {
            exchangeItem = item;
        }
    }
Ejemplo n.º 9
0
    //
    void exchange_pos(CandyAction item0, CandyAction item1)
    {
        //item0.mPos = item1.transform.position;
        //item1.mPos = item0.transform.position;

        Vector3 temp_pos = item0.mPos;

        item0.mPos = item1.mPos;
        item1.mPos = temp_pos;
        //
        int temp_row = item0.mRow;
        int temp_col = item0.mCol;

        //
        item0.mCol = item1.mCol;
        item0.mRow = item1.mRow;
        //
        item1.mRow = temp_row;
        item1.mCol = temp_col;
    }
Ejemplo n.º 10
0
    void Start()
    {
        float Re_X = mBegin_Pos.x;

        Container = new List <CandyAction> ();
        for (int row = 0; row < this.Row_Count; ++row)
        {
            for (int col = 0; col < this.Col_Count; ++col)
            {
                CandyAction instance = getRandomGameObject(col, row);
                if (null != instance)
                {
                    instance.gameObject.transform.position = new Vector3(mBegin_Pos.x + col * mSep, mBegin_Pos.y + row * mSep, 0f);
                    Container.Add(instance);
                }
                else
                {
                    Debug.Log("getRandomGameObject(col,row) Faild!");
                }
            }
        }
    }
Ejemplo n.º 11
0
 void Start()
 {
     exchangeItem = null;
     exchangeList = new ArrayList();
 }
Ejemplo n.º 12
0
 void Start()
 {
     exchangeItem = null;
     exchangeList = new ArrayList ();
 }