Example #1
0
        public Model(char[,] statics, char[,] mobiles, IModelBehaviour behaviourModel)
        {
            InputBuffer = new ControllerMessageMediator();
            var loader = new TileLoader();

            Statics = loader.Load(statics, StaticsMap.TileBuilder);

            Statics.AddCollisionRules(
                (mobile, tile) => !tile.IsTraversible);

            Mobiles = loader.Load(mobiles, MobilesMap.TileBuilder);

            Mobiles.AddCollisionRules(
                (mobile, tile) => !(mobile.CanPush && tile.CanBePushed),
                (mobile, tile) => !(mobile.CanKill && tile.CanBeKilled),
                (mobile, tile) => !(mobile.CanFall && tile.CanBeFellInto)
                );

            Width = statics.GetWidth();
            Height = statics.GetHeight();

            behaviourModel.SetupBehaviours(Mobiles, Statics ,_gameMessageReactor);

            _messageHandler = new MessageHandler(Mobiles, Statics);

            InputBuffer.Subscribe(GameConstants.PLAYER, _playerInputQueue);
            InputBuffer.Subscribe(GameConstants.GAME, _gameInputQueue);

            _playerInputQueue.MessageRecieved += ResolvePlayerInput;
            _gameInputQueue.MessageRecieved += ResolveGameMessage;
        }
 public void CanListenForMessages()
 {
     var listener = new MessageListener<ControllerMessage>();
     var mediator = new ControllerMessageMediator();
     mediator.Subscribe("test", listener);
     var testMessage = new ControllerMessage { Header = "test", Body = "testing123" };
     var uselessMessage = new ControllerMessage { Header = "poop", Body = "xxxx" };
     var callCount = 0;
     listener.MessageRecieved += m => callCount++;
     mediator.Send(testMessage);
     mediator.Send(uselessMessage);
     Assert.AreEqual(1, callCount);
 }