diff --git a/works/csharp/lab-01/Program.cs b/works/csharp/lab-01/Program.cs index 54318db..413f95d 100644 --- a/works/csharp/lab-01/Program.cs +++ b/works/csharp/lab-01/Program.cs @@ -1,4 +1,5 @@ -using System; +using System; + namespace Lab01 { internal class Program @@ -37,4 +38,4 @@ namespace Lab01 Console.WriteLine("****************************************"); } } -} \ No newline at end of file +} diff --git a/works/csharp/lab-02/Program.cs b/works/csharp/lab-02/Program.cs index db441cf..22dc6db 100644 --- a/works/csharp/lab-02/Program.cs +++ b/works/csharp/lab-02/Program.cs @@ -1,4 +1,5 @@ -using System; +using System; + namespace Lab02 { internal class Program @@ -10,10 +11,10 @@ namespace Lab02 // Задание 1.1: Расчёт характеристик покемона Console.WriteLine("=== Прокачка покемона ==="); Console.Write("Введите базовое значение атаки: "); - int baseAttack = Convert.ToInt32(Console.ReadLine()); + int.TryParse(Console.ReadLine(), out int baseAttack); Console.Write("Введите количество полученных уровней: "); - int levels = Convert.ToInt32(Console.ReadLine()); + int.TryParse(Console.ReadLine(), out int levels); int totalAttack = baseAttack + (levels * 5); Console.WriteLine($"Итоговая атака: {totalAttack}\n"); @@ -24,7 +25,7 @@ namespace Lab02 Console.WriteLine($"Текущий баланс: {balance} монет."); Console.Write("Сколько зелий лечения вы хотите купить? "); - int potionCount = Convert.ToInt32(Console.ReadLine()); + int.TryParse(Console.ReadLine(), out int potionCount); int totalPrice = potionCount * potionPrice; balance -= totalPrice; @@ -35,7 +36,7 @@ namespace Lab02 // Задание 2.1: Проверка состояния покемона в бою Console.Write("Введите текущее количество HP покемона: "); - int currentHp = Convert.ToInt32(Console.ReadLine()); + int.TryParse(Console.ReadLine(), out int currentHp); if (currentHp <= 0) { @@ -64,7 +65,7 @@ namespace Lab02 Console.WriteLine("4 — Побег"); Console.Write("Выберите действие (1-4): "); - int action = Convert.ToInt32(Console.ReadLine()); + int.TryParse(Console.ReadLine(), out int action); switch (action) { @@ -86,4 +87,4 @@ namespace Lab02 } } } -} \ No newline at end of file +} diff --git a/works/kotlin/lab-02/Main.kt b/works/kotlin/lab-02/Main.kt index ea12fee..0d6a15f 100644 --- a/works/kotlin/lab-02/Main.kt +++ b/works/kotlin/lab-02/Main.kt @@ -1,17 +1,13 @@ fun main() { // --- ЗАДАНИЕ 1. Явное приведение типов (Casting) --- print("Введите номер текущего хода: ") - val currentTurnInput = readln() + val currentTurn = readln().toIntOrNull() ?: 1 print("Введите количество энергии на столе: ") - val energyInput = readln() + val energy = readln().toIntOrNull() ?: 0 print("Введите коэффициент усиления атаки: ") - val multiplierInput = readln() - - val currentTurn: Int = currentTurnInput.toInt() - val energy: Int = energyInput.toInt() - val multiplier: Double = multiplierInput.toDouble() + val multiplier = readln().toDoubleOrNull() ?: 1.0 println("\n=== ИНИЦИАЛИЗАЦИЯ ПАРАМЕТРОВ ХОДА ===") println("Текущий ход: $currentTurn (тип Int)") @@ -27,13 +23,13 @@ println() print("Введите базовый урон покемона: ") - val baseDamage = readln().toInt() + val baseDamage = readln().toIntOrNull() ?: 0 println("Применена карта Тренера 'Леди из Центра Покемонов'!") cardsPlayed += 1 println() print("Сколько карт энергии прикрепить к Покемону? ") - val energyAttached = readln().toInt() + val energyAttached = readln().toIntOrNull() ?: 0 cardsPlayed += energyAttached val finalDamage = baseDamage * multiplier