private void InitializeGridCheckStructArrayArray(GridCheckStruct[,] checkStruct) { for (int x = 0; x < (int)this.grid.GridSize.X; x++) { for (int y = 0; y < (int)this.grid.GridSize.Y; y++) { checkStruct[x, y].Change = false; checkStruct[x, y].LeftChecked = false; checkStruct[x, y].RightChecked = false; checkStruct[x, y].UpChecked = false; checkStruct[x, y].DownChecked = false; checkStruct[x, y].ID = new Vector2(x, y); } } }
private static void FindFillCells(ref Color changeColor, ref GridCheckStruct[,] checkStruct) { Boolean allChecked = false; while (!allChecked) { allChecked = true; GridCheckStruct[,] holdStruct = checkStruct; foreach (GridCheckStruct index in checkStruct) { if (index.Change && !index.AllChecked) { if ((int)index.ID.X > 0) if (!index.LeftChecked) { allChecked = false; if (FrameManager.ActiveFrame.Grid.Peek().Cells[(int)index.ID.X - 1, (int)index.ID.Y].Color == changeColor) { holdStruct[(int)index.ID.X - 1, (int)index.ID.Y].Change = true; } holdStruct[(int)index.ID.X, (int)index.ID.Y].LeftChecked = true; } if (index.ID.X < FrameManager.ActiveFrame.Grid.Peek().GridSize.X - 1) if (!index.RightChecked) { allChecked = false; if (FrameManager.ActiveFrame.Grid.Peek().Cells[(int)index.ID.X + 1, (int)index.ID.Y].Color == changeColor) { holdStruct[(int)index.ID.X + 1, (int)index.ID.Y].Change = true; } holdStruct[(int)index.ID.X, (int)index.ID.Y].RightChecked = true; } if (index.ID.Y > 0) if (!index.UpChecked) { allChecked = false; if (FrameManager.ActiveFrame.Grid.Peek().Cells[(int)index.ID.X, (int)index.ID.Y - 1].Color == changeColor) { holdStruct[(int)index.ID.X, (int)index.ID.Y - 1].Change = true; } holdStruct[(int)index.ID.X, (int)index.ID.Y].UpChecked = true; } if (index.ID.Y < FrameManager.ActiveFrame.Grid.Peek().GridSize.Y - 1) if (!index.DownChecked) { allChecked = false; if (FrameManager.ActiveFrame.Grid.Peek().Cells[(int)index.ID.X, (int)index.ID.Y + 1].Color == changeColor) { holdStruct[(int)index.ID.X, (int)index.ID.Y + 1].Change = true; } holdStruct[(int)index.ID.X, (int)index.ID.Y].DownChecked = true; } } } checkStruct = holdStruct; } }
private void FillGrid(GridCell gridCell) { Color changeColor = gridCell.Color; GridCheckStruct[,] checkStruct = new GridCheckStruct[(int)FrameManager.ActiveFrame.Grid.Peek().GridSize.X, (int)FrameManager.ActiveFrame.Grid.Peek().GridSize.Y]; InitializeGridCheckStructArrayArray(checkStruct); checkStruct[(int)gridCell.ID.X, (int)gridCell.ID.Y].Change = true; FindFillCells(ref changeColor, ref checkStruct); FillCells(checkStruct); }
private static void FillCells(GridCheckStruct[,] checkStruct) { foreach (GridCheckStruct check in checkStruct) { if (check.Change) { FrameManager.ActiveFrame.Grid.Peek().Cells[(int)check.ID.X, (int)check.ID.Y].Color = Globals.DrawingColor; } } }