Пример #1
0
        private IEnumerable <T> ReturnAround <T>(Point p, Func <Point, T> func)
        {
            Point aroundPoint = new Point(0, 0);

            for (aroundPoint.Y = p.Y - 1; aroundPoint.Y < p.Y + 2; aroundPoint.Y++)
            {
                for (aroundPoint.X = p.X - 1; aroundPoint.X < p.X + 2; aroundPoint.X++)
                {
                    if (InMat(aroundPoint))
                    {
                        if (!p.Equals(aroundPoint))
                        {
                            yield return(func(aroundPoint));
                        }
                    }
                }
            }
        }
Пример #2
0
        private void DoAround(Point p, Action <Point> action)
        {
            Point aroundPoint = new Point(0, 0);

            for (aroundPoint.Y = p.Y - 1; aroundPoint.Y < p.Y + 2; aroundPoint.Y++)
            {
                for (aroundPoint.X = p.X - 1; aroundPoint.X < p.X + 2; aroundPoint.X++)
                {
                    if (InMat(aroundPoint))
                    {
                        if (!p.Equals(aroundPoint))
                        {
                            action(aroundPoint);
                        }
                    }
                }
            }
        }
Пример #3
0
 private void SetMat(Point firstP)
 {
     for (int i = 0; i < mines; i++)
     {
         Point rndP = new Point(rnd.Next(matWidth), rnd.Next(matHeight));
         if (!HasMine(rndP) && !firstP.Equals(rndP))
         {
             mineMat[rndP.Y, rndP.X] = -1;
             DoAround(rndP, (aroundP) =>
             {
                 if (!HasMine(aroundP))
                 {
                     mineMat[aroundP.Y, aroundP.X]++;
                 }
             }
                      );
         }
         else
         {
             i--;
         }
     }
 }