예제 #1
0
        public override void Step(IList <IStepable> oldWorld, IList <IStepable> newWorld)
        {
            if (_actions.Last().Type == ActionType.BallConsumed)
            {
                return;
            }

            var ball = Clone() as Ball;

            Debug.Assert(ball != null, "ball != null");

            while (Count > 0)
            {
                ball.GetActions().Add(new StepAction(ActionType.Nope, null, ball.GetPosition(), ball.Color));
                Count--;
            }

            var otherBlock = Game.GetByPos(ball.GetPosition(), oldWorld) as IInteract;

            if (otherBlock != null)
            {
                ball.GetActions().Add(new StepAction(ActionType.BallInteract, otherBlock, ball.GetPosition(), ball.Color));
                otherBlock.Interact(ball);
            }
            else
            {
                ball.Move(0, 1);
                ball.GetActions().Add(new StepAction(ActionType.BallMove, null, ball.GetPosition(), ball.Color));
            }

            BallHistory.GetInstance().AddBall(ball);
            newWorld.Add(ball);
        }
예제 #2
0
        /// <summary>
        ///     Произвести заполнение внутренего хранилища шариками
        ///     в случайном порядке.
        /// </summary>
        private void _generateBalls()
        {
            int ballsCount = 0;

            foreach (var pair in _ballsSettings)
            {
                for (var i = 0; i < pair.Value; i++)
                {
                    var ball = new Ball(ballsCount)
                    {
                        Color = pair.Key
                    };
                    ball.SetPosition(GetPosition());
                    _genBalls.Add(ball);
                    BallHistory.GetInstance().AddBall(ball);
                    ballsCount++;
                }
            }

            Shuffle(_genBalls);
        }