Professional Documents
Culture Documents
Sudoku
Sudoku
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
Button[,] matrice = new Button[9, 9];
int m = 0;
private void Form1_Load(object sender, EventArgs e)
{
for(int i =0; i<9; i++)
{
}
int[] niz = new int[9];
int br = 0;
int i1;
int j1;
private void button_Click(object sender, EventArgs e)
{
Button clickedbutton = sender as Button;
clickedbutton.Text = br.ToString();
for(int i =0; i < 9; i++)
{
for(int j =0; j < 9; j++)
{
if (matrice[i, j] == clickedbutton)
{
i1=i;
j1 = j;
Proverakv(i1, j1, clickedbutton);
break;
}
}
}
}
}
if (zbir == 405)
{
MessageBox.Show("jupiiii");
}
}
}
int z = 0;
int mm ;
int nn;
private void Proverakv(int i1, int j1, Button clickedbutton)
{
#region aa
for (int i = 0; i<9; i++)
{
if (matrice[i,j1].Text == clickedbutton.Text)
{
matrice[i, j1].BackColor = Color.RosyBrown;
clickedbutton.BackColor = Color.RosyBrown;
z++;
}
else
{
matrice[i, j1].BackColor = Color.White;
}
if (matrice[i1,i].Text == clickedbutton.Text)
{
matrice[i1,i].BackColor = Color.RosyBrown;
clickedbutton.BackColor = Color.RosyBrown;
z++;
}
else
{
matrice[i1, i].BackColor = Color.White;
}
}
if (z - 2 == 0)
{
clickedbutton.BackColor = Color.White;
}
z = 0;
#endregion
if(i1 > -1 && i1 < 3)
{
if(j1>-1 && j1 < 3)
{
mm = 0;
nn = 0;
Proveradva(mm, nn, i1, j1, clickedbutton);
}
if (j1 > 2 && j1 < 6)
{
mm = 0;
nn = 3;
Proveradva(mm, nn, i1, j1, clickedbutton);
}
if (j1 > 5 && j1 < 9)
{
mm = 0;
nn = 6;
Proveradva(mm, nn, i1, j1, clickedbutton);
}
}
else if(i1 > 2 && i1 < 6)
{
if (j1 > -1 && j1 < 3)
{
mm = 3;
nn = 0;
Proveradva(mm, nn, i1, j1, clickedbutton);
}
if (j1 > 2 && j1 < 6)
{
mm = 3;
nn = 3;
Proveradva(mm, nn, i1, j1, clickedbutton);
}
if (j1 > 5 && j1 < 9)
{
mm = 3;
nn = 6;
Proveradva(mm, nn, i1, j1, clickedbutton);
}
}
else if (i1 > 5 && i1 < 9)
{
if (j1 > -1 && j1 < 3)
{
mm = 6;
nn = 0;
Proveradva(mm, nn, i1, j1, clickedbutton);
}
if (j1 > 2 && j1 < 6)
{
mm = 6;
nn = 3;
Proveradva(mm, nn, i1, j1, clickedbutton);
}
if (j1 > 5 && j1 < 9)
{
mm = 6;
nn = 6;
Proveradva(mm, nn, i1, j1, clickedbutton);
}
}
int i2;
int j2;
private void Proveradva(int mm, int nn, int i1, int j1, Button
clickedbutton) {
bool na = false;
for (int i = mm; i < mm+3; i++)
{
for(int j = nn; j < nn+3; j++)
{
if(i != i1 && j!=j1 && matrice[i, j].Text ==
clickedbutton.Text)
{
i2=i;
j2 = j;
na= true;
matrice[i, j].BackColor = Color.RosyBrown;
clickedbutton.BackColor = Color.RosyBrown;
}
}
}
if (!na)
{
na = false;
matrice[i2, j2].BackColor = Color.White;
}
}
private void button82_Click(object sender, EventArgs e)
{
br = 1;
}
private void button83_Click(object sender, EventArgs e)
{
br = 2;
}