public void CanLoad()
 {
     var staticLoader = new TileLoader();
     var statics = staticLoader.Load(_level, StaticsMap.TileBuilder);
     Assert.That(statics[0,0].Token == '#');
     Assert.That(statics[1,1].Token == '.');
 }
Beispiel #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) => !(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 CanResolveMessage()
        {
            var loader = new TileLoader();
            var mobiles = loader.Load(_level, MobilesMap.TileBuilder);
            var messageHandler = new MessageHandler(mobiles, null);

            var player = mobiles.WithName("player");

            var previousPlayerLocation = player.Location;

            var message = new Message{
                Name = "player",
                Type = "movement",
                From = player.Location.ToString(),
                To = new Point(player.Location.X - 1, player.Location.Y).ToString()
            };

            messageHandler.Resolve(message);

            Assert.AreNotEqual(previousPlayerLocation,player.Location);
            Assert.AreEqual(previousPlayerLocation.X - 1, player.Location.X);

            messageHandler.Resolve(message.Invert());
            Assert.AreEqual(previousPlayerLocation, player.Location);
        }
 public void CanUpdate()
 {
     var loader = new TileLoader();
     var tileSet = loader.Load(_level, StaticsMap.TileBuilder);
     tileSet[1, 1].Location = new Point(0,0);
     tileSet[0, 0].Location = new Point(1, 1);
     tileSet.Update();
     Assert.AreEqual(tileSet[1, 1].Token, '#');
 }
 public void CanIndex()
 {
     var loader = new TileLoader();
     var tileSet = loader.Load(_level, StaticsMap.TileBuilder);
     Assert.AreEqual(tileSet[1,1].Token, '.');
 }
 public void CanConstruct()
 {
     var loader = new TileLoader();
     var tileSet = loader.Load(_level, StaticsMap.TileBuilder);
     Assert.IsNotNull(tileSet.Tiles);
 }