Beispiel #1
0
        private async void Loop()
        {
            await Task.Run(() =>
            {
                while (_continue)
                {
                    try
                    {
                        using (NamedPipeServerStream pipe = new NamedPipeServerStream("ping/tir763", PipeDirection.InOut))
                        {
                            pipe.WaitForConnection();
                            using (StreamReader sr = new StreamReader(pipe))
                            {
                                string line = sr.ReadLine();
                                if (line != null)
                                {
                                    string[] tab  = line.Split(';');
                                    Point pt      = new Point();
                                    bool change   = false;
                                    bool fireBall = false;
                                    foreach (string item in tab)
                                    {
                                        string[] tab1 = item.Split('=');
                                        if (tab1[1] != "None")
                                        {
                                            double value = double.Parse(tab1[1].Replace('.', ','));
                                            switch (tab1[0])
                                            {
                                            case "speed":
                                                BallSpeed = value;
                                                break;

                                            case "bAngle":
                                                BallisticAngle = value;
                                                break;

                                            case "dAngle":
                                                Angle = value;
                                                break;

                                            case "rotationX":
                                                XRotation = value;
                                                break;

                                            case "rotationY":
                                                YRotation = value;
                                                break;

                                            case "rotationZ":
                                                ZRotation = value;
                                                break;

                                            case "x":
                                                pt.X   = value;
                                                change = true;
                                                break;

                                            case "y":
                                                pt.Y   = -value;
                                                change = true;
                                                break;

                                            case "fire":
                                                if (value == 1)
                                                {
                                                    fireBall = true;
                                                }
                                                break;
                                            }
                                        }
                                    }
                                    if (change)
                                    {
                                        MainWindow.DipThread?.Invoke(() => BallPos = pt + (Center - new Point()) - new Vector(ballSize, ballSize));
                                    }
                                    if (fireBall)
                                    {
                                        MainWindow.DipThread?.Invoke(() => FireBall?.Execute(null), System.Windows.Threading.DispatcherPriority.Send);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            });
        }