public bool CanMoveLeft() { //get the min col of the tetromino int minCol = CoveredCells.Min(_ => _.Column); //If any of the covered spaces are currently in the left border, the piece cannot move left. if (minCol == 0) { return(false); } //get all the leftest tetromino's cells var leftestCells = CoveredCells.Where(_ => _.Column == minCol); //For each of the covered spaces, get the space immediately below foreach (var leftestCell in leftestCells) { if (_GameBoard.GetRow(leftestCell.Row).HasCellTaken(leftestCell.Column - 1)) { return(false); } } return(true); }
public bool CanMoveRight() { //get the max col of the tetromino int maxCol = CoveredCells.Max(_ => _.Column); Console.WriteLine("CanMoveRight - maxCol=" + maxCol); //If any of the covered spaces are currently in the right border, the piece cannot move right. if (maxCol == _GameBoard.Cols - 1) { return(false); } //get all the righest tetromino's cells var righestCells = CoveredCells.Where(_ => _.Column == maxCol); //For each of the covered spaces, get the space immediately below foreach (var rightestCell in righestCells) { if (_GameBoard.GetRow(rightestCell.Row).HasCellTaken(rightestCell.Column + 1)) { return(false); } } return(true); }
/// <summary> /// Check whether the tetromino can move down by 1 cell or not /// </summary> /// <returns>true if it can move, false otherwise</returns> public bool CanMoveDown() { //get the min row of the tetromino int minRow = CoveredCells.Min(_ => _.Row); //If any of the covered spaces are currently in the lowest row, the piece cannot move down. Console.WriteLine("CanMoveDown - minRow=" + minRow); if (minRow == 0) { return(false); } //get all the lowest tetromino's cells var lowestCells = CoveredCells.Where(_ => _.Row == minRow); //For each of the covered spaces, get the space immediately below foreach (var lowestCell in lowestCells) { if (_GameBoard.GetRow(lowestCell.Row - 1).HasCellTaken(lowestCell.Column)) { return(false); } } return(true); }
public SampleGridControl() { GridCellNestedGridModel gridModel = new GridCellNestedGridModel(GridNestedAxisLayout.Normal, GridNestedAxisLayout.Normal); GridCellNestedScrollGridModel scrollGridModel = new GridCellNestedScrollGridModel(); GridCellNestedGridModel shareRowLayoutGridModel = new GridCellNestedGridModel(GridNestedAxisLayout.Shared, GridNestedAxisLayout.Normal); GridCellNestedGridModel shareColumnLayoutGridModel = new GridCellNestedGridModel(GridNestedAxisLayout.Normal, GridNestedAxisLayout.Shared); GridCellNestedGridModel gridInRowModel = new GridCellNestedGridModel(GridNestedAxisLayout.Nested, GridNestedAxisLayout.Normal); Model.CellModels.Add("Grid", gridModel); Model.CellModels.Add("ScrollGrid", scrollGridModel); Model.CellModels.Add("ShareRowLayoutGrid", shareRowLayoutGridModel); Model.CellModels.Add("ShareColumnLayoutGrid", shareColumnLayoutGridModel); Model.CellModels.Add("GridInRow", gridInRowModel); #region Sample Setup RowHeights.DefaultLineSize = 20; Model.RowCount = 6000; ColumnWidths.DefaultLineSize = 100; Model.ColumnCount = 20; Random buttonRandom = new Random(23); Random orangePenRandom = new Random(2); Random backBrushRandom = new Random(18); gridLinePen = new Pen(Brushes.DarkGray, 1); gridLinePen.Freeze(); Pen orangePen = new Pen(Brushes.DarkOrange, 5); orangePen.EndLineCap = PenLineCap.Triangle; orangePen.StartLineCap = PenLineCap.Triangle; orangePen.Freeze(); Pen bgPen = new Pen(Brushes.Gold, 6); bgPen.EndLineCap = PenLineCap.Triangle; bgPen.StartLineCap = PenLineCap.Triangle; bgPen.Freeze(); SolidColorBrush bg1 = new SolidColorBrush(Color.FromArgb(128, 128, 0, 0)); SolidColorBrush bg2 = new SolidColorBrush(Color.FromArgb(128, 0, 128, 0)); SolidColorBrush bg3 = new SolidColorBrush(Color.FromArgb(128, 0, 0, 128)); GradientBrush bg = new LinearGradientBrush(Color.FromArgb(128, 255, 255, 0), Color.FromArgb(128, 0, 255, 255), 45.0); //GradientBrush bg = new LinearGradientBrush(Colors.Gray, Colors.White, 45); CellSpanBackgrounds.Add(new CellSpanBackgroundInfo(9, 2, 22, 8, false, false, bg1, bgPen)); CellSpanBackgrounds.Add(new CellSpanBackgroundInfo(3, 4, 28, 6, false, false, bg2, bgPen)); CellSpanBackgrounds.Add(new CellSpanBackgroundInfo(25, 2, 30, 4, false, false, bg3, bgPen)); CellSpanBackgrounds.Add(new CellSpanBackgroundInfo(0, 0, 12, 1, false, false, bg, null)); CoveredCells.Add(new CoveredCellInfo(4, 0, 6, 1)); CoveredCells.Add(new CoveredCellInfo(4, 19, 6, 19)); CoveredCells.Add(new CoveredCellInfo(6, 2, 8, 4)); CoveredCells.Add(new CoveredCellInfo(4, 2, 5, 3)); Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo); for (int n = 0; n < Model.RowCount; n++) { for (int c = 0; c < Model.ColumnCount; c++) { GridStyleInfo ci = new GridStyleInfo(); if (backBrushRandom.Next(10) == 5) { ci.Background = Brushes.Tomato; } if (c == 5)//% 4 == 3)// || c == 5) { ci.CellType = "CheckBox"; ci.Description = String.Format("Check {0}:{1}", n, c); ci.CellValue = n % 2 == 0; } if (c == 2) { ci.CellType = "TextBox"; ci.CellValue = String.Format("Edit {0}:{1}", n, c); } if (buttonRandom.Next(10) == 5) { ci.CellType = "Button"; ci.Description = String.Format("Click {0}:{1}", n, c); ci.Background = null; } if (orangePenRandom.Next(10) == 5) { ci.Borders.Right = orangePen; ci.Borders.Bottom = orangePen; ci.Borders.Left = orangePen; ci.Borders.Top = orangePen; //ci.BorderMargins.Right = orangePen.Thickness / 2; //ci.BorderMargins.Bottom = orangePen.Thickness / 2; //ci.BorderMargins.Top = orangePen.Thickness / 2; //ci.BorderMargins.Left = orangePen.Thickness / 2; } if (!ci.IsEmpty) { //if (n == Model.RowCount - 1 && c == Model.ColCount - 1) // Console.WriteLine("ddd"); Model[n, c].Background = Brushes.Red; Model[n, c] = ci; } } } if (true) { Model[6, 2].CellType = "Grid"; //Model[6, 2].CellRenderer = gridRenderer; Model[6, 2].CellValue = GetSimpleNestedGrid(); } if (true) { CoveredCellInfo coveredCell1 = new CoveredCellInfo(36, 0, 36, Model.ColumnCount - 1); coveredCell1.SpanWholeRow = true; CoveredCells.Add(coveredCell1); Model[36, 0].CellType = "GridInRow"; //Model[36, 0].CellRenderer = gridInRowRenderer; GridModel m = GetSimpleNestedGrid(); Model[36, 0].CellValue = m; //PixelScrollAxis mb = new PixelScrollAxis(new ScrollInfo(), m.RowHeights); RowHeights.SetNestedLines(36, m.RowHeights);//.Distances;//.TotalDistance GridModel m2 = GetSimpleNestedGrid(); m[5, 1].Background = new SolidColorBrush(Colors.LightCoral); m[5, 1].CellValue = m2; m2.ColumnWidths.DefaultLineSize = 65; m[5, 1].CellType = "GridInRow"; //m[5, 1].CellRenderer = gridInRowRenderer; m.RowHeights.SetNestedLines(5, m2.RowHeights); m.CoveredCells.Add(new CoveredCellInfo(5, 1, 5, 6)); } if (true) { Model[40, 2].CellType = "ScrollGrid"; //Model[40, 2].CellRenderer = scrollGridRenderer; Model[40, 2].CellValue = GetScrollNestedGrid(); CoveredCells.Add(new CoveredCellInfo(40, 2, 49, 5)); } if (true) { Model[60, 1].CellType = "ShareColumnLayoutGrid"; //Model[60, 1].CellRenderer = shareColumnLayoutGridRenderer; Model[60, 1].BorderMargins.Top = 0; Model[60, 1].BorderMargins.Left = 0; Model[60, 1].BorderMargins.Right = 0; Model[60, 1].BorderMargins.Bottom = 0; Model[60, 1].Background = SystemColors.InactiveCaptionBrush; GridModel nestedGridWithSharedColumnsModel = GetNestedGridWithSharedColumnsModel(); Model[60, 1].CellValue = nestedGridWithSharedColumnsModel; CoveredCells.Add(new CoveredCellInfo(60, 1, 80, 1 + nestedGridWithSharedColumnsModel.ColumnCount - 1)); } if (true) { Model[100, 2].CellType = "ShareRowLayoutGrid"; //Model[100, 2].CellRenderer = shareRowLayoutGridRenderer; Model[100, 2].BorderMargins.Top = 0; Model[100, 2].BorderMargins.Left = 0; Model[100, 2].BorderMargins.Right = 0; Model[100, 2].BorderMargins.Bottom = 0; Model[100, 2].Background = SystemColors.InactiveCaptionBrush; GridModel nestedGridWithSharedRowsModel = GetNestedGridWithSharedRowsModel(); Model[100, 2].CellValue = nestedGridWithSharedRowsModel; CoveredCells.Add(new CoveredCellInfo(100, 2, 100 + nestedGridWithSharedRowsModel.RowCount - 1, 5)); Random rnd = new Random(120); for (int n = 0; n < 100; n++) { RowHeights[rnd.Next(Model.RowCount)] = rnd.Next(10, 50); } for (int n = 0; n < 5; n++) { ColumnWidths[rnd.Next(Model.ColumnCount)] = rnd.Next(40, 400); } } RowHeights.SetHidden(10, 20, true); FrozenRows = 2; FrozenColumns = 1; FooterColumns = 1; FooterRows = 1; Console.WriteLine(FrozenRows); Console.WriteLine(FrozenColumns); #endregion GridStyleInfo tableStyle = Model.TableStyle; GridStyleInfo headerStyle = Model.HeaderStyle; GridStyleInfo footerStyle = Model.FooterStyle; tableStyle.CellType = "TextBox"; tableStyle.BorderMargins.Top = gridLinePen.Thickness; tableStyle.BorderMargins.Left = gridLinePen.Thickness; tableStyle.BorderMargins.Right = gridLinePen.Thickness / 2; tableStyle.BorderMargins.Bottom = gridLinePen.Thickness / 2; tableStyle.Borders.Right = gridLinePen; tableStyle.Background = null;// Brushes.White; tableStyle.Borders.Bottom = gridLinePen; headerStyle.Background = SystemColors.ControlBrush; headerStyle.CellType = "Static"; footerStyle.Background = Brushes.Wheat; }