Exemplo n.º 1
0
 public void AddToBallPocketedList(CueBallController ball)
 {
     // making sure we are not adding a ball multiple times
     if (!_ballsPocketed.Contains(ball))
     {
         _ballsPocketed.Add(ball);
     }
 }
Exemplo n.º 2
0
        private void OnTriggerStay(Collider collider)
        {
            CueBallController cueBallController = collider.gameObject.GetComponent <CueBallController>();

            if (cueBallController != null && cueBallController.GetComponent <Rigidbody>().IsSleeping())
            {
                GameManager.Instance.AddToBallHitOutList(cueBallController);
            }
        }
Exemplo n.º 3
0
 public void AddToBallHitOutList(CueBallController ball)
 {
     // these balls will be back on pool table
     // check if the ball is already potted too and then fell on floor
     if (!_ballsHitOut.Contains(ball) && !_ballsPocketed.Contains(ball))
     {
         _ballsHitOut.Add(ball);
     }
 }
Exemplo n.º 4
0
        private void OnTriggerEnter(Collider collider)
        {
            CueBallController cueBall = collider.gameObject.GetComponent <CueBallController>();

            if (cueBall != null)
            {
                cueBall.BallPocketed();
            }
        }
Exemplo n.º 5
0
        private void CalculateThePointAndNextTurn()
        {
            // now that all the ball are stationary, lets decide on  next state of game
            // check the balls pocketed list, first for the cueball and then to the count
            // if there is a cue ball in the list then the current player looses a point, and the cue ball is placed in the table
            // else then the score is count for the current player
            // then check if there are any ball in the floor
            // if there is any they get placed in their respective position
            Player currPlayer = _players.Peek();

            // check if the player has striked the ball
            if (currPlayer.HasStrikedBall)
            {
                CueBallController whiteBall = _ballsPocketed.FirstOrDefault(b => b.BallType == CueBallController.CueBallType.White);
                if (whiteBall != null)
                {
                    // player looses score
                    currPlayer.CalculateScore(-1);

                    // remove the white ball from pocket
                    _ballsPocketed.Remove(whiteBall);

                    // set all pocketed balls to true, as the ball pocketed along with the white ball is considered already pocketed
                    _ballsPocketed.ForEach(b => b.IsPocketedInPrevTurn = true);

                    // place the cue ball back in the table
                    whiteBall.PlaceBallInInitialPos();

                    SetNewPlayerTurn();
                }
                else
                {
                    if (_ballsPocketed.Count() > 0)
                    {
                        // get the balls that are currently pockted, the currently pocketed ball will have a value set to false
                        var ballsCurrentlyPocketed = _ballsPocketed.Where(b => b.IsPocketedInPrevTurn == false);
                        Debug.Log("Balls Currently Pocketed" + ballsCurrentlyPocketed.Count());
                        if (ballsCurrentlyPocketed.Count() > 0)
                        {
                            // count for the number of balls pocketed, and increment the player score
                            currPlayer.CalculateScore(ballsCurrentlyPocketed.Count());

                            // set all pocketed balls to true
                            _ballsPocketed.ForEach(b => b.IsPocketedInPrevTurn = true);

                            // player continues to play
                        }
                        else
                        {
                            SetNewPlayerTurn();
                        }
                    }
                    else
                    {
                        SetNewPlayerTurn();
                    }
                }

                // place these balls back in the pool table
                foreach (var ballHitOut in _ballsHitOut)
                {
                    ballHitOut.PlaceBallInInitialPos();
                }
            }

            // clear up every information
            _ballsHitOut.Clear();

            // reset players state
            foreach (var player in _players)
            {
                // checking if the current player in iteration is the first player and setting the state accordingly
                // only the first player in the queue is in playing state
                // note: state is set based on the condition
                player.SetPlayingState((player == _players.Peek()));
            }

            // check if all balls in the game are pocketed
            if (IsGameComplete())
            {
                StartCoroutine(OnGameComplete());
            }
            else
            {
                EventManager.Notify(typeof(CueBallActionEvent).Name, this, new CueBallActionEvent()
                {
                    State = CueBallActionEvent.States.Stationary
                });
            }
        }