Clickable grid for minesweeper

JuliusKreutzJuliusKreutz Member ✭✭
edited September 2018 in Xamarin.Forms

Hello there, I'm currently working on a minesweeper project. So I created a grid with buttons that changes size with the chosen difficulty but it takes a very long time to load. So I just wanted to know if there is a better way to create a grid with buttons that won't load that long.

This is the code I currently use:

protected override void OnAppearing()
        {
            var controlGrid = new Grid { RowSpacing = 1, ColumnSpacing = 1 };
            controlGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(150) });
            for (int i = 0; i < lenght; i++)
            {
                controlGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
            }
            for (int i = 0; i < height; i++)
            {
                controlGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            }

            for (int x = 0; x < lenght; x++)
            {
                for (int y = 1; y <= height; y++)
                {
                    for (int i = 0; i <= lenght * height; i++)
                    {
                        controlGrid.Children.Add(new Button { ClassId = i.ToString(), Style = fieldButton }, x, y);
                    }
                }
            }
            Content = controlGrid;
        }

Best Answer

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Uh... I know I answered this very question in the last couple days. Did you start this topic once before recently?

    Suggesting you first figure out where exactly the delay is coming from by putting comments and console.writeline in your code at each stage. YOu need to know if the problem is at makingthe grid, making the buttons or adding the buttons, etc.

Sign In or Register to comment.