Question: This is my C# Winform question. Here I am trying to create a soduko game that will populate 20 random numbers with no duplicate in

This is my C# Winform question.

Here I am trying to create a soduko game that will populate 20 random numbers with no duplicate in rows and columns.

Can someone help me to fix my code below

namespace Soduko { public partial class Form1 : Form {

const int n = 3; public int[,] myArray = new int[n * n, n * n]; const int SIZE = 40; public Form1() { InitializeComponent();

GenerateMap();

HideCells();

}

public void GenerateMap() { for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { myArray[i, j] = (i * n + i / n + j) % (n * n) + 1; } } CreateButton(); }

public void HideCells() { int N = 20; Random r = new Random(); while (N > 0) { for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { int a = r.Next(0, 3); buttons[i, j].Text = a == 0 ? "" : buttons[i, j].Text; if (a ==0) N--; } } } }

public void CreateButton() { for (int i = 0; i < 9; i++) { for (int j = 0; j <9; j++) { Button btn = new Button(); btn.Size = new System.Drawing.Size(SIZE, SIZE); btn.Text = myArray[i, j].ToString(); btn.Location = new Point(j * SIZE, i * SIZE); flowLayoutPanel1.Controls.Add(btn);

} }

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!