using System; using System.Collections.Generic; class Program { static void Main() { Player player = new Player("Hero", 100); List enemies = new List { new Enemy("Goblin", 30, 10), new Enemy("Orc", 50, 15), new Enemy("Dragon", 100, 20) }; Console.WriteLine("Welcome to the Shooter Game!"); Console.WriteLine("-----------------------------"); while (player.Health > 0 && enemies.Count > 0) { Console.WriteLine($"\n{player.Name}'s Health: {player.Health}"); Console.WriteLine("Enemies:"); foreach (var enemy in enemies) { Console.WriteLine($"- {enemy.Name} (Health: {enemy.Health})"); } Console.WriteLine("\nChoose an action:"); Console.WriteLine("1. Shoot an enemy"); Console.WriteLine("2. Heal yourself"); Console.Write("Enter your choice: "); string choice = Console.ReadLine(); if (choice == "1") { Console.Write("Enter the name of the enemy to shoot: "); string enemyName = Console.ReadLine(); Enemy targetEnemy = enemies.Find(e => e.Name.Equals(enemyName, StringComparison.OrdinalIgnoreCase)); if (targetEnemy != null) { player.Shoot(targetEnemy); if (targetEnemy.Health <= 0) { Console.WriteLine($"{targetEnemy.Name} has been defeated!"); enemies.Remove(targetEnemy); } } else { Console.WriteLine("Enemy not found."); } } else if (choice == "2") { player.Heal(); } else { Console.WriteLine("Invalid choice."); } foreach (var enemy in enemies) { enemy.Attack(player); } } if (player.Health <= 0) { Console.WriteLine("You have been defeated. Game Over."); } else { Console.WriteLine("You defeated all the enemies! Congratulations!"); } } } class Player { public string Name { get; } public int Health { get; private set; } public Player(string name, int health) { Name = name; Health = health; } public void Shoot(Enemy enemy) { int damage = new Random().Next(10, 21); // Random damage between 10 and 20 enemy.TakeDamage(damage); Console.WriteLine($"{Name} shoots {enemy.Name} for {damage} damage!"); } public void Heal() { int healAmount = new Random().Next(15, 31); // Random heal between 15 and 30 Health += healAmount; Console.WriteLine($"{Name} heals for {healAmount} health!"); } } class Enemy { public string Name { get; } public int Health { get; private set; } public int AttackPower { get; } public Enemy(string name, int health, int attackPower) { Name = name; Health = health; AttackPower = attackPower; } public void TakeDamage(int damage) { Health -= damage; if (Health < 0) Health; = 0 } public void Attack(Player player) { if (Health > 0) { player.Health -= AttackPower; Console.WriteLine($"{Name} attacks {player.Name} for {AttackPower} damage!"); } } }