Пример #1
0
    private void InitBalls()
    {
        for (int i = 0; i < Board.instance.GetRowNumber(); ++i)
        {
            for (int j = 0; j < Board.instance.GetColumnNumber(); ++j)
            {
                m_ballsArray[i, j] = null;
            }
        }

        for (int i = 0; i < INIT_BALL;)
        {
            int row = Random.Range(0, Board.instance.GetRowNumber());
            int col = Random.Range(0, Board.instance.GetColumnNumber());

            if (m_ballsArray[row, col] == null)
            {
                ColorsBall color = (ColorsBall)Random.Range((int)ColorsBall.blue, (int)ColorsBall.yellow);;
                m_ballsArray[row, col] = NewBall(row, col, m_boardPos[row, col], color, StatusBall.ON_BOARD);
                m_ballsArray[row, col].GetComponent <Ball>().SetProperties(row, col, m_boardPos[row, col], color, StatusBall.ON_BOARD);
                m_ballsArray[row, col].GetComponent <Ball>().ActiveTrigger(AnimBallType.GROW_UP2);

                ++i;
            }
        }
    }
Пример #2
0
 public void SetProperties(int row, int col, Vector2 pos, ColorsBall color, StatusBall status)
 {
     m_row    = row;
     m_col    = col;
     m_pos    = pos;
     m_color  = color;
     m_status = status;
     if (m_color == ColorsBall.ghost)
     {
         m_type = TypesBall.GHOST;
     }
     else
     {
         m_type = TypesBall.NORMAL;
     }
 }
Пример #3
0
    public GameObject NewBall(int row, int col, Vector2 pos, ColorsBall color, StatusBall status)
    {
        switch (color)
        {
        case ColorsBall.blue:
            return(Instantiate(BlueBallPrefab, new Vector3(pos.x, pos.y, 0.0f), Quaternion.identity));

            break;

        case ColorsBall.boxdeaux_red:
            return(Instantiate(BoxdeauxRedBallPrefab, new Vector3(pos.x, pos.y, 0.0f), Quaternion.identity));

            break;

        case ColorsBall.cyan:
            return(Instantiate(CyanBallPrefab, new Vector3(pos.x, pos.y, 0.0f), Quaternion.identity));

            break;

        case ColorsBall.ghost:
            return(Instantiate(GhostBallPrefab, new Vector3(pos.x, pos.y, 0.0f), Quaternion.identity));

            break;

        case ColorsBall.green:
            return(Instantiate(GreenBallPrefab, new Vector3(pos.x, pos.y, 0.0f), Quaternion.identity));

            break;

        case ColorsBall.pink:
            return(Instantiate(PinkBallPrefab, new Vector3(pos.x, pos.y, 0.0f), Quaternion.identity));

            break;

        case ColorsBall.red:
            return(Instantiate(RedBallPrefab, new Vector3(pos.x, pos.y, 0.0f), Quaternion.identity));

            break;

        case ColorsBall.yellow:
            return(Instantiate(YellowBallPrefab, new Vector3(pos.x, pos.y, 0.0f), Quaternion.identity));

            break;
        }
        return(null);
    }
Пример #4
0
    private void GenerateNextBalls()
    {
        int emptySquare = GetEmptySquare();

        for (int i = 0; i < NEXT_BALL && i < emptySquare;)
        {
            int row = Random.Range(0, Board.instance.GetRowNumber());
            int col = Random.Range(0, Board.instance.GetColumnNumber());

            bool alreadyExisted = false;
            if (m_ballsArray[row, col] != null)
            {
                alreadyExisted = true;
            }

            for (int j = 0; j < m_ballInQueueList.Count; ++j)
            {
                if (row == m_ballInQueueList[j].GetComponent <Ball>().GetRowIndex() && col == m_ballInQueueList[j].GetComponent <Ball>().GetColumnIndex())
                {
                    alreadyExisted = true;
                }
            }

            if (!alreadyExisted)
            {
                ColorsBall color = (ColorsBall)Random.Range((int)ColorsBall.blue, (int)ColorsBall.yellow);;
                m_ballInQueueList.Add(NewBall(row, col, m_boardPos[row, col], color, StatusBall.IN_QUEUE));
                m_ballInQueueList[m_ballInQueueList.Count - 1].GetComponent <Ball>().SetProperties(row, col, m_boardPos[row, col], color, StatusBall.IN_QUEUE);

                m_nextDisplayBallList.Add(NewBall(row, col, m_ballDisplayDummyPos - new Vector2(0, i * m_displayBallVerticalLength), color, StatusBall.NO_QUEUE));
                m_nextDisplayBallList[m_nextDisplayBallList.Count - 1].GetComponent <Ball>().SetProperties(row, col, m_ballDisplayDummyPos - new Vector2(0, i * m_displayBallVerticalLength), color, StatusBall.NO_QUEUE);
                m_nextDisplayBallList[m_nextDisplayBallList.Count - 1].GetComponent <Ball>().ActiveTrigger(AnimBallType.GROW_UP2);

                ++i;
            }
        }
    }
Пример #5
0
    private int EarnBalls()
    {
        //m_earnedBallsList
        List <GameObject> earnedBalllistInCase = new List <GameObject>();
        int earnBallsTotal = 0;

        for (int i = 0; i < Board.instance.GetRowNumber(); ++i)
        {
            for (int j = 0; j < Board.instance.GetColumnNumber(); ++j)
            {
                if (m_ballsArray[i, j] != null)
                {
                    ColorsBall color = m_ballsArray[i, j].GetComponent <Ball>().GetColor();

                    //check horizontal
                    earnedBalllistInCase.Clear();
                    earnedBalllistInCase.Add(m_ballsArray[i, j]);
                    int earnBall = 1; //one in focus
                    for (int u = j + 1; u < Board.instance.GetColumnNumber(); ++u)
                    {
                        if (m_ballsArray[i, u] != null && color == m_ballsArray[i, u].GetComponent <Ball>().GetColor())
                        {
                            earnBall++;
                            earnedBalllistInCase.Add(m_ballsArray[i, u]);
                        }
                        else
                        {
                            break;
                        }
                    }
                    for (int u = j - 1; u > -1; --u)
                    {
                        if (m_ballsArray[i, u] != null && color == m_ballsArray[i, u].GetComponent <Ball>().GetColor())
                        {
                            earnBall++;
                            earnedBalllistInCase.Add(m_ballsArray[i, u]);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (earnBall >= MIN_BALL_NUM_TO_EARN)
                    {
                        int listSize = m_earnedBallsList.Count;
                        CopyList(earnedBalllistInCase, m_earnedBallsList);
                        if (listSize != m_earnedBallsList.Count)
                        {
                            earnBallsTotal += earnBall;
                        }
                    }

                    //check vertical
                    earnedBalllistInCase.Clear();
                    earnedBalllistInCase.Add(m_ballsArray[i, j]);
                    earnBall = 1; //one in focus
                    for (int u = i + 1; u < Board.instance.GetRowNumber(); ++u)
                    {
                        if (m_ballsArray[u, j] != null && color == m_ballsArray[u, j].GetComponent <Ball>().GetColor())
                        {
                            earnBall++;
                            earnedBalllistInCase.Add(m_ballsArray[u, j]);
                        }
                        else
                        {
                            break;
                        }
                    }
                    for (int u = i - 1; u > -1; --u)
                    {
                        if (m_ballsArray[u, j] != null && color == m_ballsArray[u, j].GetComponent <Ball>().GetColor())
                        {
                            earnBall++;
                            earnedBalllistInCase.Add(m_ballsArray[u, j]);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (earnBall >= MIN_BALL_NUM_TO_EARN)
                    {
                        int listSize = m_earnedBallsList.Count;
                        CopyList(earnedBalllistInCase, m_earnedBallsList);
                        if (listSize != m_earnedBallsList.Count)
                        {
                            earnBallsTotal += earnBall;
                        }
                    }

                    //check diagonal 1
                    earnedBalllistInCase.Clear();
                    earnedBalllistInCase.Add(m_ballsArray[i, j]);
                    earnBall = 1; //one in focus
                    int r = i, c = j;
                    while (r > 0 && c > 0)
                    {
                        r--;
                        c--;
                        if (m_ballsArray[r, c] != null && color == m_ballsArray[r, c].GetComponent <Ball>().GetColor())
                        {
                            earnBall++;
                            earnedBalllistInCase.Add(m_ballsArray[r, c]);
                        }
                        else
                        {
                            break;
                        }
                    }

                    r = i; c = j;
                    while (r < Board.instance.GetRowNumber() - 1 && c < Board.instance.GetColumnNumber() - 1)
                    {
                        r++;
                        c++;
                        if (m_ballsArray[r, c] != null && color == m_ballsArray[r, c].GetComponent <Ball>().GetColor())
                        {
                            earnBall++;
                            earnedBalllistInCase.Add(m_ballsArray[r, c]);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (earnBall >= MIN_BALL_NUM_TO_EARN)
                    {
                        int listSize = m_earnedBallsList.Count;
                        CopyList(earnedBalllistInCase, m_earnedBallsList);
                        if (listSize != m_earnedBallsList.Count)
                        {
                            earnBallsTotal += earnBall;
                        }
                    }

                    //check diagonal 2
                    earnedBalllistInCase.Clear();
                    earnedBalllistInCase.Add(m_ballsArray[i, j]);
                    earnBall = 1; //one in focus
                    r        = i; c = j;
                    while (r > 0 && c < Board.instance.GetColumnNumber() - 1)
                    {
                        r--;
                        c++;
                        if (m_ballsArray[r, c] != null && color == m_ballsArray[r, c].GetComponent <Ball>().GetColor())
                        {
                            earnBall++;
                            earnedBalllistInCase.Add(m_ballsArray[r, c]);
                        }
                        else
                        {
                            break;
                        }
                    }

                    r = i; c = j;
                    while (r < Board.instance.GetRowNumber() - 1 && c > 0)
                    {
                        r++;
                        c--;
                        if (m_ballsArray[r, c] != null && color == m_ballsArray[r, c].GetComponent <Ball>().GetColor())
                        {
                            earnBall++;
                            earnedBalllistInCase.Add(m_ballsArray[r, c]);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (earnBall >= MIN_BALL_NUM_TO_EARN)
                    {
                        int listSize = m_earnedBallsList.Count;
                        CopyList(earnedBalllistInCase, m_earnedBallsList);
                        if (listSize != m_earnedBallsList.Count)
                        {
                            earnBallsTotal += earnBall;
                        }
                    }
                    earnedBalllistInCase.Clear();
                }
            }
        }

        if (earnBallsTotal > 0)
        {
            for (int i = 0; i < m_earnedBallsList.Count; ++i)
            {
                int r = m_earnedBallsList[i].GetComponent <Ball>().GetRowIndex();
                int c = m_earnedBallsList[i].GetComponent <Ball>().GetColumnIndex();
                Destroy(m_ballsArray[r, c]);
                m_ballsArray[r, c] = null;

                m_explosionBallList.Add(Instantiate(ExplosionBall, new Vector3(m_boardPos[r, c].x, m_boardPos[r, c].y, 0.0f), Quaternion.identity));
            }

            m_earnedBallsList.Clear();
        }

        return(earnBallsTotal);
    }