Example #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);
        }