public void TestAdjacentChange()
        {
            var s = new VoxelChangeListener();

            var world = TestWorldBuilder.createTestWorld(10, 10);

            var target = world.GetVoxel(new Point2(5, 5));

            var count = 0;

            s.RegisterAdjacentChange(target, _ => count++);

            world.GetVoxel(new Point2(4, 5)).Data.Type = new GameVoxelType("Type1");
            world.GetVoxel(new Point2(5, 4)).Data.Type = new GameVoxelType("Type3");
            world.GetVoxel(new Point2(5, 7)).Data.Type = new GameVoxelType("Type2");

            s.ProcessChanges(world);
            world.ClearChangedFlags();
            Assert.AreEqual(2, count);

            s.UnRegisterAdjacentChange(target);

            world.GetVoxel(new Point2(4, 5)).Data.Type = new GameVoxelType("Type1");
            world.GetVoxel(new Point2(5, 4)).Data.Type = new GameVoxelType("Type3");
            world.GetVoxel(new Point2(5, 7)).Data.Type = new GameVoxelType("Type2");

            s.ProcessChanges(world);
            world.ClearChangedFlags();
            Assert.AreEqual(2, count);
        }
        public void TestRegisterAnyChange()
        {
            var s = new VoxelChangeListener();

            var world = TestWorldBuilder.createTestWorld(10, 10);
            var count = 0;

            var d = s.ChangedVoxels.Subscribe(_ => count++);

            world.GetVoxel(new Point2(4, 5)).Data.Type = new GameVoxelType("Type1");
            world.GetVoxel(new Point2(5, 4)).Data.Type = new GameVoxelType("Type3");
            world.GetVoxel(new Point2(5, 7)).Data.Type = new GameVoxelType("Type2");

            s.ProcessChanges(world);
            world.ClearChangedFlags();
            Assert.AreEqual(3, count);

            d.Dispose();

            world.GetVoxel(new Point2(4, 5)).Data.Type = new GameVoxelType("Type1");
            world.GetVoxel(new Point2(5, 4)).Data.Type = new GameVoxelType("Type3");
            world.GetVoxel(new Point2(5, 7)).Data.Type = new GameVoxelType("Type2");

            s.ProcessChanges(world);
            world.ClearChangedFlags();
            Assert.AreEqual(3, count);
        }
        public void Setup()
        {
            world = TestWorldBuilder.createTestWorld(20, 10);

            gameState = new GameState(world);

            inputHandler = Substitute.For <IPlayerInputHandler>();
            npf          = new NetworkedPlayerFactory(
                (transporter, handler) => new NetworkPlayerInputForwarder(transporter, handler, world),
                state => inputHandler, gameState);
        }
Ejemplo n.º 4
0
        public void Setup()
        {
            textarea      = new Textarea();
            textarea.Text = "";

            builder = new Autofac.ContainerBuilder();

            foreach (var type in Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace != null && t.Namespace.StartsWith("MHGameWork.TheWizards.GodGame") &&
                                                                                  t.IsPublic))
            {
                builder.Register(delegate(IComponentContext ctx)
                {
                    textarea.Text += type.FullName + "\n";
                    return(new object());
                }).As(type);
            }

            world = TestWorldBuilder.createTestWorld(100, 10);
            builder.RegisterInstance(world);
            builder.RegisterInstance(worldPersister);

            builder.Register(ctx => new PlayerTool[0]).As <IEnumerable <PlayerTool> >();
        }
        private static void testInputHandler(IClientPacketTransporter <UserInputHandlerPacket> proxyTrans, IClientPacketTransporter <UserInputHandlerPacket> realTrans)
        {
            var world         = TestWorldBuilder.createTestWorld(20, 10);
            var proxyHandler  = new ProxyPlayerInputHandler(proxyTrans);
            var realHandler   = Substitute.For <IPlayerInputHandler>();
            var inputReceiver = new NetworkPlayerInputForwarder(realTrans, realHandler, world);

            proxyHandler.OnSave();
            Thread.Sleep(100);
            inputReceiver.ForwardReceivedInputs();
            realHandler.Received().OnSave();

            proxyHandler.OnNextTool();
            Thread.Sleep(100);
            inputReceiver.ForwardReceivedInputs();
            realHandler.Received().OnNextTool();

            proxyHandler.OnPreviousTool();
            Thread.Sleep(100);
            inputReceiver.ForwardReceivedInputs();
            realHandler.Received().OnPreviousTool();

            var pos1 = new Point2(3, 4);

            proxyHandler.OnLeftClick(world.GetVoxel(pos1));
            Thread.Sleep(100);
            inputReceiver.ForwardReceivedInputs();
            realHandler.Received().OnLeftClick(world.GetVoxel(pos1));


            var pos2 = new Point2(3, 4);

            proxyHandler.OnRightClick(world.GetVoxel(pos2));
            Thread.Sleep(100);
            inputReceiver.ForwardReceivedInputs();
            realHandler.Received().OnRightClick(world.GetVoxel(pos2));
        }