Example #1
0
        /// <summary>
        /// Выстреливает по полю противника
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void opponentSquare_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (_isMyTurn)
            {
                if (_stateGame == StateGame.Game)
                {
                    var element = (UIElement)e.Source;
                    int row     = Grid.GetRow(element);
                    int column  = Grid.GetColumn(element);

                    if (row > 0 && column > 0)
                    {
                        if (_seaOpponent.Map[row - 1, column - 1].State == FieldState.Sea)
                        {
                            XYCoordinate position = new XYCoordinate()
                            {
                                X = column - 1, Y = row - 1
                            };
                            Shot shot = new Shot()
                            {
                                XyCoordinate = position
                            };
                            ClientManager.Instance.Client.DoShot(shot);
                        }
                    }
                }
            }
        }
Example #2
0
        public void ValidTestXYZero()
        {
            int XCoord = 0;
            int YCoord = 0;

            XYCoordinate coords = new XYCoordinate(XCoord, YCoord);

            Assert.AreEqual(XCoord, coords.X);
            Assert.AreEqual(YCoord, coords.Y);
        }
Example #3
0
        public void ValidTestXYProperties()
        {
            int XCoord = 5;
            int YCoord = 2;

            XYCoordinate coords = new XYCoordinate(XCoord, YCoord);

            Assert.AreEqual(XCoord, coords.X);
            Assert.AreEqual(YCoord, coords.Y);
        }
Example #4
0
 private Triangle CreateTriangle(XYCoordinate Vertex1, XYCoordinate Vertex2, XYCoordinate Vertex3)
 {
     return(new Triangle(
                new List <XYCoordinate>()
     {
         Vertex1,
         Vertex2,
         Vertex3
     }
                ));
 }
Example #5
0
        public void InvalidTestNegativeY()
        {
            int XCoord = 5;
            int YCoord = -1;

            XYCoordinate coords;

            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
                                                                 coords = new XYCoordinate(XCoord, YCoord)
                                                                 );
        }
        public void InvalidTestWithTwoVertices()
        {
            XYCoordinate Vertex1 = new XYCoordinate(1, 1);
            XYCoordinate Vertex2 = new XYCoordinate(1, 2);

            Triangle triangle;

            Assert.ThrowsException <ArgumentException>(() =>
                                                       triangle = new Triangle(
                                                           new List <XYCoordinate>()
            {
                Vertex1,
                Vertex2
            }
                                                           )
                                                       );
        }
        public void ValidTestTriangleVertices()
        {
            XYCoordinate Vertex1 = new XYCoordinate(1, 1);
            XYCoordinate Vertex2 = new XYCoordinate(1, 2);
            XYCoordinate Vertex3 = new XYCoordinate(2, 1);

            Triangle triangle = new Triangle(
                new List <XYCoordinate>()
            {
                Vertex1,
                Vertex2,
                Vertex3
            }
                );

            Assert.AreEqual("Triangle", triangle.Name);
            Assert.AreEqual(3, triangle.Vertices.Count);
            Assert.IsTrue(XYCoordinateTestHelper.TestXYCoordinateValues(Vertex1, triangle.Vertices[0]));
            Assert.IsTrue(XYCoordinateTestHelper.TestXYCoordinateValues(Vertex2, triangle.Vertices[1]));
            Assert.IsTrue(XYCoordinateTestHelper.TestXYCoordinateValues(Vertex3, triangle.Vertices[2]));
        }
        /// <summary>
        /// Return a list of X/Y coordinates from a string which contains the point as string format.
        /// </summary>
        /// <param name="PointsShapeCoordinate">X/Y coordinate as string format.</param>
        /// <returns>Return a list of X/Y coordinates from the PointsShapeCoordinate string property.</returns>
        public static List <XYCoordinate> PointsShapeCoordinateToList(string PointsShapeCoordinate)
        {
            List <XYCoordinate> Points = new List <XYCoordinate>();

            if (PointsShapeCoordinate != null)
            {
                string[] pointsTab = PointsShapeCoordinate.Split(",".ToCharArray());
                foreach (string coordinate in pointsTab)
                {
                    string[]     pointXY = coordinate.Split("/".ToCharArray());
                    XYCoordinate xy      = new XYCoordinate();

                    try
                    {
                        xy.X = Convert.ToDouble(pointXY[0]);
                        xy.Y = Convert.ToDouble(pointXY[1]);
                    }
                    catch (FormatException e)
                    {
                        Debug.WriteLine("FormatException: " + e.ToString());
                    }
                    catch (NullReferenceException e)
                    {
                        Debug.WriteLine("NullReferenceException: " + e.ToString());
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine("Exception: " + e.ToString());
                    }
                    finally
                    {
                        Points.Add(xy);
                    }
                }
            }

            return(Points);
        }
Example #9
0
        public void ProcessReceive()
        {
            LogFiler.Log(Category.Info, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": started receiving data.");

            try
            {
                while (!IsStopped)
                {
                    var watch = new System.Diagnostics.Stopwatch();
                    watch.Start();
                    Task <byte[]> receive = TReceive();
                    ScannerDecode Info    = new ScannerDecode().Decode(receive.Result);

                    if (Info.ID == 1)
                    {
                        RefreshScanner(Info);
                        Tuple <float, float> angleinfo = ScannerFunctionality.GetAngleId1(receive.Result);
                        Degree          = angleinfo.Item1;
                        AngleDifference = angleinfo.Item2;
                    }
                    else if (Info.ID == 6)
                    {
                        if (BlockOrderCorrect(Info.Block))
                        {
                            ExpandScanner(Info, receive.Result);

                            // if the id6 telegramblocks are finished - split the distance based on the scannergap information (not visible area)
                            // if its not getting split, the averaging will create datapoints where the scanner couldnt be able to see at all - leads to consequential errors
                            if (Id6Complete())
                            {
                                Distance = ScannerFunc.GetProcessedDistance(Id6Distance.ToList());

                                if (Mainframe.IsNormalizedbyMedian[Tag])
                                {
                                    Distance = ScannerFunc.GetMedianAverageArray(Distance.ToList());
                                }

                                XYCoord = ScannerFunc.GetXYCoordinate(Distance.ToList(), this);

                                XYCoordinate = ScannerFunctionality.MergeXYArray(XYCoord.ToList());
                                OnScannerRaw(this, XYCoordinate.ToList());

                                List <List <Tuple <int, int, int> > > Normalizer = new List <List <Tuple <int, int, int> > >();
                                List <Tuple <int, int, int> >         Normalized = new List <Tuple <int, int, int> >();

                                // try to accomplish the necessary kinds of averaging the distance sent by the scanner
                                // data averaged by time
                                if (Mainframe.IsNormalizedbyTime[Tag])
                                {
                                    List <Tuple <int, int, int> > xycollection = new List <Tuple <int, int, int> >(XYCoordinate);
                                    XYCollection[RingBufferCount] = xycollection;

                                    List <List <Tuple <int, int, int> > > xycolle = new List <List <Tuple <int, int, int> > >(XYCoord);
                                    XYColl[RingBufferCount] = xycolle;

                                    RingBufferCount++;
                                    CountTimeAverage++;

                                    if (RingBufferCount == Mainframe.NormalizebyTimeCountStoredData[Tag])
                                    {
                                        RingBufferCount = 0;
                                    }

                                    if (CountTimeAverage == Mainframe.NormalizebyTimeCountDataAverage[Tag])
                                    {
                                        Normalizer       = ScannerFunc.NormalizationByTime(RingBufferCount, XYColl);
                                        CountTimeAverage = 0;
                                    }
                                }
                                else
                                {
                                    Normalizer = XYCoord;
                                }

                                if (Normalizer.Count != 0)
                                {
                                    if (Mainframe.IsNormalizedbyTriangle[Tag])
                                    {
                                        Normalizer = ScannerFunc.Normalization(Normalizer.ToList());
                                    }

                                    Normalized = ScannerFunctionality.MergeNormalizeArray(Normalizer.ToList());

                                    Normalized = ScannerFunc.ChangePositionOfXY(Normalized.ToList());

                                    NormalizedData = Normalized;
                                    OnScannerNormalized(this, new List <Tuple <int, int, int> >(NormalizedData));

                                    List <Tuple <int, int, int> > Analyser = new List <Tuple <int, int, int> >(Normalized);
                                    AnalyseData = Analyser;
                                }

                                if (watch.IsRunning)
                                {
                                    watch.Stop();
                                    LogFiler.Log(Category.Info, "normalise" + watch.ElapsedMilliseconds.ToString());
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogFiler.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
        }
Example #10
0
        private void DetermineAllCoordinates()
        {
            Coordinates = new XYCoordinate
            {
                X = VisShape.Cells["PinX"].Result["inches"],
                Y = VisShape.Cells["PinY"].Result["inches"],
            };

            Height = VisShape.Cells["Height"].Result["inches"];
            Width = VisShape.Cells["Width"].Result["inches"];
            PageHeight = VisShape.ContainingPage.Document.PaperHeight["inches"];
          
            if ((ShapeCategory != ShapeTypeCategory.Connector))
            {
                double extra = (ShapeCategory == ShapeTypeCategory.Activity) ? -1 : 0;
                
                double activityVisY = PageHeight - (Coordinates.Y + (Height / 2));

                double activityVisX = (Coordinates.X - (Width/2));
                              
                TopLeft = new XYCoordinate {
                                               X = activityVisX,
                                               Y = activityVisY
                                           };
            }
        }
 public static bool TestXYCoordinateValues(XYCoordinate expected, XYCoordinate actual)
 {
     return(expected.X == actual.X &&
            expected.Y == actual.Y);
 }
Example #12
0
 private double CalcDistance(XYCoordinate source, XYCoordinate destination)
 {
     double xdif=Math.Abs(source.X - destination.X);
     double ydif=Math.Abs(source.Y - destination.Y);
     return Math.Ceiling(Math.Sqrt(Math.Pow(xdif, 2) + Math.Pow(ydif, 2)));
 }