private void buttonTemizle_Click(object sender, EventArgs e) { Reset(); radioButton1.Enabled = true; radioButton1.Checked = true; radioButton2.Enabled = true; radioButton3.Enabled = true; radioButton4.Enabled = true; BenPanel.Invalidate(); buttonHazir.Enabled = false; }
private void buttonRastgele_Click(object sender, EventArgs e) { var r = new Random(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { ben[i][j] = 0; } } int count = 10, size = 0; while (count >= 0) { if (count < 5) { size = 1; } else if (count < 7) { size = 2; } else if (count < 9) { size = 3; } else if (count == 9) { size = 4; } int y = r.Next(0, 10); int x = r.Next(0, 10); if (r.Next(0, 2) == 1) { ChangeVerctical(); } NullMas(); if (CheckSq(x, y, size - 1, GetLink())) { CreateShip(x, y, 2, size - 1, GetLink()); count--; } } radioButton1.Enabled = false; radioButton2.Enabled = false; radioButton3.Enabled = false; radioButton4.Enabled = false; BenPanel.Invalidate(); buttonHazir.Enabled = true; }
public void EnemyTurn() { Random r = new Random(); bool flag = true; while (flag) { X = r.Next(0, 10); Y = r.Next(0, 10); if (ben[X][Y] == 4 || ben[X][Y] == 3) { flag = true; continue; } if (ben[X][Y] == 0 || ben[X][Y] == 2) { flag = false; } if (ben[X][Y] == 0) { ben[X][Y] = 4; BenPanel.Invalidate(); } else if (ben[X][Y] != 4 && ben[X][Y] != 3) { ben[X][Y] = 3; MyShip--; Explosion(X, Y, GetLink(), true); if (MyShip == 0) { Victory("Üzgünüm Kaybettin..."); } } } }
private void BenPanel_MouseClick(object sender, MouseEventArgs e) { if ((radioButton1.Enabled == false && radioButton2.Enabled == false && radioButton3.Enabled == false && radioButton4.Enabled == false)) { MessageBox.Show("Tüm gemiler yerleştirildi.", "Dikkat!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (e.Button == MouseButtons.Right) { ChangeVerctical(); NullMas(); BenPanel.Invalidate(); } else { int w = BenPanel.Width / ReturnMasSize(); int h = BenPanel.Height / ReturnMasSize(); int size; if (radioButton1.Checked) { size = 1; } else if (radioButton2.Checked) { size = 2; } else if (radioButton3.Checked) { size = 3; } else { size = 4; } int x = e.X / w; int y = e.Y / h; if (x == 9 && size != 1 && !Vertical) { x -= size - 1; } if (y == 9 && size != 1 && Vertical) { y -= size - 1; } NullMas(); if (CheckSq(x, y, size - 1, GetLink())) { CreateShip(x, y, 2, size - 1, GetLink()); if (radioButton1.Checked) { Count1X++; } else if (radioButton2.Checked) { Count2X++; } else if (radioButton3.Checked) { Count3X++; } else { Count4X++; } if (Count1X > 3 && radioButton1.Enabled) { radioButton1.Enabled = false; FindNextRb(radioButton1, radioButton2, radioButton3, radioButton4); } else if (Count2X > 2 && radioButton2.Enabled) { radioButton2.Enabled = false; FindNextRb(radioButton1, radioButton2, radioButton3, radioButton4); } else if (Count3X > 1 && radioButton3.Enabled) { radioButton3.Enabled = false; FindNextRb(radioButton1, radioButton2, radioButton3, radioButton4); } else if (Count4X > 0 && radioButton4.Enabled) { radioButton4.Enabled = false; FindNextRb(radioButton1, radioButton2, radioButton3, radioButton4); } if (Count4X > 0 && Count3X > 1 && Count2X > 2 && Count1X > 3) { buttonHazir.Enabled = true; } } BenPanel.Invalidate(); } } }
private void BenPanel_MouseLeave(object sender, EventArgs e) { NullMas(); BenPanel.Invalidate(); }