generated from admin/template
Fix UTF-8 encoding and add null-safety parsing for inputs
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Lab01
|
||||
{
|
||||
internal class Program
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user