예제 #1
0
 //Ball state
 public void ChangeBallState(Ball.State state)
 {
     if (state == Ball.State.Idle && Ball != null)
     {
         Ball.Idle();
     }
     else if (state == Ball.State.Selected && Ball != null)
     {
         Ball.Selected();
         CellPointer.ChangePointerState(CellPointer.PointerState.Selected);
     }
 }
예제 #2
0
    private void SpawnBalls(int _id, Ball.Type _type, Ball.State _state)
    {
        if (_id >= lBalls.Count)
        {
            return;
        }

        // active ball
        Ball ball = lBalls[_id];

        // swap component (only for special ball)
        if (_type == Ball.Type.COLORFULL)
        {
            BallColorFull compBall = ball.gameObject.AddComponent <BallColorFull>();
            compBall.Clone(ball);
            Destroy(ball);

            lBalls[_id] = compBall;
            ball        = compBall;
        }
        else
        {
            if (ball.GetType() == Ball.Type.COLORFULL)
            {
                Ball compBall = ball.gameObject.AddComponent <Ball>();
                compBall.Clone(ball);
                Destroy(ball);

                lBalls[_id] = compBall;
                ball        = compBall;
            }
        }

        ball.SetType(_type);
        ball.SetActiveState(_state, true);

        // update list of small balls
        if (_state == Ball.State.GROWSMALL)
        {
            UpdateListSmallBalls(true, _id);
        }

        // update list empty tiles (remove this id)
        UpdateListEmptyTiles(false, _id);

        // DEBUG
        if (DebugUtils.IsDebugEnable())
        {
            Debug.Log("SPAWN BALL = " + _id);
        }
    }
예제 #3
0
    public void OnBallStateEventHandler(Ball ball, Ball.State state)
    {
        switch (state)
        {
        case Ball.State.IDLE:
        case Ball.State.MOVING:
        {
            break;
        }

        case Ball.State.DESTROYED:
        {
            if (ball)
            {
                ball.onStateChange            -= OnBallStateEventHandler;
                ball.onReadyToGenerateNewBall -= OnReadyToGenerateNewBallHandler;
            }
            break;
        }
        }
    }
예제 #4
0
    // === spawn ball ===
    private void SpawnRandomBalls(Ball.State _state)
    {
        // gen balls
        List <int> spawnIds = new List <int>();
        int        turn     = Mathf.Min(GameConfig.ballSpawnPerTurn, lEmptyTiles.Count);

        // Random Position (not match prev pos)
        for (int i = 0; i < turn; i++)
        {
            int rdId = -1;
            do
            {
                rdId = (turn == GameConfig.ballSpawnPerTurn) ? Random.Range(0, lEmptyTiles.Count) : i;
            } while (rdId >= lEmptyTiles.Count || spawnIds.Contains(lEmptyTiles[rdId]));

            spawnIds.Add(lEmptyTiles[rdId]);
        }

        // Random Type
        List <Ball.Type> rdTypes = new List <Ball.Type>();

        for (int i = 0; i < 3; i++)
        {
            Ball.Type type = Ball.Type.BLUE;    // default color
            // get type from random list
            if (i < lnextTypes.Count)
            {
                rdTypes.Add(lnextTypes[i]);
            }
            else
            {
                // random type for this turn
                type = (Ball.Type)Random.Range((int)Ball.Type.BLUE, (int)Ball.Type.COUNT);
                rdTypes.Add(type);
            }

            // random for next turn
            type = (Ball.Type)Random.Range((int)Ball.Type.BLUE, (int)Ball.Type.COUNT);
            if (i < lnextTypes.Count)
            {
                lnextTypes[i] = (type);
            }
            else
            {
                lnextTypes.Add(type);
            }
        }

        for (int i = 0; i < spawnIds.Count; i++)
        {
            SpawnBalls(spawnIds[i], rdTypes[i], _state);
        }

        // Show Panel
        if (lnextTypes.Count >= 3)
        {
            TopPanelMgr.instance.RefreshBallPanel(Ball.GetSprite(lnextTypes[0]), Ball.GetSprite(lnextTypes[1]), Ball.GetSprite(lnextTypes[2]));
        }

        // GAME OVER (out of slot of ball to spawn)
        if (turn < GameConfig.ballSpawnPerTurn || lEmptyTiles.Count <= 0)
        {
            GameMgr.Instance.OnGameOver();

            if (DebugUtils.IsDebugEnable())
            {
                Debug.Log("GAME OVER");
            }
        }
    }