Пример #1
0
 bool CheckSurroundings(int x, int y, CornorMode mode)
 {
     if (!NothingIn(x, y))
     {
         return(false);
     }
     if ((mode & CornorMode.NoEdge) == CornorMode.NoEdge)
     {
         if (!(NothingIn(x + 1, y) && NothingIn(x - 1, y) && NothingIn(x, y + 1) && NothingIn(x, y - 1)))
         {
             return(false);
         }
     }
     if ((mode & CornorMode.NoCornor) == CornorMode.NoCornor)
     {
         if (!(NothingIn(x + 1, y + 1) && NothingIn(x - 1, y + 1) && NothingIn(x + 1, y - 1) && NothingIn(x - 1, y - 1)))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #2
0
            /// <summary>
            /// 尝试在给定坐标处放置单位
            /// </summary>
            /// <param name="pattern"></param>
            /// <param name="x"></param>
            /// <param name="y"></param>
            /// <param name="cornor"></param>
            /// <returns>放置是否成功</returns>
            public bool PutPatern(PatternGameBoard pattern, int x, int y, CornorMode cornor = CornorMode.All)
            {
                if (x > Height || y > Width || x < 0 || y < 0)
                {
                    return(false);
                }
                if (x + pattern.Height > Height || y + pattern.Width > Width)
                {
                    return(false);
                }
                for (int iout = x; iout < x + pattern.Height; iout++)
                {
                    int iin = iout - x;
                    for (int jout = y; jout < y + pattern.Width; jout++)
                    {
                        int jin = jout - y;
                        if (pattern[iin, jin] == GameBoardBlock.ModelBody || pattern[iin, jin] == GameBoardBlock.ModelHead)
                        {
                            if (!CheckSurroundings(iout, jout, cornor))
                            {
                                return(false);
                            }
                        }
                    }
                }
                PlaneCount++;
                HeadCount += pattern.HeadCount;
                char pchar = 'a';

                if (PatternChars.ContainsValue(pattern.Name))
                {
                    foreach (char i in PatternChars.Keys)
                    {
                        if (PatternChars[i] == pattern.Name)
                        {
                            pchar = i;
                            break;
                        }
                    }
                }
                else
                {
                    pchar = NewPatternChar;
                    PatternChars.Add(pchar, pattern.Name);
                    NewPatternChar++;
                }
                for (int iout = x; iout < x + pattern.Height; iout++)
                {
                    int iin = iout - x;
                    for (int jout = y; jout < y + pattern.Width; jout++)
                    {
                        int jin = jout - y;
                        if (pattern[iin, jin] == GameBoardBlock.ModelBody)
                        {
                            this[iout, jout] = (GameBoardBlock)pchar;
                        }
                        if (pattern[iin, jin] == GameBoardBlock.ModelHead)
                        {
                            this[iout, jout] = (GameBoardBlock)char.ToUpper(pchar);
                        }
                    }
                }
                BlockRangeChanged?.Invoke(x, y, x + pattern.Height, y + pattern.Width);
                return(true);
            }