/// <summary>
 /// 初始化一个指定大小的PatternGameBoard。元素将会初始化为Nothing
 /// </summary>
 /// <param name="w"></param>
 /// <param name="h"></param>
 public PatternGameBoard(int w, int h) : base(w, h)
 {
     for (int i = 0; i < Height; i++)
     {
         for (int j = 0; j < Width; j++)
         {
             Blocks[i][j] = GameBoardBlock.Nothing;
         }
     }
     BlockRangeChanged?.Invoke(0, 0, Height - 1, Width - 1);
 }
Exemple #2
0
 PlayerViewGameBoard(int w, int h) : base(w, h)
 {
     for (int i = 0; i < Height; i++)
     {
         BlockDetails.Add(new List <string>());
         for (int j = 0; j < Width; j++)
         {
             BlockDetails[i].Add(null);
             Blocks[i][j] = GameBoardBlock.Unknown;
         }
     }
     BlockRangeChanged?.Invoke(0, 0, Height - 1, Width - 1);
 }
Exemple #3
0
        /// <summary>
        /// 从现有字符串数组加载GameBoard
        /// </summary>
        /// <param name="vs"></param>
        public GameBoard(string[] vs)
        {
            Height = vs.Length;
            Width  = int.MaxValue;
            for (int i = 0; i < Height; i++)
            {
                Width = Math.Min(Width, vs[i].Length);
            }
            Blocks = new List <List <GameBoardBlock> >(Height);
            for (int i = 0; i < Height; i++)
            {
                Blocks.Add(new List <GameBoardBlock>(Width));
                for (int j = 0; j < Width; j++)
                {
                    switch (vs[i][j])
                    {
                    case ' ':
                        Blocks[i].Add(GameBoardBlock.Nothing);
                        break;

                    case '?':
                        Blocks[i].Add(GameBoardBlock.Unknown);
                        break;

                    case '!':
                        Blocks[i].Add(GameBoardBlock.Null);
                        break;

                    default:
                        Blocks[i].Add((GameBoardBlock)vs[i][j]);
                        break;
                    }
                }
            }
            BlockRangeChanged?.Invoke(0, 0, Height - 1, Width - 1);
        }
            /// <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);
            }