public bool CheckAllBall(BallController[,] newGamePole)
        {
            for (int y = 0; y < _ballPole.GetLength(0) - 1; y++)
            {
                for (int x = 0; x < _ballPole.GetLength(0) - 1; x++)
                {
                    ReverceBall(x, y, x + 1, y);
                    if (_checkBall.CheckChangedBall(_ballPole[x, y], newGamePole, false))
                    {
                        ReverceBall(x, y, x + 1, y);
                        CallSuccessBall(_ballPole[x + 1, y]);
                        return(true);
                    }
                    if (_checkBall.CheckChangedBall(_ballPole[x + 1, y], newGamePole, false))
                    {
                        ReverceBall(x, y, x + 1, y);
                        CallSuccessBall(_ballPole[x, y]);
                        return(true);
                    }



                    ReverceBall(x, y, x + 1, y);

                    ReverceBall(x, y, x, y + 1);

                    if (_checkBall.CheckChangedBall(_ballPole[x, y], newGamePole, false))
                    {
                        ReverceBall(x, y, x, y + 1);
                        CallSuccessBall(_ballPole[x, y + 1]);
                        return(true);
                    }

                    if (_checkBall.CheckChangedBall(_ballPole[x, y + 1], newGamePole, false))
                    {
                        ReverceBall(x, y, x, y + 1);
                        CallSuccessBall(_ballPole[x, y]);
                        return(true);
                    }

                    ReverceBall(x, y, x, y + 1);
                }
            }
            foreach (var ball in newGamePole)
            {
                if (_checkBall.CheckChangedBall(ball, newGamePole, false))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
        public void OnBallMoved(BallController ball, MoveSide side)
        {
            if (_allowMove)
            {
                int  x     = ball.Positinon.X;
                int  y     = ball.Positinon.Y;
                int  newX  = x;
                int  newY  = y;
                bool moved = false;
                switch (side)
                {
                case MoveSide.Down:
                    newY++;
                    if (newY < _gamePole.CountVertCell)
                    {
                        moved = true;
                    }
                    break;

                case MoveSide.Left:
                    newX--;
                    if (newX >= 0)
                    {
                        moved = true;
                    }
                    break;

                case MoveSide.Right:
                    newX++;
                    if (newX < _gamePole.CountHorCell)
                    {
                        moved = true;
                    }
                    break;

                case MoveSide.Up:
                    newY--;
                    if (newY >= 0)
                    {
                        moved = true;
                    }
                    break;
                }
                if (moved)
                {
                    _allowMove = false;
                    CallStartBallMoved();
                    var newBall = _ballPole[newX, newY];
                    _ballPole[newX, newY] = ball;
                    _ballPole[x, y]       = newBall;
                    if (newBall != null)
                    {
                        var ballReverce    = new MoveReverce(ball);
                        var newBallReverce = new MoveReverce(newBall);
                        Move(ball, newX, newY);
                        Move(newBall, x, y);
                        _movedBall += 2;
                        if (_checkBall.CheckChangedBall(ball, _ballPole, true) | _checkBall.CheckChangedBall(newBall, _ballPole, true))
                        {
                            _changed = true;
                            ball.BallAnimationEnd    += OnBallAnimationComplete;
                            newBall.BallAnimationEnd += OnBallAnimationComplete;
                        }
                        else
                        {
                            _reverces.Clear();
                            _reverces[ball]           = ballReverce;
                            _reverces[newBall]        = newBallReverce;
                            ball.BallAnimationEnd    += OnBallReverce;
                            newBall.BallAnimationEnd += OnBallReverce;
                        }
                    }
                }
            }
        }