/// <summary> /// Adds a bomb from an invader /// </summary> /// <param name="bombLocation"> /// the location where the bomb should be dropped from, if it is not assigned then a random /// location will be assigned /// </param> public void FireBomb(Point bombLocation = new Point()) { if (_isPlayerDead) { return; } if (!Invaders.Any()) { return; } if (!_helper.CanFireBomb(InvaderShots.Count, Wave)) { return; } if (!bombLocation.Initialized) { bombLocation = _helper.GetRandomBombLocation(Invaders); } var invaderShot = new Shot(bombLocation, Direction.Down, ShotType.Bomb); InvaderShots.Add(invaderShot); TriggerShotMoved(invaderShot, false); }
/// <summary> /// Removes all shots went out of bounds /// </summary> public void RemoveOutOfBoundShots(double playerShotsBound, double invadorShotBound) { var outOfBoundsPlayerShots = (from shot in PlayerShots where shot.Location.Y < playerShotsBound select shot).ToList(); var outOfBoundsInvadersShots = (from shot in InvaderShots where shot.Location.Y > invadorShotBound select shot).ToList(); if (outOfBoundsPlayerShots != null) { foreach (var shot in outOfBoundsPlayerShots) { PlayerShots.Remove(shot); TriggerShotMoved(shot, true); } } if (outOfBoundsInvadersShots == null) { return; } foreach (var shot in outOfBoundsInvadersShots) { InvaderShots.Remove(shot); TriggerShotMoved(shot, true); } }
/// <summary> /// Sets the game from the initial state /// </summary> public void InitializeGameStatus() { GameOver = false; Lives = 2; Wave = 0; PlayerShots.Clear(); InvaderShots.Clear(); Invaders.Clear(); }
/// <summary> /// Removes all the shots from the screen /// </summary> public void RemoveShots() { foreach (var shot in PlayerShots.ToList()) { PlayerShots.Remove(shot); TriggerShotMoved(shot, true); } foreach (var shot in InvaderShots.ToList()) { InvaderShots.Remove(shot); TriggerShotMoved(shot, true); } }