public void Shoot(ITank opponent) { if (Ammo.IsZero) { BuyAmmo(); return; } else { Ammo.Subtract(1); Random r = new Random(); double shootChance = r.NextDouble(); float currentDamage = Damage; var message = "Был произведён выстрел."; // Шанс критического выстрела if (shootChance <= 0.1) { currentDamage *= 1.2f; message = "Был произведён критический выстрел."; } // Шанс промаха else if (shootChance <= 0.3) { currentDamage = 0; message = "Случился промах."; } Console.WriteLine(message); opponent.TakeDamage(currentDamage); } }
public void Shoot(ITank opponent) { // Создание исходного сообщения var message = $"Произведён выстрел на {Damage} урона.\n"; var currentDamage = Damage; if (Ammo == 0) { if (TankType == TankTypes.Player) { message = "Не хватает патронов, внимательнее, мы пропустили ход!"; } else { BuyAmmo(); return; } } else { Ammo.Subtract(1); Random r = new Random(); // 10%-ый шанс на критический выстрел if (0.1 > r.NextDouble()) { currentDamage *= 1.2f; message = $"Произведён критический выстрел на {currentDamage} урона.\n"; } // 20%-ый шанс на промах else if (0.2 > r.NextDouble()) { currentDamage = 0; message = $"Произведён тактический промах с целью запугивания.\n"; } Console.WriteLine(message); opponent.TakeDamage(currentDamage); } }