Ich möchte in der Lage sein, eine Kugel zu löschen, nachdem sie eine Wand berührt hat Komponente
Code: Select all
private void bullet_Tick(object sender, EventArgs e)
{
foreach (Bullet bullet in BulletList)
{
foreach(var wall in wallList)
{
if (bullet.BulletPictureBox.Bounds.IntersectsWith(wall.Bounds))
{
// method to destroy the bullet object
}
}
}
}
Ich habe mich gefragt, ob es eine Methode gibt, die ich übersehen habe, oder ob ich aufhören muss, die foreach-Methode zu verwenden (ich weiß, dass ich hätte es durch die Verwendung von Tags einfacher machen können). oder ob ich etwas innerhalb meiner eigentlichen Bullet-Klasse ändern muss
Code: Select all
public class Bullet
{
public PictureBox BulletPictureBox { get; private set; }
string DREC;
public Bullet(Form form, int x, int y, List BulletList, string direction)
{
BulletPictureBox = new PictureBox
{
Size = new Size(10, 10),
BackColor = Color.Red,
Location = new Point(x, y)
};
DREC = direction;
form.Controls.Add(BulletPictureBox);
BulletList.Add(this);
}
public string GetDirection()
{
return DREC;
}
}