Fix UTF-8 encoding and add null-safety parsing for inputs

This commit is contained in:
2026-09-09 09:54:53 +03:00
parent 13882ab7c2
commit 59cd1bce36
3 changed files with 16 additions and 18 deletions
+3 -2
View File
@@ -1,4 +1,5 @@
using System;
using System;
namespace Lab01
{
internal class Program
@@ -37,4 +38,4 @@ namespace Lab01
Console.WriteLine("****************************************");
}
}
}
}
+8 -7
View File
@@ -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
}
}
}
}
}
+5 -9
View File
@@ -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