Hello, I have some problems when getting the diagonal coordinates of the queen. What certain steps or algorithm could you suggest me as I am just manipulating the button list. It would be just fine for me if you suggest reworking the whole program for a better solution.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class eightqueens : Form
{
public eightqueens()
{
InitializeComponent();
}
List<Button> btnList = new List<Button>();
private void eightqueens_Load(object sender, EventArgs e)
{
for(int x = 1, z = 1; x <= 8; x++)
{
for (int y = 1; y <= 8; y++, z++)
{
Button btn = new Button();
btn.Size = new Size(30, 30);
flpBox.Controls.Add(btn);
btn.Name= (x).ToString(); // row
btn.Tag = (y).ToString(); // column assignment of number
if (y % 8 == 0)
{
flpBox.SetFlowBreak(btn, true);
}
btnList.Add(btn);
btn.Click += Button_Click;
}
}
}
private void flpBox_Paint(object sender, PaintEventArgs e)
{
}
private void Button_Click(Object sender, EventArgs e)
{
Object btn = sender;
if (((Button)btn).Text == "")
{
foreach (Button b in btnList)
{
if (int.Parse(((Button)btn).Tag.ToString()) == int.Parse(b.Tag.ToString()))
{
b.Text = "x";
}
else if (int.Parse(((Button)btn).Name) == int.Parse(b.Name))
{
b.Text = "x";
}
else if (int.Parse(b.Name) == int.Parse(b.Tag.ToString()))
{
}
}
((Button)btn).Text = "q";
}
else if (((Button)btn).Text == "q")
{
foreach (Button b in btnList)
{
if (int.Parse(b.Name) == int.Parse(b.Tag.ToString()))
{
b.Text = "";
}
}
((Button)btn).Text = "";
}
}
}
}