/// <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()); }
/// <summary>Initializes a new instance of the MatchService class.</summary> public MatchService() { _service.UserConnectionStateChanged += OnUserConnectionStateChanged; _service.PacketReceived += OnPacketReceived; _realm = new Realm(new IRealmBehavior[] { new LoadMapRealmBehavior(), new EnterLeaveRealmBehavior(), new PlayerControlRealmBehavior(), new PlayerKickBallControlRealmBehavior(), new PlayerFireControlRealmBehavior(), new PhysicsRealmBehavior(), new BallInGateRealmBehavior(), new SyncEntitiesRealmBehavior(_service) }); }