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
}
}
}
}
}