C#C
C#2y ago
Bớp

draw board caro

Hi! I want when the user drags up, down, left or right, it will draw more! I am new to C# (MAUI). Below is the code for drawing the mechanical table
namespace CaroGame.Source;

internal class Board : IDrawable {
    private readonly float cellSize = 100f;
    
    public void Draw(ICanvas canvas, RectF rect) {
        canvas.StrokeColor = Colors.Black;
        canvas.StrokeSize = 1;

        int numberOfLinesHorizontal = (int)Math.Ceiling(rect.Height / cellSize);
        int numberOfLinesVertical = (int)Math.Ceiling(rect.Width / cellSize);

        for (int i = 0; i <= numberOfLinesHorizontal; i++) {
            float y = i * cellSize;
            canvas.DrawLine(rect.Left, y, rect.Right, y);
        }

        for (int j = 0; j <= numberOfLinesVertical; j++) {
            float x = j * cellSize;
            canvas.DrawLine(x, rect.Top, x, rect.Bottom);
        }
    }
}

Thanks!
Screenshot_2024-06-14_at_11.39.31.png
Was this page helpful?