示例#1
0
            public override EventResult HandleEvent(EventContext context, MessageAnswerSelectedEvent @event)
            {
                context.PlayerInput.Suspend();

                ChainedCommand moveActorCommand = Commands
                                                  .Chain(Commands
                                                         .ActorInstanceMove(_actorInstance, MoveDirection.Right)
                                                         .Repeat(TimeSpan.FromMilliseconds(100), 9))
                                                  .And(Commands.Delay(TimeSpan.FromMilliseconds(100)))
                                                  .And(Commands.ActorInstanceMove(_actorInstance, MoveDirection.Down))
                                                  .And(Commands.Delay(TimeSpan.FromMilliseconds(500)))
                                                  .And(Commands.PlaySoundEffect(context.GetSoundEffectById(ExplodeSoundEffect.SoundEffectId), Volume.Full))
                                                  .And(Commands.RemoveSprite(context.CurrentBoard.ForegroundLayer, new Coordinate(50, 11)))
                                                  .And(Commands.ActorInstanceDestroy(_actorInstance))
                                                  .And(Commands.PlayerResumeInput());

                if (context.Player.Coordinate == new Coordinate(_actorInstance.Coordinate.X + 1, _actorInstance.Coordinate.Y))
                {
                    ChainedCommand command = Commands
                                             .Chain(Commands.Delay(TimeSpan.FromSeconds(1)))
                                             .And(Commands.PlaySoundEffect(context.GetSoundEffectById(SlapSoundEffect.SoundEffectId), Volume.Full))
                                             .And(Commands.PlayerMove(MoveDirection.Down))
                                             .And(Commands.Message(Message.Build(Color.DarkRed, new EventHandlerCollection(new SlapMessageClosedEventHandler(moveActorCommand))).Text(Color.Yellow, "WHAP!")))
                                             .And(Commands.Delay(TimeSpan.FromSeconds(1)));

                    context.EnqueueCommand(command);

                    return(EventResult.Completed);
                }

                context.EnqueueCommand(moveActorCommand);

                return(EventResult.Completed);
            }
            public override EventResult HandleEvent(EventContext context, PlayerTouchedActorInstanceEvent @event)
            {
                Color          indent0        = Color.Yellow;
                Color          indent1        = Color.White;
                MessageBuilder messageBuilder = Message
                                                .Build(Color.DarkBlue)
                                                .Text(indent0, "Actors", 1)
                                                .Text(indent1, "  - Provide a template for actor instances", 1)
                                                .Text(indent1, "  - Don't have any behavior or event handlers");

                context.EnqueueCommand(Commands.Message(messageBuilder));

                if (_handledOnce)
                {
                    return(EventResult.Canceled);
                }

                _handledOnce = true;

                Actor         actor         = context.GetActorById(@event.Target.ActorId);
                ActorInstance actorInstance = actor.CreateActorInstance(BoardId, ExitCoordinates[0], new EventHandlerCollection(new PlayerTouchedActorsActorCopyEventHandler()));
                ActorInstanceCreateCommand actorInstanceCreateCommand = Commands.ActorInstanceCreate(context.GetBoardById(BoardId), actorInstance);

                context.EnqueueCommand(actorInstanceCreateCommand);

                ChainedCommand chainedCommand = Commands
                                                .Chain(Commands.Delay(TimeSpan.FromMilliseconds(200)))
                                                .And(Commands
                                                     .ActorInstanceMove(actorInstance, MoveDirection.Down)
                                                     .Repeat(TimeSpan.FromMilliseconds(200), 2))
                                                .And(Commands.Delay(TimeSpan.FromMilliseconds(200)))
                                                .And(Commands
                                                     .ActorInstanceMove(actorInstance, MoveDirection.Right)
                                                     .Repeat(TimeSpan.FromMilliseconds(200), 5));

                context.EnqueueCommand(chainedCommand);

                return(EventResult.Completed);
            }
            public override EventResult HandleEvent(EventContext context, PlayerTouchedActorInstanceEvent @event)
            {
                switch (@event.TouchDirection)
                {
                case TouchDirection.FromBelow:
                    context.ExecuteCommand(Commands.ActorInstanceMove(@event.Target, MoveDirection.Up));
                    break;

                case TouchDirection.FromAbove:
                    context.ExecuteCommand(Commands.ActorInstanceMove(@event.Target, MoveDirection.Down));
                    break;

                case TouchDirection.FromLeft:
                    context.ExecuteCommand(Commands.ActorInstanceMove(@event.Target, MoveDirection.Right));
                    break;

                case TouchDirection.FromRight:
                    context.ExecuteCommand(Commands.ActorInstanceMove(@event.Target, MoveDirection.Left));
                    break;
                }

                return(EventResult.Completed);
            }