i am writing the game of nim in wpf and so far i have figured out how display the objects and added a mouse down event to highlight which object the user has selected to remove. Now my question is how do i make it so that the user can only select objects from the same row? Here is the code from the mouse down event:
private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
p = e.GetPosition(canvas1);
brushColor = Brushes.Blue;
foreach (object obj in canvas1.Children)
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
if (((Rectangle)obj).IsMouseDirectlyOver)
{
if (p.Y >= ((Rectangle)obj).Height && p.Y <= ((Rectangle)obj).Height*j + 45.5)
{
((Rectangle)obj).Fill = brushColor;
Console.WriteLine("p = " + p);
return;
}
}
}
}
}
}