private void ShootEnemy(int x, int y) { int enemyIndex = enemies.GetIndexByPosition(x, y); enemies[enemyIndex].Lifes--; if (enemies[enemyIndex].Lifes == 0) { enemies.Delete(enemyIndex); gameField.MakeDestroyed(x, y); } if (enemies.Count == 0) { Win(); } }
private void BulletsMove() { for (int i = 0; i < bullets.Count; i++) { int dx = 0, dy = 0; switch (bullets[i].CurrentDirection) { case Direction.Up: dy--; break; case Direction.Down: dy++; break; case Direction.Left: dx--; break; case Direction.Right: dx++; break; } if (gameField.NotOutOfField(bullets[i].X + dx, bullets[i].Y + dy)) { bullets[i].MakeStep(); } else { bullets.Delete(i--); continue; } int x = bullets[i].X; int y = bullets[i].Y; if (gameField[x, y] is Wall) { bullets.Delete(i--); gameField.MakeDestroyed(x, y); } else if (gameField[x, y] is Player) { bullets.Delete(i--); player.Lifes--; if (player.Lifes == 0) { Lose(); } } else if (!bullets[i].EnemySource) { for (int j = 0; j < enemies.Count; j++) { if (enemies[j].X == x && enemies[j].Y == y) { enemies[j].Lifes--; if (enemies[j].Lifes == 0) { enemies.Delete(j); gameField.MakeDestroyed(x, y); } break; } } if (enemies.Count == 0) { Win(); } } } }