public Form4()
{
InitializeComponent();
objects = new List<MapObject2>();
objects.Add(new MapObject2()
{
Name = "Мумия",
X = 258,
Y = 136,
Width = 24,
Height = 43
});
objects.Add(new MapObject2()
{
Name = "Банка",
X = 286,
Y = 178,
Width = 17,
Height = 17
});
objects.Add(new MapObject2()
{
Name = "Змеи",
X = 370,
Y = 303,
Width = 23,
Height = 19
});
objects.Add(new MapObject2()
{
Name = "Царь",
X = 73,
Y = 132,
Width = 31,
Height = 42
});
objects.Add(new MapObject2()
{
Name = "Колесница",
X = 352,
Y = 103,
Width = 65,
Height = 41
});
objects.Add(new MapObject2()
{
Name = "Конь",
X = 5,
Y = 163,
Width = 15,
Height = 38
});
}
List<MapObject2> objects;
private void PictureBox2_MouseClick(object sender, MouseEventArgs e)
{
int currentX = e.X;
int currentY = e.Y;
for (int i = 0; i < objects.Count; i++)
{
if (currentX > (objects[i].X - objects[i].Width / 2) & currentX < (objects[i].X + objects[i].Width / 2)
& currentY > (objects[i].Y - objects[i].Height / 2) & currentY < (objects[i].Y + objects[i].Height / 2))
{
MessageBox.Show("Ты нашел слово!");
}
}
}
public class MapObject2
{
public string Name;
public int X;
public int Y;
public int Width;
public int Height;
public bool IsClicked = false;
}
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
int currentX = e.X;
int currentY = e.Y;
for (int i = 0; i < objects.Count; i++)
{
if (currentX > (objects[i].X - objects[i].Width / 2) & currentX < (objects[i].X + objects[i].Width / 2)
& currentY > (objects[i].Y - objects[i].Height / 2) & currentY < (objects[i].Y + objects[i].Height / 2))
{
MessageBox.Show("Ты нашел слово: " + objects[i].Name);
//Отмечаем что данный объект прокликан
objects[i].IsClicked = true;
}
}
//Проверяем все ли объекты прокликаны
if (IsAllClicked()) MessageBox.Show("Все объекты прокликаны");
}
//Проверка коллекции объектов - все ли прокликаны
private bool IsAllClicked()
{
bool AllObjectsClicked = true;
foreach (MapObject2 item in objects)
{
if (!item.IsClicked)
{
AllObjectsClicked = false; break;
}
}
return AllObjectsClicked;
}
public class SomeObject
{
public bool WasClicked { get; set; }
public MapObject2 Object { get; }
public SomeObject(MapObject2 mobj)
{
Object = new MapObject2(mobj);
}
}