Example #1
0
        /// <summary>Initializes a new instance of the MatchViewModel class.</summary>
        /// <param name="endpoint">EndPoint to connect to.</param>
        public MatchViewModel(IPEndPoint endpoint)
        {
            var matchService = ServiceLocator.MatchService;

            // realm
            Entities = new ObservableCollection<object>();
            Realm = new Realm(new IRealmBehavior[] {
                new UpdatePlayerPositionRealmBehavior(),
                new UpdateBallPositionRealmBehavior(),
                new UpdateBulletPositionRealmBehavior()
            });

            // Commands
            KeyPressCommand = new KeyPressCommand(matchService);
            MouseMoveCommand = new MouseMoveCommand(matchService);
            MouseLeftButtonDownCommand = new MouseLeftButtonDownCommand(matchService);
            MouseRightButtonDownCommand = new MouseRightButtonDownCommand(matchService);
            ConnectCommand = new ConnectCommand(matchService, endpoint);

            // Behaviors
            ConnectionStateChangedBehavior = new ConnectionStateChangedBehavior(this);
            EntityModelStateChangedBehavior = new EntityModelStateChangedBehavior(this);
            EntityViewModelStateChangedBehavior = new EntityViewModelStateChangedBehavior(this);
            CameraFollowBehavior = new CameraFollowBehavior(this);
            UpdateRealmBehavior = new UpdateRealmBehavior(this);

            // MatchService events
            matchService.ConnectionStateChanged += (s, e) => ConnectionStateChangedBehavior.Handle(e.ConnectionState);
            matchService.EntityStateChanged += (s, e) => EntityModelStateChangedBehavior.Handle(e.Entity, e.EntityState);
            Entities.CollectionChanged += (s, e) => { lock (Realm) { EntityViewModelStateChangedBehavior.Handle(e); } };
            CompositionTarget.Rendering += (s, e) => { lock (Realm) { UpdateRealmBehavior.Handle(); } };
            CompositionTarget.Rendering += (s, e) => CameraFollowBehavior.Handle(matchService.GetMyPlayer());
        }
Example #2
0
 public InputHandler()
 {
     mouseLeftButtonDown  = new MouseLeftButtonDownCommand();
     mouseRightButtonDown = new MouseRightButtonDownCommand();
     buttonO = new ButtonOCommand();
     button1 = new Button1Command();
     button2 = new Button2Command();
     button3 = new Button3Command();
     button4 = new Button4Command();
     buttonN = new NextTurnCommand();
 }