예제 #1
0
파일: Car.cs 프로젝트: malka88/OOP_3
        private void MoveByRoute()
        {
            // последовательный перебор точек маршрута
            foreach (var point in route.getPoints())
            {
                // делегат, возвращающий управление в главный поток
                Application.Current.Dispatcher.Invoke(delegate {
                    // изменение позиции маркера
                    carMarker.Position = point;

                    this.point = point;

                    if (pass != null)
                    {
                        pass.setPosition(point);
                        pass.humanMarker.Position = point;
                    }
                    Follow?.Invoke(this, null);
                });
                // задержка 500 мс
                Thread.Sleep(500);
            }
            if (pass == null)
            {
                Arrived?.Invoke(this, null);
            }
            else
            {
                pass = null;
            }
        }
예제 #2
0
        private void moveByRoute()
        {
            PointLatLng prevPoint = route.getPoints()[0];

            foreach (var point in route.getPoints())
            {
                Application.Current.Dispatcher.Invoke(delegate {
                    carMarker.Position = point;

                    double latDiff = point.Lat - prevPoint.Lat;
                    double lngDiff = point.Lng - prevPoint.Lng;
                    double angle   = Math.Atan2(lngDiff, latDiff) * 180.0 / Math.PI;
                    carMarker.Shape.RenderTransform = new RotateTransform {
                        Angle = angle + 80
                    };

                    this.point = point;
                    if (passengers.Count != 0)
                    {
                        passengers[0].setPoint(point);
                        passengers[0].humanMarker.Position = point;
                    }
                });
                Thread.Sleep(500);
                prevPoint = point;
            }
            Arrived?.Invoke(this, null);
        }
예제 #3
0
파일: Car.cs 프로젝트: Anastasia1005/Lab2_2
 private void MoveByRoute()
 {
     // последовательный перебор точек маршрута
     foreach (var point in route.GetPoints())
     {
         // делегат, возвращающий управление в главный поток
         Application.Current.Dispatcher.Invoke(delegate {
             // изменение позиции маркера
             carMarker.Position = point;
             this.point         = point;
             if (pass != null)
             {
                 pass.setPosition(point);
                 pass.humanMarker.Position = point;
                 Follow?.Invoke(this, null);
             }
         });
         // задержка 500 мс
         Thread.Sleep(500);
     }
     if (pass == null)
     {
         // отправка события о прибытии после достижения последней точки маршрута
         Arrived?.Invoke(this, null);
         //      MessageBox.Show("Пункт назначения.");
     }
     else
     {
         MessageBox.Show("Вы прибыли в пункт назначения.");
         newThread.Abort();
         pass = null;
     }
 }
예제 #4
0
        // WebSocketに接続
        public void Connect()
        {
            var random = new Random();
            var server = WebSocketServers[random.Next(0, WebSocketServers.Length - 1)];

            //クライアント側のWebSocketを定義
            WebSocket = new WebSocket($"wss://{server}:3000/");
            Timer     = new Timer(s => WebSocket.Send("{}"), null, Timeout.Infinite, Timeout.Infinite);

            WebSocket.Opened += (s, e) =>
            {
                WebSocket.Send("{\"time\":0}");
                Debug.WriteLine("Opened");
                Timer.Change(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30));
            };
            WebSocket.MessageReceived += (s, e) =>
            {
                Arrived?.Invoke(JsonConvert.DeserializeObject <Lighitning>(e.Message));
            };
            WebSocket.Closed += (s, e) =>
            {
                Debug.WriteLine("Closed");
                Timer.Change(Timeout.Infinite, Timeout.Infinite);
            };
            WebSocket.Error += (s, e) => Debug.WriteLine("Error");

            WebSocket.Open();
        }
예제 #5
0
        private void MoveByRoute()
        {
            foreach (var Point in route.Points)
            {
                Application.Current.Dispatcher.Invoke(delegate
                {
                    if (marker_car != null)
                    {
                        this.Point          = Point;
                        marker_car.Position = Point;
                    }
                    if (human != null)
                    {
                        human.marker_human.Position = Point;
                        Follow?.Invoke(this, null);
                    }
                });


                Thread.Sleep(500);
            }
            if (human == null)
            {
                Arrived?.Invoke(this, null);
            }
        }
예제 #6
0
        public override MovementOutput GetMovement()
        {
            Vector3 direction = this.Target.position - this.Character.position;

            float distance = direction.magnitude;

            float targetSpeed;

            if (distance < StopRadius)
            {
                Arrived.Add(Character);
                return(new MovementOutput());
            }

            if (distance > SlowRadius)
            {
                targetSpeed = MaxSpeed;
            }
            else
            {
                targetSpeed = MaxSpeed * (distance / SlowRadius);
            }

            MovingTarget.velocity = direction.normalized * targetSpeed;

            var output = base.GetMovement();

            //Debug.DrawRay(this.Character.position, output.linear, Color.blue);
            return(output);
        }
예제 #7
0
        // метод перемещения по маршруту
        private void MoveByRoute()
        {
            double pointss = 100 / route.getLocations().Count;

            foreach (var point in route.getLocations())
            {
                this.location = point;
                Application.Current.Dispatcher.Invoke(delegate
                {
                    this.location   = point;
                    marker.Position = point;
                    gMap.Position   = point;
                    (Application.Current.MainWindow as MainWindow).Progress.Value += pointss + 1;
                    if (pers != null)
                    {
                        pers.setLocation(point);
                        pers.getMarker().Position = point;
                    }
                });
                Thread.Sleep(300);
            }
            // отправка события о прибытии после достижения последней точки маршрута
            if (pers == null)
            {
                Arrived?.Invoke(this, null);
            }
            else
            {
                pers.endOfJourney();
                pers = null;
            }
        }
예제 #8
0
        // метод перемещения по маршруту
        private void MoveByRoute()
        {
            // последовательный перебор точек маршрута
            foreach (var point in route.Points)
            {
                // делегат, возвращающий управление в главный поток
                Application.Current.Dispatcher.Invoke(delegate
                {
                    this.point = point;
                    // изменение позиции маркера
                    marker.Position = point;

                    if (human != null)
                    {
                        human.marker.Position = point;
                        Follow?.Invoke(this, null);
                    }
                });
                // задержка 500 мс
                Thread.Sleep(500);
            }

            if (human == null)
            {
                // отправка события о прибытии после достижения последней точки маршрута
                Arrived?.Invoke(this, null);
            }
            else
            {
                MessageBox.Show("so, here we are!");
                human = null;
                Arrived?.Invoke(this, null);
            }
        }
예제 #9
0
 internal void FireArrived(double ra, double dec, double zoom)
 {
     if (Arrived != null)
     {
         Arrived.Invoke(this, new ArrivedEventArgs(ra, dec, zoom));
     }
 }
예제 #10
0
 private void MoveByRoute()
 {
     try
     {
         foreach (var point in route.Points)
         {
             Application.Current.Dispatcher.Invoke(delegate
             {
                 this.point      = point;
                 marker.Position = point;
                 if (human != null)
                 {
                     human.marker.Position = point;
                     human.point           = point;
                     Follow?.Invoke(this, null);
                 }
             });
             Thread.Sleep(1000);
         }
         if (human == null)
         {
             Arrived?.Invoke(this, null);
         }
         else
         {
             MessageBox.Show("Passenger arrived");
             human = null;
             Arrived?.Invoke(this, null);
         }
     }
     catch { };
 }
예제 #11
0
 private bool Equals(Data other)
 {
     return((ReferenceEquals(Clients, other.Clients) || Clients.SequenceEqual(other.Clients)) &&
            string.Equals(Barrier, other.Barrier) &&
            (ReferenceEquals(Arrived, other.Arrived) || Arrived.SequenceEqual(other.Arrived)) &&
            Equals(Deadline, other.Deadline));
 }
예제 #12
0
        private void MoveByRoute()
        {
            foreach (var point in route.Points)
            {
                Application.Current.Dispatcher.Invoke(delegate
                {
                    this.point      = point;
                    marker.Position = point;

                    if (h != null)
                    {
                        h.marker.Position = point;
                        Follow?.Invoke(this, null);
                    }
                });

                Thread.Sleep(1000);
            }

            if (h == null)
            {
                Arrived?.Invoke(this, null);
            }
            else
            {
                h = null;
                ArrivedToLocate?.Invoke(this, null);
            }
        }
예제 #13
0
 private void Movement()
 {
     foreach (var point in route.GetPoints())
     {
         Application.Current.Dispatcher.Invoke(delegate {
             marker_car.Position = point;
             this.Point          = point;
             if (chel != null)
             {
                 chel.setPosition(point);
                 chel.marker_chelik.Position = point;
                 Follow?.Invoke(this, null);
             }
         });
         Thread.Sleep(1000);
     }
     if (chel == null)
     {
         Arrived?.Invoke(this, null);
     }
     else
     {
         MessageBox.Show("Приехали");
         newThread.Abort();
         chel = null;
     }
 }
예제 #14
0
        private void MoveByRoute()
        {
            lock (lerpPoints)
            {
                double cAngle = 0;

                for (int i = 0; i < lerpPoints.Count; i++)
                {
                    var point = lerpPoints[i];

                    if (Application.Current == null)
                    {
                        _moveThread?.Abort();
                        return;
                    }

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        //if (i < lerpPoints.Count - 10)
                        //{
                        //	var nextPoint = lerpPoints[i + 10];
                        //	double latDiff = nextPoint.Lat - point.Lat;
                        //	double lngDiff = nextPoint.Lng - point.Lng;
                        //	double angle = Math.Atan2(lngDiff, latDiff) * 180.0 / Math.PI - 90.0;

                        //	if (Math.Abs(angle - cAngle) > 11)
                        //	{
                        //		cAngle = angle;
                        //		_carMarker.Shape.RenderTransform = new RotateTransform { Angle = angle/*, CenterX = 20, CenterY = 26.67*/ };
                        //	}
                        //}

                        _point = point;
                        _carMarker.Position = point;
                        if (_passenger.IsSeated)
                        {
                            _passenger.SetPosition(point);
                            _passenger.GetMarker().Position = point;
                        }
                        PositionChanged?.Invoke(this, new CarPositionChangedArgs {
                            Max = lerpPoints.Count, Progress = i
                        });
                    });

                    Thread.Sleep(1);
                }

                if (_moveThread.IsAlive)
                {
                    Application.Current.Dispatcher.Invoke(() => Arrived?.Invoke(this, EventArgs.Empty));
                }

                if (!_passenger.IsSeated)
                {
                    Application.Current.Dispatcher.Invoke(() => PassengerArrived?.Invoke(this, EventArgs.Empty));
                }
            }
        }
예제 #15
0
        private void MoveByRoute()
        {
            double cAngle = 0;

            // последовательный перебор точек маршрута
            for (int i = 0; i < ePoints.Count; i++)
            {
                var point = ePoints[i];
                // делегат, возвращающий управление в главный поток
                Application.Current.Dispatcher.Invoke(delegate {
                    if (i < ePoints.Count - 10)
                    {
                        var nextPoint = ePoints[i + 10];

                        double latDiff = nextPoint.Lat - point.Lat;
                        double lngDiff = nextPoint.Lng - point.Lng;
                        // вычисление угла направления движения
                        // latDiff и lngDiff - катеты прямоугольного треугольника
                        double angle = Math.Atan2(lngDiff, latDiff) * 180.0 / Math.PI;

                        // установка угла поворота маркера

                        if (Math.Abs(angle - cAngle) > 10) //|| (a - angle < 0))
                        {
                            cAngle = angle;
                            carMarker.Shape.RenderTransform = new RotateTransform(angle, 10, 10);
                        }
                    }
                    gMap.Position = carMarker.Position;
                    // изменение позиции маркера
                    carMarker.Position = point;
                    this.point         = point;

                    if (pass != null)
                    {
                        pass.setPosition(point);
                        pass.humanMarker.Position = point;
                        pass.humanMarker.Shape.RenderTransform = new RotateTransform(cAngle, 16, 16);

                        // FollowtheCar?.Invoke(this, null);
                    }
                });
                // задержка 5 мс
                Thread.Sleep(5);
            }
            // отправка события о прибытии после достижения последней точки маршрута
            if (pass == null)
            {
                Arrived?.Invoke(this, null);
            }
            else
            {
                pass = null;

                FollowtheCar?.Invoke(this, null);
                //newThread.Abort();
            }
        }
예제 #16
0
 /// <summary>
 /// Create list and Add Listeners to the events.
 /// </summary>
 private void Start()
 {
     itemManager          = new ItemManager(hands);
     interactionQueue     = new List <NavigationInteraction>();
     interactionQueueText = new Dictionary <NavigationInteraction, GameObject>();
     Interacted.AddListener(PerformInteraction);
     Arrived.AddListener(ArrivedAtInteraction);
     currentPosition = start.position;
 }
예제 #17
0
        private void moveByRoute()
        {
            foreach (var point in route)
            {
                {
                    // вычисление разницы между двумя соседними точками по широте и долготе
                    double latDiff = point.Lat - this.point.Lat;
                    double lngDiff = point.Lng - this.point.Lng;
                    // вычисление угла направления движения
                    //latDiff и lngDiff - катеты прямоугольного треугольника
                    double angle = Math.Atan2(lngDiff, latDiff) * 180.0 / Math.PI;



                    this.point = point;
                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        // установка угла поворота маркера
                        TransformGroup transform = new TransformGroup();
                        transform.Children.Add(new RotateTransform {
                            Angle = angle - 90.0, CenterX = 14, CenterY = 14
                        });
                        transform.Children.Add(new TranslateTransform {
                            X = -14, Y = -14
                        });
                        MainWindow.marker_taxiCar.Shape.RenderTransform = transform;

                        //MainWindow.marker_taxiCar.Shape.RenderTransform = new RotateTransform { Angle = angle - 90.0, CenterX = 14, CenterY = 14 };
                        //MainWindow.marker_taxiCar.Shape.RenderTransform = new TranslateTransform { X = -14, Y = -14 };
                        MainWindow.marker_taxiCar.Position = this.point;
                        MainWindow.map.Position            = this.point;

                        //добавить перемещение пассажиров
                        foreach (Human passenger in passengers)
                        {
                            pos += 1;
                            passenger.moveTo(this.point);
                            MainWindow.marker_taxiClient.Position = passenger.getFocus();
                            Follow?.Invoke(this, EventArgs.Empty);
                        }
                    });
                }
                Thread.Sleep(250);
            }

            if (passengers.Count() > 0)
            {
                MessageBox.Show("Такси приехало в пункт назначения");
            }



            passengers.Clear();
            route.Clear();
            // отправка события о прибытии после достижения последней точки маршрута
            Arrived?.Invoke(this, null);
        }
예제 #18
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (Clients != null ? Clients.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Barrier != null ? Barrier.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Arrived != null ? Arrived.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Deadline != null ? Deadline.GetHashCode() : 0);
         return(hashCode);
     }
 }
예제 #19
0
 public void Run()
 {
     Arrived += (int way) => {
         Console.WriteLine($"{RoadsNames[way]} - приехала машина и теперь там {Roads[way]}");
         if (Roads[0] + Roads[2] > (Roads[1] + Roads[3]) * 2)
         {
             ChangeLight(new int[] { 0, 2 });
         }
         else if (Roads[1] + Roads[3] > (Roads[0] + Roads[2]) * 2)
         {
             ChangeLight(new int[] { 1, 3 });
         }
         else if (TrafficLightStatus[way])
         {
             CrossroadsPermits[way].Set();
         }
     };
     for (int i = 0; i < Roads.Length; i++)
     {
         new Thread((object way) => {
             while (true)
             {
                 Roads[(int)way]++;
                 Arrived?.Invoke((int)way);
                 Monitor.TryEnter(random, -1);
                 int sleepTime = random.Next(200, 1001);
                 Monitor.Exit(random);
                 Thread.Sleep(sleepTime);
             }
         }).Start(i);
         new Thread((object way) => {
             while (true)
             {
                 CrossroadsPermits[(int)way].WaitOne();
                 if (Roads[(int)way] > 0)
                 {
                     Console.WriteLine($"{RoadsNames[(int)way]} - машина едет {GetDirection()}, осталось {--Roads[(int)way]}");
                     Thread.Sleep(300);
                 }
                 else
                 {
                     CrossroadsPermits[(int)way].Reset();
                 }
             }
         }).Start(i);
     }
 }
예제 #20
0
    private void Update()
    {
        transform.Translate(Vector2.left * _speed * Time.deltaTime);

        if (_player.transform.position.x >= gameObject.transform.position.x && !_isArrived)
        {
            Arrived?.Invoke();
            _isArrived = true;
        }

        if (_countdown > 0)
        {
            _countdown -= Time.deltaTime;
        }
        else
        {
            Destroy(gameObject);
        }
    }
예제 #21
0
파일: UnitView.cs 프로젝트: gormel/rts
        protected virtual void OnTriggerEnter(Collider other)
        {
            if (IsClient)
            {
                return;
            }

            if (IsArrived)
            {
                return;
            }

            var pf = other.gameObject.GetComponentInChildren <IPathFinderBase>();

            if (pf != null && pf.IsArrived && other.gameObject.activeSelf && pf.Target == Target)
            {
                mNavMeshAgent.ResetPath();
                Arrived?.Invoke();
                IsArrived = true;
                mWaypointInst.SetActive(false);
            }
        }
예제 #22
0
        public static IEnumerable <ICommand> When(Arrived @event, Transport[] transports)
        {
            yield return(new Return
            {
                Time = @event.Time,
                TransportId = @event.TransportId
            });

            if ([email protected]())
            {
                yield break;
            }

            if (@event.Cargo.First().Destination != @event.Location)
            {
                var availableTransport = transports
                                         .Where(t => t.TransportId != @event.TransportId)
                                         .Where(t => t.Location == @event.Location)
                                         .Where(t => !t.EnRoute)
                                         .Where(t => !t.HasCargo)
                                         .FirstOrDefault();

                if (availableTransport == null)
                {
                    yield break;
                }

                yield return(new PickUp
                {
                    Cargo = new[] { @event.Cargo.First() },
                    Time = @event.Time,
                    TransportId = availableTransport.TransportId
                });
            }

            yield break;
        }
예제 #23
0
파일: UsbHub.cs 프로젝트: tuutuu803/ScpDS3
        public override DsPadId Notify(ScpDevice.Notified Notification, String Class, String Path)
        {
            LogDebug(String.Format("++ Notify [{0}] [{1}] [{2}]", Notification, Class, Path));

            switch (Notification)
            {
            case ScpDevice.Notified.Arrival:
            {
                UsbDevice Arrived = new UsbDevice();

                if (Class.ToUpper() == UsbDs3.USB_CLASS_GUID.ToUpper())
                {
                    Arrived = new UsbDs3(); LogDebug("-- DS3 Arrival Event");
                }

                if (Arrived.Open(Path))
                {
                    LogDebug(String.Format("-- Device Arrival [{0}]", Arrived.Local));

                    if (LogArrival(Arrived))
                    {
                        if (Device[(Byte)Arrived.PadId].IsShutdown)
                        {
                            Device[(Byte)Arrived.PadId].IsShutdown = false;

                            Device[(Byte)Arrived.PadId].Close();
                            Device[(Byte)Arrived.PadId] = Arrived;

                            return(Arrived.PadId);
                        }
                        else
                        {
                            Arrived.Debug  += new EventHandler <DebugEventArgs> (On_Debug);
                            Arrived.Report += new EventHandler <ReportEventArgs>(On_Report);

                            Device[(Byte)Arrived.PadId].Close();
                            Device[(Byte)Arrived.PadId] = Arrived;

                            if (m_Started)
                            {
                                Arrived.Start();
                            }
                            return(Arrived.PadId);
                        }
                    }
                }

                Arrived.Close();
            }
            break;

            case ScpDevice.Notified.Removal:
            {
                for (Int32 Index = 0; Index < Device.Length; Index++)
                {
                    if (Device[Index].State == DsState.Connected && Path == Device[Index].Path)
                    {
                        LogDebug(String.Format("-- Device Removal [{0}]", Device[Index].Local));

                        Device[Index].Stop();
                    }
                }
            }
            break;
            }

            return(DsPadId.None);
        }
예제 #24
0
 /// <summary>
 /// Remove listeners.
 /// </summary>
 private void OnDestroy()
 {
     Interacted.RemoveListener(PerformInteraction);
     Arrived.RemoveListener(ArrivedAtInteraction);
 }