//######################################################################## //# Event Handlers /// <summary> /// Tick event handler of animation timer. /// Moves all sprites by calling the Move() method. /// </summary> private void AnimationTimerTick(object sender, EventArgs e) { // Move all bombs. // Also remove bombs that are off screen, hence the backwards loop. for (int index = _bombs.Count - 1; index >= 0; index--) { Bomb bomb = _bombs[index]; if (bomb.Y >= Height) { _bombs.RemoveAt(index); } else { bomb.Move(); if (bomb.CollidedWith(_ship)) { Win("Alien"); } } } // Move the alien _alien.Move(); // Ask the alien whether it wants to drop another bomb Bomb newBomb = _alien.LaunchBomb(); if (newBomb != null) { _bombs.Add(newBomb); } // Force repaint. This triggers the GamePaint() handler below. Refresh(); }
private void _animationTimer_Tick(object sender, EventArgs e) { _alien.Move(); foreach (Bomb bomb in _bombs) { bomb.Move(); } if (_randomNumberGenerator.NextDouble() < BOMB_PROBABILITY) { Bomb bomb = _alien.DropBomb(); _bombs.Add(bomb); } _pictureBox.Refresh(); }
/// <summary> /// Moves the alien in the specified direction. /// </summary> /// <param name="dir">The direction to move the alien.</param> public void Move(Direction dir) { alien.Move(dir); }