generated from admin/template
lesson6
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lesson6", "lesson6\lesson6.csproj", "{A31EA002-0F0C-4893-81F6-C620F32573DB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A31EA002-0F0C-4893-81F6-C620F32573DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A31EA002-0F0C-4893-81F6-C620F32573DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A31EA002-0F0C-4893-81F6-C620F32573DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A31EA002-0F0C-4893-81F6-C620F32573DB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,78 @@
|
||||
class Pokemon
|
||||
{
|
||||
private string name;
|
||||
private int level;
|
||||
private int hp;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
set
|
||||
{
|
||||
name = string.IsNullOrWhiteSpace(value) ? "Безымянный" : 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()
|
||||
{
|
||||
Name = "";
|
||||
Level = 1;
|
||||
Hp = 100;
|
||||
}
|
||||
public Pokemon(string name, int level, int hp)
|
||||
{
|
||||
Name = name;
|
||||
Level = level;
|
||||
Hp = hp;
|
||||
}
|
||||
|
||||
public void takeDamage(int damage)
|
||||
{
|
||||
Hp -= damage;
|
||||
}
|
||||
|
||||
public void Heal()
|
||||
{
|
||||
Hp = 100;
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("=== ПРОВЕРКА ИНКАПСУЛЯЦИИ ===");
|
||||
Pokemon pokemon = new Pokemon("Пикачу", 5, 100);
|
||||
Console.WriteLine("Попытка установить HP = -50...");
|
||||
pokemon.Hp = -50;
|
||||
Console.WriteLine($"Текущее HP: {pokemon.Hp} (защита сработала)");
|
||||
pokemon.Hp = 100;
|
||||
pokemon.takeDamage(30);
|
||||
Console.WriteLine($"Покемон получил 30 урона. HP: {pokemon.Hp}");
|
||||
pokemon.Heal();
|
||||
Console.WriteLine($"Покемон вылечился. HP: {pokemon.Hp}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{7D920295-759D-4CFB-B58B-F6677971FD2F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7D920295-759D-4CFB-B58B-F6677971FD2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7D920295-759D-4CFB-B58B-F6677971FD2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7D920295-759D-4CFB-B58B-F6677971FD2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7D920295-759D-4CFB-B58B-F6677971FD2F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1 @@
|
||||
Console.WriteLine("Hello, World!");
|
||||
@@ -0,0 +1,32 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Kotlin ###
|
||||
.kotlin
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
@@ -0,0 +1,5 @@
|
||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
fun main() {
|
||||
println("meow")
|
||||
}
|
||||
Reference in New Issue
Block a user