private void BulletsMoveWorker_Tick(object sender, EventArgs e) { foreach (var b in bullets) { if (b.IsDisposed) { break; } switch (b.Direction) { case DIRECTION.U: b.Location = new Point(b.Location.X, b.Location.Y - bulletStep); break; case DIRECTION.D: b.Location = new Point(b.Location.X, b.Location.Y + bulletStep); break; case DIRECTION.L: b.Location = new Point(b.Location.X - bulletStep, b.Location.Y); break; case DIRECTION.R: b.Location = new Point(b.Location.X + bulletStep, b.Location.Y); break; default: bullets.Remove(b); b.Close(); break; } if (b.Location.X <= gameFieldLocationX || b.Location.X >= gameFieldLocationX + gameFieldWidth || b.Location.Y <= gameFieldLocationY || b.Location.Y >= gameFieldLocationY + gameFieldHeight) { bullets.Remove(b); b.Close(); break; } Point bulletCenter = new Point(b.Location.X + bulletHeight / 2, b.Location.Y + bulletWidth / 2); foreach (var wall in walls) { if (bulletCenter.X >= wall.Location.X && bulletCenter.X <= wall.Location.X + wallWidth && bulletCenter.Y >= wall.Location.Y && bulletCenter.Y <= wall.Location.Y + wallHeight) { walls.Remove(wall); Controls.Remove(wall); bullets.Remove(b); b.Close(); break; } } if (bulletCenter.X >= userBase.Location.X && bulletCenter.X <= userBase.Location.X + baseWidth && bulletCenter.Y >= userBase.Location.Y && bulletCenter.Y <= userBase.Location.Y + baseHeight) { isUserTankAlive = false; userBase.Close(); bullets.Remove(b); b.Close(); break; } bool isNeedBreak = false; switch (b.BulletType) { case BULLET_TYPE.USER: foreach (CompTank tank in compTanks) { if (bulletCenter.X >= tank.Location.X && bulletCenter.X <= tank.Location.X + tankWidth && bulletCenter.Y >= tank.Location.Y && bulletCenter.Y <= tank.Location.Y + tankHeight) { compTanks.Remove(tank); tank.Close(); bullets.Remove(b); b.Close(); isNeedBreak = true; break; } } break; case BULLET_TYPE.COMP: if (bulletCenter.X >= userTank.Location.X && bulletCenter.X <= userTank.Location.X + tankWidth && bulletCenter.Y >= userTank.Location.Y && bulletCenter.Y <= userTank.Location.Y + tankHeight) { isUserTankAlive = false; userTank.Close(); bullets.Remove(b); b.Close(); isNeedBreak = true; break; } break; } if (isNeedBreak) { break; } } }