Ejemplo n.º 1
0
    /*
     * bool checkSameColor(bool bClean = false)
     * {
     *  // check line
     *  int nSameColorCount = 0;
     *  int nOldColor = -1;
     *  for (int x = 0; x < xIndex; ++x)
     *  {
     *      // Recalc
     *      nSameColorCount = 0;
     *      nOldColor = -1;
     *      for (int y = 0; y < yIndex; ++y)
     *      {
     *          TileScript tileScript = tiles[x, y].GetComponent<TileScript>();
     *          if (tileScript.IsCleaned())
     *          {
     *              nSameColorCount = 0;
     *              nOldColor = -1;
     *              continue;
     *          }
     *          if (x == circleIndexX &&
     *              y == circleIndexY)
     *          {
     *              nSameColorCount = 0;
     *              nOldColor = -1;
     *              continue;
     *          }
     *          int nColor = tileScript.returnColor();
     *          if (nColor == nOldColor)
     *          {
     ++nSameColorCount;
     *          }
     *          else
     *          {
     *              nSameColorCount = 1;
     *              nOldColor = nColor;
     *          }
     *
     *          if (nSameColorCount >= 3)
     *          {
     *              // 消除这些连续的色块
     *              if(bClean)
     *              {
     *                  nCicleMoveTimes = 6;
     *                  score.SendMessage("addScore", nSameColorCount);
     *                  for (int o = 0; o < nSameColorCount; ++o)
     *                 {
     *                     tiles[x, y - o].GetComponent<TileScript>().Clean();
     *
     *                      Vector2 fogPos = new Vector2(arrPosX[x, y-o]-1, arrPosY[x, y-o]);
     *                      GameObject fog = Instantiate(fogPS);
     *                      fog.transform.parent = gridHolder.transform;
     *                      fog.transform.position = fogPos;
     *                  }
     *              }
     *              Debug.Log("3 Same Color : x = " + x + ", y = " + y);
     *              return true;
     *          }
     *      }
     *  }
     *
     *  // check row
     *  nSameColorCount = 0;
     *  nOldColor = -1;
     *  for (int y = 0; y < yIndex; ++y)
     *  {
     *      // Recalc
     *      nSameColorCount = 0;
     *      nOldColor = -1;
     *      for (int x = 0; x < xIndex; ++x)
     *      {
     *          TileScript tileScript = tiles[x, y].GetComponent<TileScript>();
     *          if(tileScript.IsCleaned())
     *          {
     *              nSameColorCount = 0;
     *              nOldColor = -1;
     *              continue;
     *          }
     *          if(x == circleIndexX &&
     *              y == circleIndexY)
     *          {
     *              nSameColorCount = 0;
     *              nOldColor = -1;
     *              continue;
     *          }
     *          int nColor = tileScript.returnColor();
     *          if (nColor == nOldColor)
     *          {
     ++nSameColorCount;
     *          }
     *          else
     *          {
     *              nSameColorCount = 1;
     *              nOldColor = nColor;
     *          }
     *
     *          if (nSameColorCount >= 3)
     *          {
     *
     *              // 消除这些连续的色块
     *              if (bClean)
     *              {
     *                  nCicleMoveTimes = 6;
     *                  score.SendMessage("addScore",nSameColorCount);
     *                  for (int o = 0; o < nSameColorCount; ++o)
     *                  {
     *                      tiles[x - o, y].GetComponent<TileScript>().Clean();
     *                      Vector2 fogPos = new Vector2(arrPosX[x - o, y]-1, arrPosY[x-o, y]);
     *                      GameObject fog = Instantiate(fogPS);
     *                      fog.transform.parent = gridHolder.transform;
     *                      fog.transform.position = fogPos;
     *                  }
     *              }
     *             // Debug.Log("3 Same Color : x = " + x + ", y = " + y);
     *              return true;
     *          }
     *      }
     *  }
     *
     *  return false;
     * }
     */
    bool checkSameColor(bool bClean = false)
    {
        // check line
        int nSameColorCount = 0;
        int nOldColor       = -1;
        int nStartY         = -1;

        for (int x = 0; x < xIndex; ++x)
        {
            // Recalc
            nSameColorCount = 0;
            nOldColor       = -1;
            nStartY         = -1;
            for (int y = 0; y < yIndex; ++y)
            {
                TileScript tileScript = tiles[x, y].GetComponent <TileScript>();
                if (tileScript.IsCleaned() ||
                    (x == circleIndexX && y == circleIndexY))
                {
                    if (nSameColorCount >= 3)
                    {
                        break;
                    }
                    nSameColorCount = 0;
                    nOldColor       = -1;
                    nStartY         = -1;
                    continue;
                }

                int nColor = tileScript.returnColor();
                if (nColor == nOldColor)
                {
                    ++nSameColorCount;
                    nStartY = y;
                }
                else
                {
                    if (nSameColorCount >= 3)
                    {
                        break;
                    }
                    nSameColorCount = 1;
                    nOldColor       = nColor;
                }
            }

            if (nSameColorCount >= 3)
            {
                // 消除这些连续的色块
                if (bClean)
                {
                    nCicleMoveTimes = 6;
                    score.SendMessage("addScore", nSameColorCount);
                    myAudio.PlayOneShot(getSameColorAudio);
                    for (int o = 0; o < nSameColorCount; ++o)
                    {
                        tiles[x, nStartY - o].GetComponent <TileScript>().Clean();

                        Vector2    fogPos = new Vector2(arrPosX[x, nStartY - o] - 1, arrPosY[x, nStartY - o]);
                        GameObject fog    = Instantiate(fogPS);
                        fog.transform.parent   = gridHolder.transform;
                        fog.transform.position = fogPos;
                    }
                }
                Debug.Log("3 Same Color : x = " + x + ", y = " + nStartY);
                return(true);
            }
        }

        // check row
        nSameColorCount = 0;
        nOldColor       = -1;
        int nStartX = -1;

        for (int y = 0; y < yIndex; ++y)
        {
            // Recalc
            nSameColorCount = 0;
            nOldColor       = -1;
            nStartX         = -1;
            for (int x = 0; x < xIndex; ++x)
            {
                TileScript tileScript = tiles[x, y].GetComponent <TileScript>();
                if (tileScript.IsCleaned() ||
                    (x == circleIndexX && y == circleIndexY))
                {
                    if (nSameColorCount >= 3)
                    {
                        break;
                    }
                    nSameColorCount = 0;
                    nOldColor       = -1;
                    nStartX         = -1;
                    continue;
                }
                int nColor = tileScript.returnColor();
                if (nColor == nOldColor)
                {
                    ++nSameColorCount;
                    nStartX = x;
                }
                else
                {
                    if (nSameColorCount >= 3)
                    {
                        break;
                    }
                    nSameColorCount = 1;
                    nOldColor       = nColor;
                }
            }

            if (nSameColorCount >= 3)
            {
                // 消除这些连续的色块
                if (bClean)
                {
                    nCicleMoveTimes = 6;
                    score.SendMessage("addScore", nSameColorCount);
                    myAudio.PlayOneShot(getSameColorAudio);
                    for (int o = 0; o < nSameColorCount; ++o)
                    {
                        tiles[nStartX - o, y].GetComponent <TileScript>().Clean();
                        Vector2    fogPos = new Vector2(arrPosX[nStartX - o, y] - 1, arrPosY[nStartX - o, y]);
                        GameObject fog    = Instantiate(fogPS);
                        fog.transform.parent   = gridHolder.transform;
                        fog.transform.position = fogPos;
                    }
                }
                Debug.Log("3 Same Color : x = " + nStartX + ", y = " + y);
                return(true);
            }
        }

        return(false);
    }