Ejemplo n.º 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;
        }
Ejemplo n.º 2
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) => !(tile.IsTraversible),
                (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);

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

            _playerInputQueue.MessageRecieved += ResolvePlayerInput;
            _gameInputQueue.MessageRecieved   += ResolveGameMessage;
        }