Example #1
0
    private void CheckDirectionForMatchingNeighbors(CPUActions cpuAction, Ball ball, RaycastHit2D[] direction)
    {
        if (direction.Length > 0)
        {
            switch (cpuAction)
            {
            case CPUActions.FindBall:
                CheckForMatchingNeighbors(ball, direction);
                break;

            case CPUActions.MakeBrown:
                CheckForBrownNeighbors(ball, direction);
                break;

            default:
                break;
            }
        }
    }
Example #2
0
 // Start is called before the first frame update
 void Start()
 {
     ShowDebug = true;
     //BallSize = Constants.FindOffset(Cursor.Ball.gameObject);
     PlayerManager      = GetComponentInParent <PlayerManager>();
     PlayerColorManager = PlayerManager.PlayerColorManager;
     Cursor             = GetComponent <Cursor>();
     BallSize           = gameObject.transform.localScale;
     Gameboard          = Cursor.Gameboard;
     Detectors          = PlayerManager.detectorManager.VerticalDetectors;
     PlayerPrefix       = PlayerManager.PlayerNumberManager.PlayerPrefix;
     SetMovementSpeed(cpuDifficulty);
     if (Gameboard.ObjectPooler.PooledItems.Count > 0)
     {
         BallSize = Gameboard.ObjectPooler.PooledItems[0].transform.localScale;
     }
     action       = CPUActions.FindBall;
     coolDownTime = 3f;
 }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        if (coolDownTime <= 0 && !PlayerManager.GameOver)
        {
            if (ShowDebug)
            {
                print(PlayerManager.PlayerNumber.ToString() + ": " + action);
            }
            switch (action)
            {
            case CPUActions.CheckColumns:
                //print("Checvking COlumns");
                foreach (Detector detector in Detectors)
                {
                    if (detector.BallCount())
                    {
                        print("Make a brown");
                        action = CPUActions.MakeBrown;
                        break;
                    }
                }
                //print(action + " is the action");
                action = CPUActions.FindBall;
                break;

            case CPUActions.FindBall:
                FindSameColor();
                FindSameColorNeighbors(UsableBalls);
                chosenBall = PickBallToGoTo(MultipleMatchingNeighbors, SingleMatchingNeighbors);
                SingleMatchingNeighbors.Clear();
                MultipleMatchingNeighbors.Clear();
                if (chosenBall != null)
                {
                    action = CPUActions.Move;
                }
                coolDownTime = cursorMovementSpeed;
                break;

            case CPUActions.WhiteOut:
                UseWhiteOut(chosenBall.GetComponent <Ball>());
                action       = CPUActions.FindBall;
                coolDownTime = cursorMovementSpeed;
                break;

            case CPUActions.Move:
                if (chosenBall != null)
                {
                    float destX = Mathf.Round(chosenBall.transform.position.x);
                    float destY = Mathf.Round(chosenBall.transform.position.y);
                    MoveStepTowardsDestination(destX, destY);
                    if (Mathf.Round(transform.position.x) == destX && Mathf.Round(transform.position.y) == destY)
                    {
                        if (chosenBall.GetComponent <Ball>().BallColor == BallColor.black)
                        {
                            action = CPUActions.WhiteOut;
                        }
                        else
                        {
                            action = CPUActions.ChangeColor;
                        }
                    }
                    break;
                }
                else
                {
                    action = CPUActions.FindBall;
                    break;
                }

            case CPUActions.ChangeColor:
                transform.position = chosenBall.transform.position;
                ChangeColor(chosenBall.GetComponent <Ball>());
                action       = CPUActions.CheckColumns;
                coolDownTime = cursorMovementSpeed;
                break;

            case CPUActions.MakeBrown:
                chosenBall = MakeABrownBall();
                action     = CPUActions.Move;
                break;

            default:
                break;
            }
        }
        else
        {
            coolDownTime -= Time.deltaTime;
        }
    }
Example #4
0
    public void FindSameColor()
    {
        UsableBalls.Clear();
        CurrentBalls.Clear();
        //Get the current color
        PlayerColor playerColor        = PlayerColorManager.ColorQueue[0];
        BallColor   ballColor          = BallColor.white;
        BallColor   secondaryBallColor = BallColor.white;
        BallColor   tertiaryBallColor  = BallColor.white;

        switch (playerColor)
        {
        case PlayerColor.red:
            ballColor          = BallColor.red;
            secondaryBallColor = BallColor.purple;
            tertiaryBallColor  = BallColor.orange;
            break;

        case PlayerColor.blue:
            ballColor          = BallColor.blue;
            secondaryBallColor = BallColor.green;
            tertiaryBallColor  = BallColor.purple;
            break;

        case PlayerColor.yellow:
            ballColor          = BallColor.yellow;
            secondaryBallColor = BallColor.orange;
            tertiaryBallColor  = BallColor.green;
            break;

        default:
            break;
        }
        //Find all existing balls with the same color on the board.
        foreach (Ball ball in Gameboard.GetComponentsInChildren <Ball>())
        {
            if (ball.isActiveAndEnabled)
            {
                CurrentBalls.Add(ball);
            }
        }
        foreach (Ball ball in CurrentBalls)
        {
            if (ball.BallColor == BallColor.black && Cursor.RemoveColor.Uses > 0)
            {
                chosenBall = ball.gameObject;
                action     = CPUActions.Move;
                return;
            }
            //Branch to consider using a whiteout if there aren't any matching colors.
            if ((ball.BallColor == ballColor || ball.BallColor == secondaryBallColor || ball.BallColor == tertiaryBallColor))
            {
                UsableBalls.Add(ball);
            }
        }
        //In case there are balls matching the player color at all.
        if (UsableBalls.Count <= 0)
        {
            Ball randomWhiteBall = CurrentBalls[Random.Range(0, CurrentBalls.Count)];
            UsableBalls.Add(randomWhiteBall);
        }
    }