public override Image ToImg(int cellSize = 50, float insetPrc = 0.0f) { cellSize = cellSize / 2; var aSize = cellSize / 2.0; var bSize = cellSize / Math.Sqrt(2); var octSize = cellSize + bSize * 2; var imgWidth = (int)(octSize + (cellSize + bSize) * (Columns - 1)); var imgHeight = (int)(octSize + (cellSize + bSize) * (Rows - 1)); var img = new Bitmap(imgWidth + 1, imgHeight + 1); using (var g = Graphics.FromImage(img)) { g.Clear(Color.Transparent); foreach (var mode in new[] { DrawMode.Background, DrawMode.Walls, DrawMode.Path, }) { foreach (var cell in Cells.Cast <CartesianCell>()) { var cx = bSize + aSize + (bSize + cellSize) * cell.Column; var cy = bSize + aSize + (bSize + cellSize) * cell.Row; if (mode == DrawMode.Background) { var color = BackgroundColorFor(cell); if (color != null) { var octagonCell = cell as OctagonCell; if (octagonCell != null) { FillOctagon(g, cx, cy, aSize, bSize, color); } else { FillSquare(g, cx, cy, aSize, color); } } } else if (mode == DrawMode.Walls) { var octagonCell = cell as OctagonCell; if (octagonCell != null) { DrawOctagon(g, octagonCell, cx, cy, aSize, bSize); } else { DrawSquare(g, cell, cx, cy, aSize); } } else if (mode == DrawMode.Path) { DrawPath(cell, g, cellSize); } } } } return(img); }
private void ConfigureCells() { foreach (var cell in Cells.Cast <OverCell>()) { var row = cell.Row; var col = cell.Column; cell.North = (OverCell)this[row - 1, col]; cell.South = (OverCell)this[row + 1, col]; cell.West = (OverCell)this[row, col - 1]; cell.East = (OverCell)this[row, col + 1]; } }
private void ConfigureCells() { foreach (var cell in Cells.Cast <CartesianCell>()) { var row = cell.Row; var column = cell.Column; cell.North = (CartesianCell)this[row - 1, column]; cell.South = (CartesianCell)this[row + 1, column]; cell.West = (CartesianCell)this[row, column - 1]; cell.East = (CartesianCell)this[row, column + 1]; var octagonCell = cell as OctagonCell; if (octagonCell != null) { octagonCell.NorthWest = (CartesianCell)this[row - 1, column - 1]; octagonCell.NorthEast = (CartesianCell)this[row - 1, column + 1]; octagonCell.SouthWest = (CartesianCell)this[row + 1, column - 1]; octagonCell.SouthEast = (CartesianCell)this[row + 1, column + 1]; } } }
public MaskedGrid(Mask mask) : base(mask.Rows, mask.Columns) { Mask = mask; Mask.UnlinkMaskedCells(Mask, Cells.Cast <CartesianCell>()); }
public IEnumerable <Cell> ComputeWrongFlaggedMines() { return(Cells.Cast <Cell>().Where(x => x.CellType == CellType.EmptyCell && x.CellState == CellState.FlaggedAsMine)); }
public IEnumerable <Cell> ComputeUntouchedMines() { return(Cells.Cast <Cell>().Where(x => x.CellType == CellType.Mine && x.CellState == CellState.Untouched)); }
public IEnumerable <Cell> ComputeDefusedMines() { return(Cells.Cast <Cell>().Where(x => x.CellType == CellType.Mine && x.CellState == CellState.FlaggedAsMine)); }
private bool IsMineExploded() { return(Cells.Cast <Cell>().Where(x => x.CellType == CellType.Mine).Any(x => x.CellState != CellState.Untouched && x.CellState != CellState.FlaggedAsMine)); }
private bool IsEndGame() { return(Cells.Cast <Cell>().Where(x => x.CellType == CellType.EmptyCell).All(x => x.CellState == CellState.Opened)); }
public IValidationResult ValidateGrid() { return(validator.Validate(Cells.Cast <ICell>())); }
public IEnumerable <ICell> GetColumnAtIndex(int index) { return(Cells.Cast <ICell>().Where(x => x.Point.Y == index)); }
public override Image ToImg(int cellSize = 50, float insetPrc = 0.0f) { var imgSize = 2 * Rows * cellSize; var center = imgSize / 2; var img = new Bitmap(imgSize + 1, imgSize + 1); using (var g = Graphics.FromImage(img)) { g.Clear(Color.White); foreach (var mode in new[] { DrawMode.Background, DrawMode.Walls, DrawMode.Path, }) { foreach (var cell in Cells.Cast <PolarCell>()) { var theta = 2 * Math.PI / _grid[cell.Row].Count; var innerRadius = cell.Row * cellSize; var outerRadius = (cell.Row + 1) * cellSize; var thetaCCW = cell.Column * theta; var thetaCW = (cell.Column + 1) * theta; var ax = center + (float)(innerRadius * Math.Cos(thetaCCW)); var ay = center + (float)(innerRadius * Math.Sin(thetaCCW)); var bx = center + (float)(outerRadius * Math.Cos(thetaCCW)); var by = center + (float)(outerRadius * Math.Sin(thetaCCW)); var cx = center + (float)(innerRadius * Math.Cos(thetaCW)); var cy = center + (float)(innerRadius * Math.Sin(thetaCW)); var dx = center + (float)(outerRadius * Math.Cos(thetaCW)); var dy = center + (float)(outerRadius * Math.Sin(thetaCW)); var thetaCCWDegrees = (float)(thetaCCW * 180 / Math.PI); var thetaCWDegrees = (float)(thetaCW * 180 / Math.PI); var sweep = (float)(theta * 180 / Math.PI); if (mode == DrawMode.Walls) { if (cell == ActiveCell) { if (cell.Inward == null) { g.FillEllipse(Brushes.GreenYellow, center - outerRadius, center - outerRadius, outerRadius * 2, outerRadius * 2); } else { using (var path = new GraphicsPath()) { path.AddLine(cx, cy, dx, dy); //path.AddLine(dx, dy, bx, by); path.AddArc(center - outerRadius, center - outerRadius, outerRadius * 2, outerRadius * 2, thetaCWDegrees, -sweep); path.AddLine(ax, ay, bx, by); //path.AddLine(ax, ay, cx, cy); path.AddArc(center - innerRadius, center - innerRadius, innerRadius * 2, innerRadius * 2, thetaCCWDegrees, sweep); path.CloseFigure(); g.FillPath(Brushes.GreenYellow, path); } } } if (cell.Row != 0) { if (!cell.IsLinked(cell.Inward)) { //g.DrawLine(Pens.Black, ax, ay, cx, cy); g.DrawArc(Pens.Black, center - innerRadius, center - innerRadius, innerRadius * 2, innerRadius * 2, thetaCCWDegrees, sweep); } if (!cell.IsLinked(cell.Clockwise)) { g.DrawLine(Pens.Black, cx, cy, dx, dy); } } } else if (mode == DrawMode.Background) { var color = BackgroundColorFor(cell); if (color != null) { using (var path = new GraphicsPath()) { if (cell.Inward == null) { g.FillEllipse(new SolidBrush(color.GetValueOrDefault()), center - outerRadius, center - outerRadius, outerRadius * 2, outerRadius * 2); } else { path.AddLine(cx, cy, dx, dy); //path.AddLine(dx, dy, bx, by); path.AddArc(center - outerRadius, center - outerRadius, outerRadius * 2, outerRadius * 2, thetaCWDegrees, -sweep); path.AddLine(ax, ay, bx, by); //path.AddLine(ax, ay, cx, cy); path.AddArc(center - innerRadius, center - innerRadius, innerRadius * 2, innerRadius * 2, thetaCCWDegrees, sweep); path.CloseFigure(); g.FillPath(new SolidBrush(color.GetValueOrDefault()), path); g.DrawPath(new Pen(color.GetValueOrDefault()), path); } } } } else if (mode == DrawMode.Path) { DrawPath(cell, g, cellSize); } } g.DrawEllipse(Pens.Black, center - Rows * cellSize, center - Rows * cellSize, Rows * cellSize * 2, Rows * cellSize * 2); } } return(img); }
public override Image ToImg(int cellSize = 50, float insetPrc = 0.0f) { var halfWidth = cellSize / 2.0; var height = cellSize * Math.Sqrt(3) / 2; var halfHeight = height / 2.0; var imgWidth = (int)(cellSize * (Columns + 1) / 2.0) + 1; var imgHeight = (int)(height * Rows) + 1; var img = new Bitmap(imgWidth, imgHeight); using (var g = Graphics.FromImage(img)) { g.Clear(Color.Transparent); foreach (var mode in new[] { DrawMode.Background, DrawMode.Walls, DrawMode.Path }) { foreach (var cell in Cells.Cast <TriangleCell>()) { var cx = halfWidth + cell.Column * halfWidth; var cy = halfHeight + cell.Row * height; var westX = (int)(cx - halfWidth); var midX = (int)cx; var eastX = (int)(cx + halfWidth); var apexY = cell.Upright ? (int)(cy - halfHeight) : (int)(cy + halfHeight); var baseY = cell.Upright ? (int)(cy + halfHeight) : (int)(cy - halfHeight); if (mode == DrawMode.Background) { var color = BackgroundColorFor(cell); if (color != null) { g.FillPolygon(new SolidBrush(color.GetValueOrDefault()), new [] { new Point(westX, baseY), new Point(midX, apexY), new Point(eastX, baseY) }); } } else if (mode == DrawMode.Walls) { if (cell.West == null) { g.DrawLine(Pens.Black, westX, baseY, midX, apexY); } if (!cell.IsLinked(cell.East)) { g.DrawLine(Pens.Black, eastX, baseY, midX, apexY); } var noSouth = cell.Upright && cell.South == null; var notLinked = !cell.Upright && !cell.IsLinked(cell.North); if (noSouth || notLinked) { g.DrawLine(Pens.Black, eastX, baseY, westX, baseY); } if (cell == ActiveCell) { g.FillPolygon(Brushes.GreenYellow, new[] { new Point(westX, baseY), new Point(midX, apexY), new Point(eastX, baseY) }); } } else if (mode == DrawMode.Path) { DrawPath(cell, g, cellSize); } } } } return(img); }
public override Image ToImg(int cellSize = 50, float insetPrc = 0.0f) { var size = cellSize / 2; var aSize = size / 2.0; var bSize = size * Math.Sqrt(3) / 2.0; var width = size * 2; var height = bSize * 2; var imgWidth = (int)(3 * aSize * Columns + aSize + 0.5); var imgHeight = (int)(height * Rows + bSize + 0.5); var img = new Bitmap(imgWidth + 1, imgHeight + 1); using (var g = Graphics.FromImage(img)) { g.Clear(Color.Transparent); foreach (var mode in new[] { DrawMode.Background, DrawMode.Walls, DrawMode.Path, }) { foreach (var cell in Cells.Cast <HexCell>()) { var cx = size + 3 * cell.Column * aSize; var cy = bSize + cell.Row * height; if (cell.Column % 2 == 1) { cy += bSize; } var xFW = (int)(cx - size); var xNW = (int)(cx - aSize); var xNE = (int)(cx + aSize); var xFE = (int)(cx + size); var yN = (int)(cy - bSize); var yM = (int)cy; var yS = (int)(cy + bSize); if (mode == DrawMode.Background) { var color = BackgroundColorFor(cell); if (color != null) { g.FillPolygon(new SolidBrush(color.GetValueOrDefault()), new[] { new Point(xFW, yM), new Point(xNW, yN), new Point(xNE, yN), new Point(xFE, yM), new Point(xNE, yS), new Point(xNW, yS), }); } } else if (mode == DrawMode.Walls) { if (cell == ActiveCell) { g.FillPolygon( new SolidBrush(Color.GreenYellow), new[] { new Point(xFW, yM), new Point(xNW, yN), new Point(xNE, yN), new Point(xFE, yM), new Point(xNE, yS), new Point(xNW, yS), }); } if (cell.SouthWest == null) { g.DrawLine(Pens.Black, xFW, yM, xNW, yS); } if (cell.NorthWest == null) { g.DrawLine(Pens.Black, xFW, yM, xNW, yN); } if (cell.North == null) { g.DrawLine(Pens.Black, xNW, yN, xNE, yN); } if (!cell.IsLinked(cell.NorthEast)) { g.DrawLine(Pens.Black, xNE, yN, xFE, yM); } if (!cell.IsLinked(cell.SouthEast)) { g.DrawLine(Pens.Black, xFE, yM, xNE, yS); } if (!cell.IsLinked(cell.South)) { g.DrawLine(Pens.Black, xNE, yS, xNW, yS); } } else if (mode == DrawMode.Path) { DrawPath(cell, g, cellSize); } } } } return(img); }
public IEnumerable <T> SelectIf <T>() { return(Cells.Cast <IBaseCell>().Where(cell => cell is T).Cast <T>()); }