Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

using System;

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();
}

private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)


{

}
Button[,] matrice = new Button[9, 9];
int m = 0;
private void Form1_Load(object sender, EventArgs e)
{
for(int i =0; i<9; i++)
{

for(int j = 0; j < 9; j++)


{
m++;
string ime = $"button{m}";
matrice[i, j] = (Button)Controls.Find(ime, true)[0];
}

private void button32_Click(object sender, EventArgs e)


{

}
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;
}
}
}

bool moze = true;


for(int i = 0; i < 9; i++)
{
for(int j =0; j < 9; j++)
{
if(matrice[i, j].BackColor == Color.RosyBrown)
{
moze = false;
}
}
}
int zbir = 0;
int number;
if (moze)
{
for(int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (int.TryParse(matrice[i,j].Text, out number))
{
zbir += int.Parse(matrice[i, j].Text);
}

}
}
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;
}

private void button84_Click(object sender, EventArgs e)


{
br = 3;
}

private void button87_Click(object sender, EventArgs e)


{
br = 6;
}

private void button86_Click(object sender, EventArgs e)


{
br = 5;
}

private void button85_Click(object sender, EventArgs e)


{
br = 4;
}

private void button88_Click(object sender, EventArgs e)


{
br = 7;
}

private void button89_Click(object sender, EventArgs e)


{
br = 8;
}

private void button90_Click(object sender, EventArgs e)


{
br = 9;
}
}
}

You might also like