public void DrawRectangle(MatrixLevels level, Rectangle rectangle, char token, bool solid, Color4 fore, Color4 back) { if (!solid) { for (int y = (int)rectangle.Top; y < rectangle.Bottom; y++) { SetToken(level, (int)rectangle.Left, y, token, fore, back); SetToken(level, (int)rectangle.Right - 1, y, token, fore, back); } for (int x = (int)rectangle.Left; x < rectangle.Right; x++) { SetToken(level, x, (int)rectangle.Top, token, fore, back); SetToken(level, x, (int)rectangle.Bottom - 1, token, fore, back); } } else { for (int y = (int)rectangle.Top; y < rectangle.Bottom; y++) { for (int x = (int)rectangle.Left; x < rectangle.Right; x++) { SetToken(level, x, y, token, fore, back); } } } }
public void DrawLine(MatrixLevels level, Point point0, Point point1, char token) { bool steep = Math.Abs(point1.Y - point0.Y) > Math.Abs(point1.X - point0.X); if (steep) { Swap <int>(ref point0.X, ref point0.Y); Swap <int>(ref point1.X, ref point1.Y); } if (point0.X > point1.X) { Swap <int>(ref point0.X, ref point1.X); Swap <int>(ref point0.Y, ref point1.Y); } int dX = (point1.X - point0.X), dY = Math.Abs(point1.Y - point0.Y), err = (dX / 2), ystep = (point0.Y < point1.Y ? 1 : -1), y = point0.Y; for (int x = point0.X; x <= point1.X; ++x) { /*if (!(steep ? plot(y, x) : plot(x, y))) return;*/ if (steep) { GraphicConsole.Instance.Put(token, y, x); } else { GraphicConsole.Instance.Put(token, x, y); } err = err - dY; if (err < 0) { y += ystep; err += dX; } } }
public void ClearLayer(MatrixLevels level) { if (level == MatrixLevels.Effect) { for (int y = 0; y < levelMatrix.Height; y++) { for (int x = 0; x < levelMatrix.Width; x++) { levelMatrix.EffectMatrix[x, y].ForegroundColor = Color4.White; levelMatrix.EffectMatrix[x, y].BackgroundColor = Color4.Black; levelMatrix.EffectMatrix[x, y].Token = ' '; } } } else if (level == MatrixLevels.Entity) { for (int y = 0; y < levelMatrix.Height; y++) { for (int x = 0; x < levelMatrix.Width; x++) { levelMatrix.EntityMatrix[x, y].ForegroundColor = Color4.White; levelMatrix.EntityMatrix[x, y].BackgroundColor = Color4.Black; levelMatrix.EntityMatrix[x, y].Token = ' '; } } } }
public void DrawCircle(MatrixLevels level, Circle area, char token, Color4 fore, Color4 back, bool solid) { if (!solid) { #region NonSolid Circle int x = area.Radius, y = 0; int radiusError = 1 - x; while (x >= y) { SetToken(level, x + area.X, y + area.Y, token, fore, back); SetToken(level, y + area.X, x + area.Y, token, fore, back); SetToken(level, -x + area.X, y + area.Y, token, fore, back); SetToken(level, -y + area.X, x + area.Y, token, fore, back); SetToken(level, -x + area.X, -y + area.Y, token, fore, back); SetToken(level, -y + area.X, -x + area.Y, token, fore, back); SetToken(level, x + area.X, -y + area.Y, token, fore, back); SetToken(level, y + area.X, -x + area.Y, token, fore, back); SetToken(level, x + area.X, y + area.Y, token); y++; if (radiusError < 0) { radiusError += 2 * y + 1; } else { x--; radiusError += 2 * (y - x + 1); } } #endregion } else { #region SolidCircle List <Point> stainedTiles = new List <Point>(); for (int angle = 0; angle < 360; angle += 1) { for (int r = 0; r < area.Radius; r++) { Point position = new Point(); position.X = (int)(area.X + 0.5 + r * Math.Cos(angle)); position.Y = (int)(area.Y + 0.5 + r * Math.Sin(angle)); if (!stainedTiles.Contains(position)) { SetToken(level, position.X, position.Y, token, fore, back); stainedTiles.Add(position); } } } #endregion } }
private void DrawBoard() { var grid = new Grid(); grid.HorizontalOptions = LayoutOptions.CenterAndExpand; grid.RowSpacing = 20; grid.ColumnSpacing = 20; var rowSize = 7; for (int i = 0; i < rowSize; i++) { grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); } int x = 0, y = 0, z = 0; var matrixIndex = 0; var currentIndex = 0; var rowIndex = 0; foreach (var spaceOrStar in ViewModel.BaseMatrix) { if (currentIndex == rowSize) { currentIndex = 0; grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); rowIndex++; } if (spaceOrStar == 1) { var gesture = new TapGestureRecognizer(); gesture.Tapped += ViewModel.UserTurn; var emptySqare = new BoxView() { BindingContext = ViewModel.OrderedUnits[matrixIndex], CornerRadius = 2, HeightRequest = 30, WidthRequest = 30 }; emptySqare.SetBinding(BackgroundColorProperty, "ColorSelected"); emptySqare.GestureRecognizers.Add(gesture); matrixIndex++; var nextValuesOnList = MatrixLevels <Model.Unit> .GiveNextPattern(x, z, y, matrixIndex); x = nextValuesOnList[0]; z = nextValuesOnList[1]; y = nextValuesOnList[2]; grid.Children.Add(emptySqare, currentIndex, rowIndex); } currentIndex++; } this.Board.Children.Add(grid); }
public void SetToken(MatrixLevels level, int x, int y, char token) { if (!IsOutOfBounds(x, y)) { if (level == MatrixLevels.Terrain) { levelMatrix.TerrainMatrix[x, y].Token = token; } else if (level == MatrixLevels.Effect) { levelMatrix.EffectMatrix[x, y].Token = token; } else if (level == MatrixLevels.Entity) { levelMatrix.EntityMatrix[x, y].Token = token; } } }
public void SetToken(MatrixLevels level, int x, int y, char token, Color4 fore, Color4 back) { if (!IsOutOfBounds(x, y)) { if (level == MatrixLevels.Terrain) { levelMatrix.TerrainMatrix[x, y].Token = token; levelMatrix.TerrainMatrix[x, y].ForegroundColor = fore; levelMatrix.TerrainMatrix[x, y].BackgroundColor = back; } else if (level == MatrixLevels.Effect) { levelMatrix.EffectMatrix[x, y].Token = token; levelMatrix.EffectMatrix[x, y].ForegroundColor = fore; levelMatrix.EffectMatrix[x, y].BackgroundColor = back; } else if (level == MatrixLevels.Entity) { levelMatrix.EntityMatrix[x, y].Token = token; levelMatrix.EntityMatrix[x, y].ForegroundColor = fore; levelMatrix.EntityMatrix[x, y].BackgroundColor = back; } } }