Beispiel #1
0
        public NetSharedSecretExchange(NetworkLevel2Connection networkmodelconnection, bool isserver)
        {
            //LogFile.WriteLine("NetSharedSecretExchange()");
            this.parent   = networkmodelconnection;
            this.isserver = isserver;

            parent.RegisterUnsafePacketHandler('R', new PacketHandler(RPacketHandler));
            parent.RegisterUnsafePacketHandler('C', new PacketHandler(CPacketHandler));
            // parent.RegisterUnsafePacketHandler('D', new PacketHandler(DPacketHandler));

            if (rand == null)
            {
                rand = new MyRand((int)System.DateTime.Now.Ticks);
            }

            lastRpacket = new DateTime();

            if (isserver)
            {
                SharedSecretKey = GenerateSharedKey();
            }
            else
            {
                tempclientkey = rand.GetRandomInt(0, int.MaxValue - 1);
                //SendRPacketToServer();
            }
        }
 void SetRandomMatrix(Point[,] PointMatrix, int CountSwap)
 {
     for (int i = 0; i < CountSwap; i++)
     {
         int   indexI1 = MyRand.Next(0, 9), indexJ1 = MyRand.Next(0, 9);
         int   indexI2 = MyRand.Next(0, 9), indexJ2 = MyRand.Next(0, 9);
         Point TimePoint = PointMatrix[indexI2, indexJ2];
         PointMatrix[indexI2, indexJ2] = PointMatrix[indexI1, indexJ1];
         PointMatrix[indexI1, indexJ1] = TimePoint;
     }
 }
        void SetIconOfKill(List <Point> ship, Button[,] buttonsField)
        {
            foreach (Point x in ship)
            {
                buttonsField[x.X, x.Y].Content = new Image {
                    Source = new BitmapImage(new Uri("pack://application:,,,/Icons/KilledIcon.ico"))
                }
            }
            ;
        }

        void PushInStackFreeCells(int i, int j, Stack <Point> points)
        {
            List <Point> listForRandPoints = new List <Point>();
            Point        timePoint;

            try { if (ShipsFieldMatrixLeft[i - 1, j] != -1)
                  {
                      listForRandPoints.Add(new Point(i - 1, j));
                  }
            } catch { }
            try { if (ShipsFieldMatrixLeft[i + 1, j] != -1)
                  {
                      listForRandPoints.Add(new Point(i + 1, j));
                  }
            } catch { }
            try { if (ShipsFieldMatrixLeft[i, j - 1] != -1)
                  {
                      listForRandPoints.Add(new Point(i, j - 1));
                  }
            } catch { }
            try { if (ShipsFieldMatrixLeft[i, j + 1] != -1)
                  {
                      listForRandPoints.Add(new Point(i, j + 1));
                  }
            } catch { }

            for (int i1 = 0; i1 < 10; i1++)
            {
                int   FirstElemIndex = MyRand.Next(0, listForRandPoints.Count), SecondElemIndex = MyRand.Next(0, listForRandPoints.Count);
                Point FirstElem = listForRandPoints.ElementAt(FirstElemIndex), SecondElem = listForRandPoints.ElementAt(SecondElemIndex);

                timePoint = FirstElem;
                listForRandPoints[FirstElemIndex]  = listForRandPoints[SecondElemIndex];
                listForRandPoints[SecondElemIndex] = FirstElem;
            }
            foreach (Point x in listForRandPoints)
            {
                points.Push(x);
            }
        }
Beispiel #4
0
        public static DateTime RandomAdultBirthDate(int min = 18, int max = 67, int ageOfAdult = 18)
        {
            if (ageOfAdult <= 14)
            {
                ageOfAdult = 18;
            }

            if (min < ageOfAdult)
            {
                min = ageOfAdult;
            }
            if (max > 67)
            {
                max = 67;
            }
            return(DateTime.UtcNow.AddYears(-1 * MyRand.Next(min, max)).AddDays(RandomInteger(1, 360)));
        }
Beispiel #5
0
 public static IFigure Create()
 {
     return(new Rectangle(MyRand.Float(1, 10), MyRand.Float(1, 10)));
 }
 Color GetColor()
 {
     return(Color.FromRgb((byte)MyRand.Next(0, 255), (byte)MyRand.Next(0, 255), (byte)MyRand.Next(0, 255)));
 }