C#小游戏—钢铁侠VS太空侵略者
2012 年 7 月 15 日
private void FireBullet(object sender, EventArgs e) { foreach (Control c in this.Controls) { if (c is PictureBox && c.Name == "Bullet") { PictureBox bullet = (PictureBox)c; bullet.Top -= 5;
if (bullet.Location.Y <= 0) { this.Controls.Remove(bullet); }
foreach(Control ct in this.Controls) { if (ct is PictureBox && ct.Name == "Laser") { PictureBox laser = (PictureBox)ct;
if (bullet.Bounds.IntersectsWith(laser.Bounds)) { this.Controls.Remove(bullet); this.Controls.Remove(laser); pts++; Score(pts); } } }
foreach(Control ctrl in this.Controls) { if (ctrl is PictureBox && ctrl.Name == "Alien") { PictureBox alien = (PictureBox)ctrl;
if (bullet.Bounds.IntersectsWith(alien.Bounds) && !Touched(alien)) { this.Controls.Remove(bullet); this.Controls.Remove(alien); aliens.Remove(alien); pts += 5; Score(pts); CheckForWinner(); } else if (bullet.Bounds.IntersectsWith(alien.Bounds) && Touched(alien)) { this.Controls.Remove(bullet); this.Controls.Remove(alien); delay.Add(alien); pts += 5; Score(pts); CheckForWinner(); } } } } }}