예제 #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) => !(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;
        }
예제 #2
0
        public void CanResolveMessage()
        {
            var loader         = new TileLoader();
            var mobiles        = loader.Load(_level, MobilesMap.TileBuilder);
            var messageHandler = new MessageHandler(mobiles);

            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);
        }
예제 #3
0
        public void CanIndex()
        {
            var loader  = new TileLoader();
            var tileSet = loader.Load(_level, StaticsMap.TileBuilder);

            Assert.AreEqual(tileSet[1, 1].Token, '.');
        }
예제 #4
0
        public void CanConstruct()
        {
            var loader  = new TileLoader();
            var tileSet = loader.Load(_level, StaticsMap.TileBuilder);

            Assert.IsNotNull(tileSet.Tiles);
        }
예제 #5
0
        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 == '.');
        }
예제 #6
0
        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, '#');
        }
예제 #7
0
        public void LoadsTilesFromTestFile()
        {
            List <Tile> tiles = TileLoader.Load(Path.Combine(TestContext.CurrentContext.WorkDirectory, "./TestFiles/Tiles.json"));

            Assert.That(tiles, Is.Not.Null);
            Assert.That(tiles, Has.Count.EqualTo(3));
            Assert.That(tiles[0].Id, Is.EqualTo(1));
            Assert.That(tiles[0].MovementFlags, Is.EqualTo(TileMovementFlags.BulletPassable |
                                                           TileMovementFlags.Passable |
                                                           TileMovementFlags.Standable));

            Assert.That(tiles[1].Id, Is.EqualTo(5));
            Assert.That(tiles[1].MovementFlags, Is.EqualTo(TileMovementFlags.BulletPassable));

            Assert.That(tiles[2].Id, Is.EqualTo(13));
            Assert.That(tiles[2].MovementFlags, Is.EqualTo(TileMovementFlags.None));
        }
예제 #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });


            //load tiles
            MasterGameController.TheGame.Tiles = TileLoader.Load("Data/Tiles.json");
        }