Пример #1
0
        public void GetCloseModelObjects_Test()
        {
            VModel model = new VModel();

            Point size = new Point();
            size.X = 100;
            size.Y = 50;

            model.Map = new Map2d(size);

            // [TARGET of Test] Presume that the first id's are reserved for players
            ModelPlayer player = new ModelPlayer(model, 0, 10);

            // Create Coins
            ModelCoin coin_0 = new ModelCoin(model, 10, 2);
            ModelCoin coin_1 = new ModelCoin(model, 11, 2);
            ModelCoin coin_2 = new ModelCoin(model, 12, 2);
            ModelCoin coin_3 = new ModelCoin(model, 13, 2);

            // Add objects to model
            model.AddModelObject(player, new Point(10, 10));
            model.AddModelObject(coin_0, new Point(18, 18)); // should be neighbour
            model.AddModelObject(coin_1, new Point(8, 8)); // should be neighbour
            model.AddModelObject(coin_2, new Point(30, 30)); // should still be neighbour
            model.AddModelObject(coin_3, new Point(31, 31)); // should NOT be neighbour

            // Sizes:
            // -> biggest object: 10
            // -> current object: 10
            // So: currentPoint + currentObjectSize + biggestObjectSize = 30

            ICollection<ModelObject> neighbours = model.GetCloseModelObjects(player);

            Assert.AreEqual(3, neighbours.Count);

            foreach (var neigh in neighbours)
            {
                Assert.AreEqual(typeof(ModelCoin), neigh.GetType());
                Assert.AreNotEqual(coin_3, neigh);
            }
        }
Пример #2
0
        public void ComputePosition_Valid_Test()
        {
            GameLogicMock target = new GameLogicMock();

            IVModel model = new VModel();

            Point size = new Point();
            size.X = 100;
            size.Y = 50;

            model.Map = new Map2d(size);

            // Insert a Wall exactly in the middle
            model.Map.InsertWall(new Wall() { Start = new Point() { X = 0, Y = 25 }, End = new Point() { X = 100, Y = 25 } });

            Point toPosition = new Point(20, 10);

            // Create Objects
            ModelPlayer player = new ModelPlayer(model, 0, 10); // what is the size?
            ModelCoin coin = new ModelCoin(model, 10, 2);

            // Add Objects to model
            model.AddModelObject(player, new Point(10, 10));
            model.AddModelObject(coin, toPosition);

            bool result = target.computePosition(player, toPosition, true, true);

            Assert.AreEqual(true, result);
            Assert.AreEqual(1, target.CoinRemovedCounter);
        }
Пример #3
0
        public void PlayerMeetsCoin_Valid_Args_Test()
        {
            GameLogicMock target = new GameLogicMock();

            IVModel model = new VModel();

            // Create Objects
            ModelPlayer player = new ModelPlayer(model, 0, 10);
            ModelCoin coin = new ModelCoin(model, 10, 2);

            // Add Objects to model
            model.AddModelObject(player, new Point(10, 10));
            model.AddModelObject(coin, new Point(12, 12));

            var result = target.playerMeetsCoinAction(player, coin);

            Assert.AreEqual(1, target.CoinRemovedCounter);
        }
Пример #4
0
        private void initLevel(NonPersistentLevel l)
        {
            Point size = new Point(l.Lvl.Width, l.Lvl.Height);
            IMap2d map = new Map2d(size);
            Model.Map = map;

            map.InsertWalls(l.Lvl.Walls);
            //add coins
            int coinSize = 1;
            for (int i = 0; i < l.Coins.Count; i++)
            {
                ModelCoin mc = new ModelCoin(Model, l.Coins[i].Id, coinSize);
                Model.AddModelObject(mc, l.Coins[i].Pos);
            }
        }