Answer the question
In order to leave comments, you need to log in
How to make it so that when you click on unnecessary coordinates, it subtracts from the timer, for example, 5 seconds?
there is a picturebox on it with selected elements by coordinates, but how to do it if you clicked on the wrong coordinates to take time? write in the code
here is the code to understand what is happening:
public Form3()
{
InitializeComponent();
objects = new List<MapObject>();
objects.Add(new MapObject()
{
Name = "Парусник",
X = 180,
Y = 34,
Width = 27,
Height = 37
});
objects.Add(new MapObject()
{
Name = "Пароход",
X = 304,
Y = 20,
Width = 49,
Height = 19
});
objects.Add(new MapObject()
{
Name = "Кактус",
X = 369,
Y = 127,
Width = 11,
Height = 20
});
objects.Add(new MapObject()
{
Name = "Лошадь",
X = 336,
Y = 80,
Width = 18,
Height = 18
});
objects.Add(new MapObject()
{
Name = "Дирижер",
X = 228,
Y = 156,
Width = 17,
Height = 19
});
objects.Add(new MapObject()
{
Name = "Мяч",
X = 213,
Y = 261,
Width = 20,
Height = 20
});
}
List<MapObject> objects;
private void Timer1_Tick(object sender, EventArgs e)
{
tk = --i;
TimeSpan span = TimeSpan.FromMinutes(tk);
string label = span.ToString(@"hh\:mm");
label1.Text = label.ToString();
if (i <= 0)
{
timer1.Stop();
pictureBox1.Visible = false;
pictureBox2.Visible = true;
}
}
int i;
int tk;
string c;
private void Button2_Click(object sender, EventArgs e)
{
button2.Visible = false;
pictureBox1.Visible = true;
i = 300;
c = "5:00";
label1.Text = c;
timer1.Interval = 1000;
timer1.Enabled = true;
timer1.Start();
}
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("Ты нашел слово!");
}
}
}
class MapObject
{
public string Name;
public int X;
public int Y;
public int Width;
public int Height;
}
Answer the question
In order to leave comments, you need to log in
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
int currentX = e.X;
int currentY = e.Y;
//Переменная для проверки того что мы куда-то попали
//По умолчанию предполагаем что мы никуда не попали
bool FindSome = false;
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);
//Отмечаем, что у нас был клик по нужным координатам, куда-то попали
FindSome = true;
}
}
//Проверяем - был ли клик в нужные координаты
if (!FindSome) TimeDec();
}
//Метод уменьшающий время
private void TimeDec()
{
MessageBox.Show("Никуда не попали");
//уменьшаем время
i-=5;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question