Пример #1
0
        protected override void Load(ContainerBuilder builder)
        {
            // KEYBOARD:
            builder.Register<XnaKeyboard>().As<IKeyboard>().SingletonScoped();

            // MOUSE:
            builder.Register<XnaMouse>().As<IMouse>().SingletonScoped();

            // CROSSHAIR:
            builder.Register<Crosshair>().As<ICrosshair>().ContainerScoped();
            builder.Register<CrosshairView>().ContainerScoped();

            builder.Register(container =>
                {
                    var mapping = new KeyMapping();
                    mapping[GameKey.MoveLeft].Keyboard.AddRange(new List<Keys>() { Keys.Left, Keys.A });
                    mapping[GameKey.MoveRight].Keyboard.AddRange(new List<Keys>() { Keys.Right, Keys.D });
                    mapping[GameKey.Jump].Keyboard.AddRange(new List<Keys>() { Keys.Up, Keys.W });
                    mapping[GameKey.Jump].Mouse.Add(MouseKeys.Right);
                    mapping[GameKey.Shoot].Mouse.Add(MouseKeys.Left);
                    mapping[GameKey.RocketLauncher].Keyboard.Add(Keys.Q);
                    mapping[GameKey.RailGun].Keyboard.Add(Keys.E);
                    return mapping;
                }).As<IKeyMapping>().SingletonScoped();
            builder.Register<GameInput>().As<IGameInput>().SingletonScoped();
        }
Пример #2
0
        public void ShouldAllowRegisteringMultipleKeysInMapping()
        {
            var keyMapping = new KeyMapping();

            keyMapping[GameKey.MoveRight].Keyboard.Add(Keys.D);
            keyMapping[GameKey.MoveRight].Keyboard.Add(Keys.Right);
            keyMapping[GameKey.MoveRight].Mouse.Add(MouseKeys.Right);

            Assert.AreEqual(2, keyMapping[GameKey.MoveRight].Keyboard.Count);
            Assert.AreEqual(1, keyMapping[GameKey.MoveRight].Mouse.Count);
        }