generated from admin/template
lab6
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lab-06", "lab-06\lab-06.csproj", "{B696010B-D447-40B4-ABF7-6FFBE791E429}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{B696010B-D447-40B4-ABF7-6FFBE791E429}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B696010B-D447-40B4-ABF7-6FFBE791E429}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B696010B-D447-40B4-ABF7-6FFBE791E429}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B696010B-D447-40B4-ABF7-6FFBE791E429}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace LaboratoryWork6
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("=== ПОКЕДЕКС ===");
|
||||||
|
Pokemon pika1 = new Pokemon("Пикачу", 5, 100);
|
||||||
|
Pokemon squirtle1 = new Pokemon("Сквиртл", 7, 90);
|
||||||
|
|
||||||
|
Console.Write("1. ");
|
||||||
|
pika1.ShowInfo();
|
||||||
|
Console.Write("2. ");
|
||||||
|
squirtle1.ShowInfo();
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("\n=== ПРОВЕРКА ИНКАПСУЛЯЦИИ ===");
|
||||||
|
Pokemon testPoke = new Pokemon("Чармандер", 10, 100);
|
||||||
|
|
||||||
|
Console.WriteLine("Попытка установить HP = -50...");
|
||||||
|
testPoke.HP = -50;
|
||||||
|
Console.WriteLine($"Текущее HP: {testPoke.HP} (защита сработала)");
|
||||||
|
|
||||||
|
testPoke.HP = 100;
|
||||||
|
testPoke.TakeDamage(30);
|
||||||
|
Console.WriteLine($"Покемон получил 30 урона. HP: {testPoke.HP}");
|
||||||
|
|
||||||
|
testPoke.Heal();
|
||||||
|
Console.WriteLine($"Покемон вылечился. HP: {testPoke.HP}");
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("\n=== ПОКЕДЕКС: СТАТИСТИКА ===");
|
||||||
|
Pokemon extraPoke = new Pokemon();
|
||||||
|
Console.WriteLine($"Создано покемонов: {Pokemon.Count}");
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("\n=== БИТВА ===");
|
||||||
|
pika1.Battle(squirtle1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Pokemon
|
||||||
|
{
|
||||||
|
private string name;
|
||||||
|
private int level;
|
||||||
|
private int hp;
|
||||||
|
|
||||||
|
public static int Count { get; private set; } = 0;
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return name; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value)) name = "Безымянный";
|
||||||
|
else name = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Level
|
||||||
|
{
|
||||||
|
get { return level; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value < 1) level = 1;
|
||||||
|
else if (value > 100) level = 100;
|
||||||
|
else level = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int HP
|
||||||
|
{
|
||||||
|
get { return hp; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value < 0) hp = 0;
|
||||||
|
else if (value > 100) hp = 100;
|
||||||
|
else hp = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pokemon(string name, int level, int hp)
|
||||||
|
{
|
||||||
|
this.Name = name;
|
||||||
|
this.Level = level;
|
||||||
|
this.HP = hp;
|
||||||
|
Count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pokemon()
|
||||||
|
{
|
||||||
|
this.Name = "Безымянный";
|
||||||
|
this.Level = 1;
|
||||||
|
this.HP = 100;
|
||||||
|
Count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowInfo()
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Имя: {Name}, Уровень: {Level}, HP: {HP}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TakeDamage(int damage)
|
||||||
|
{
|
||||||
|
HP -= damage;
|
||||||
|
if (HP < 0) HP = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Heal()
|
||||||
|
{
|
||||||
|
HP = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Battle(Pokemon enemy)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{this.Name} (Ур. {this.Level}, HP {this.HP}) против {enemy.Name} (Ур. {enemy.Level}, HP {enemy.HP})");
|
||||||
|
|
||||||
|
if (this.Level >= enemy.Level)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{this.Name} побеждает! {enemy.Name} теряет {this.Level} HP.");
|
||||||
|
enemy.TakeDamage(this.Level);
|
||||||
|
Console.WriteLine($"Победитель: {this.Name}. Осталось HP: {this.HP}");
|
||||||
|
Console.WriteLine($"Побеждённый: {enemy.Name}. Осталось HP: {enemy.HP}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{enemy.Name} побеждает! {this.Name} теряет {enemy.Level} HP.");
|
||||||
|
this.TakeDamage(enemy.Level);
|
||||||
|
Console.WriteLine($"Победитель: {enemy.Name}. Осталось HP: {enemy.HP}");
|
||||||
|
Console.WriteLine($"Побеждённый: {this.Name}. Осталось HP: {this.HP}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<RootNamespace>lab_06</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user