Trida Sudoku.cs ma divne formatovani (viz kod dole). Zvol si jeden druh a drz si konzistenci
public bool IsNumberInTheSameCell(int number, int r, int s)
{
for (int radek = r; radek < r + 3; radek++)
{
for (int sloupec = s; sloupec < s + 3; sloupec++)
{
if (this.Controls[radek.ToString() + sloupec.ToString()].Text == number.ToString())
{
return false;
}
}
}
return true;
}
/// <summary>
/// Kontroluje, zda je na vybrané tlačítko možno doplnit právě zkoumané číslo. Zkoumá se pouze základní návaznost na ostatní čísla tj. unikátnost v řádku, sloupci a buňce.
/// </summary>
/// <param name="cislo">Zkoumané číslo (1-9)</param>
/// <param name="ButtonName">Označení buňky, u které se zkoumá dostupnost</param>
/// <returns>True - pokud se číslo nevyskytuje ani ve sloupci, řádku, buňce. False - pokud se číslo vyskytuje alespoň ve sloupci, řádku nebo buňce.</returns>
public bool CanBeFilledIn(int cislo, Button ButtonName)
{
char chari = ButtonName.Name[0];
char charj = ButtonName.Name[1];
for (int sloupec = 0; sloupec < 9; sloupec++)
{
if (this.Controls[chari.ToString() + sloupec.ToString()].Text == cislo.ToString())
{
return false;
}
}
for (int radek = 0; radek < 9; radek++)
{
if (this.Controls[radek.ToString() + charj.ToString()].Text == cislo.ToString())
{
return false;
}
}
int i = (int)Char.GetNumericValue(chari);
int j = (int)Char.GetNumericValue(charj);
if (i > -1 && i < 3)
{
if (j > -1 && j < 3)
{
if (!(IsNumberInTheSameCell(cislo, 0, 0))) return false;
}
else if (j > 2 && j < 6)
{
if (!(IsNumberInTheSameCell(cislo, 0, 3))) return false;
}
else
{
if (!(IsNumberInTheSameCell(cislo, 0, 6))) return false;
}
}
else if (i > 2 && i < 6)
{
if (j > -1 && j < 3)
{
if (!(IsNumberInTheSameCell(cislo, 3, 0))) return false;
}
else if (j > 2 && j < 6)
{
if (!(IsNumberInTheSameCell(cislo, 3, 3))) return false;
}
else
{
if (!(IsNumberInTheSameCell(cislo, 3, 6))) return false;
}
}
else if (i > 5 && i < 9)
{
if (j > -1 && j < 3)
{
if (!(IsNumberInTheSameCell(cislo, 6, 0))) return false;
}
else if (j > 2 && j < 6)
{
if (!(IsNumberInTheSameCell(cislo, 6, 3))) return false;
}
else
{
if (!(IsNumberInTheSameCell(cislo, 6, 6))) return false;
}
}
return true;
}
/// <summary>
/// Metoda, která doplní číslo do právě označené buňky, nebo číslo v ní vymaže.
/// </summary>
/// <param name="sender">Obsahuje data o objektu, který událost vyvolal.</param>
/// <param name="e">Obsahuje informace o události.</param>
private void NumberMenuButton_Click(object sender, EventArgs e)
{
Button button = sender as Button;
if (button.Text == "Vymaž")
{
if (WhereIWantToFillInNumber.Text != " ")
{
WhereIWantToFillInNumber.Text = " ";
FilledInFields--;
}
}
else
{
if (WhereIWantToFillInNumber.Text == " ") FilledInFields++;
WhereIWantToFillInNumber.Text = button.Text;
}
}
Trida
Sudoku.cs
ma divne formatovani (viz kod dole). Zvol si jeden druh a drz si konzistenci