public void Start() { dataGridView1.Enabled = true; dataGridView1.Rows.Clear(); dataGridView1.Columns.Clear(); dataGridView1.Size = new Size(Boyut * 35, Boyut * 35); dataGridView1.RowTemplate.Height = 35; game = new KnightTour(Boyut); game.Define(); click = new PointCord(); dizi = null; oncekiDizi = null; tiklama = 0; for (int i = 0; i < Boyut; i++) { dataGridView1.Columns.Add("", ""); } for (int i = 0; i < Boyut; i++) { dataGridView1.Rows.Add(); } dataGridView1.CurrentCell.Style.SelectionBackColor = Color.White; }
public void Solve(PointCord point) { if (tiklama == 0 || dataGridView1.Rows[point.x].Cells[point.y].Style.BackColor == Color.Thistle) { int numbert = game.Click(point); dataGridView1.Rows[point.x].Cells[point.y].Value = numbert; dataGridView1.CurrentCell.Style.BackColor = Color.PowderBlue; dataGridView1.CurrentCell.Style.SelectionBackColor = Color.PowderBlue; dizi = game.Identify(point); tiklama++; lblScore.Text = tiklama + ""; } if (oncekiDizi != null) { for (int i = 0; oncekiDizi[i] != null & i < oncekiDizi.Length; i++) { int x = oncekiDizi[i].x; int y = oncekiDizi[i].y; if (dataGridView1.Rows[x].Cells[y].Style.BackColor == Color.Thistle) { dataGridView1.Rows[x].Cells[y].Style.BackColor = Color.White; } } } if (dizi != null) { int i = 0; for (i = 0; dizi[i] != null & i < dizi.Length; i++) { int x = dizi[i].x; int y = dizi[i].y; dataGridView1.Rows[x].Cells[y].Style.BackColor = Color.Thistle; } label2.Text = "" + i; } oncekiDizi = dizi; bool alan = false; for (int i = 0; i < Boyut; i++) { for (int j = 0; j < Boyut; j++) { if (dataGridView1.Rows[i].Cells[j].Style.BackColor == Color.Thistle) { alan = true; } } } if (tiklama == Boyut * Boyut) { MessageBox.Show("Tebrikler Oyunu Kazandınız..."); dataGridView1.Enabled = false; tiklama = 0; } if (!alan) { MessageBox.Show("Game Over"); dataGridView1.Enabled = false; tiklama = 0; } }
public PointCord[] Identify(PointCord p) { PointCord[] point = new PointCord[8]; int i = 0; int x = p.x; int y = p.y; //X Koordinatı Üzerinde if ((int)tahta[x, y] != -1) { tahta[x, y] = count; if (x + 2 < Size && y + 1 < Size) { if ((int)tahta[x + 2, y + 1] == -1) { point[i] = new PointCord { x = x + 2, y = y + 1 }; i++; } } if (x + 2 < Size && y - 1 >= 0) { if ((int)tahta[x + 2, y - 1] == -1) { point[i] = new PointCord { x = x + 2, y = y - 1 }; i++; } } if (x - 2 >= 0 && y + 1 < Size) { if ((int)tahta[x - 2, y + 1] == -1) { point[i] = new PointCord { x = x - 2, y = y + 1 }; i++; } } if (x - 2 >= 0 && y - 1 >= 0) { if ((int)tahta[x - 2, y - 1] == -1) { point[i] = new PointCord { x = x - 2, y = y - 1 }; i++; } } //Y Kordinatı Üzerinde if (x + 1 < Size && y + 2 < Size) { if ((int)tahta[x + 1, y + 2] == -1) { point[i] = new PointCord { x = x + 1, y = y + 2 }; i++; } } if (x + 1 < Size && y - 2 >= 0) { if ((int)tahta[x + 1, y - 2] == -1) { point[i] = new PointCord { x = x + 1, y = y - 2 }; i++; } } if (x - 1 >= 0 && y + 2 < Size) { if ((int)tahta[x - 1, y + 2] == -1) { point[i] = new PointCord { x = x - 1, y = y + 2 }; i++; } } if (x - 1 >= 0 && y - 2 >= 0) { if ((int)tahta[x - 1, y - 2] == -1) { point[i] = new PointCord { x = x - 1, y = y - 2 }; i++; } } return(point); } else { return(null); } }
public int Click(PointCord point) { count++; tahta[point.x, point.y] = count; return(count); }