generated from admin/template
lab-06
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
using System.Globalization;
|
||||
|
||||
var pokemon = new Pokemon();
|
||||
|
||||
pokemon.ShowInfo();
|
||||
// Console.WriteLine($@"{pokemon.PokemonLevel}
|
||||
// {pokemon.PokemonHp}
|
||||
// {pokemon.PokemonName}");
|
||||
|
||||
class Pokemon
|
||||
{
|
||||
// FIELDS
|
||||
private string pokemonName;
|
||||
private byte pokemonLevel;
|
||||
private short pokemonHp;
|
||||
|
||||
private const byte
|
||||
MAX_NAME_LENGTH = 25,
|
||||
MIN_LEVEL = 1,
|
||||
MAX_LEVEL = 100;
|
||||
private const short
|
||||
MIN_HP = 0,
|
||||
MAX_HP = 2500;
|
||||
private const string DEFAULT_NAME = "Unknown";
|
||||
|
||||
// PROPS
|
||||
public string PokemonName
|
||||
{
|
||||
get => pokemonName;
|
||||
set
|
||||
{
|
||||
if(value != String.Empty)
|
||||
{
|
||||
if(value.Length > MAX_NAME_LENGTH)
|
||||
{
|
||||
pokemonName = value; // Cut method
|
||||
return;
|
||||
}
|
||||
|
||||
pokemonName = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte PokemonLevel
|
||||
{
|
||||
get => pokemonLevel;
|
||||
set
|
||||
{
|
||||
if (value < MIN_LEVEL) pokemonLevel = 1;
|
||||
else if (value > MAX_LEVEL) pokemonLevel = 100;
|
||||
else pokemonLevel = value;
|
||||
}
|
||||
}
|
||||
|
||||
public short PokemonHp
|
||||
{
|
||||
get => pokemonHp;
|
||||
set
|
||||
{
|
||||
if (value < MIN_HP) pokemonHp = 0;
|
||||
else if (value > MAX_HP) pokemonHp = 2500;
|
||||
else pokemonHp = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// CONSTRUCTORS
|
||||
public Pokemon(string pokemonName = DEFAULT_NAME)
|
||||
{
|
||||
this.pokemonName = pokemonName;
|
||||
}
|
||||
|
||||
public Pokemon(string pokemonName, short pokemonHp = 100) : this(pokemonName)
|
||||
{
|
||||
this.pokemonHp = pokemonHp;
|
||||
}
|
||||
|
||||
public Pokemon(string pokemonName, short pokemonHp = 100, byte pokemonLevel = MIN_LEVEL) : this(pokemonName, pokemonHp)
|
||||
{
|
||||
this.pokemonLevel = pokemonLevel;
|
||||
}
|
||||
|
||||
|
||||
// METHODS
|
||||
public override string ToString() => $"Name: {pokemonName} Level: {pokemonLevel} HP: {pokemonHp}";
|
||||
public void ShowInfo() => Console.WriteLine($"=== Information ===\n{ToString()}");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Лабораторная работа №7
|
||||
|
||||
* **Студент:** *Квасницкий Александр Александрович*
|
||||
* **lab:** *07*
|
||||
---
|
||||
@@ -0,0 +1,193 @@
|
||||
using HelpMethods;
|
||||
using System;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static Random rand = new Random();
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var pokemon1 = new Pokemon("Pokemon1", 100, 33);
|
||||
var pokemon2 = new Pokemon("Pokemon2", 100);
|
||||
|
||||
pokemon1.ShowInfo();
|
||||
StringHelp.Br();
|
||||
|
||||
pokemon2.ShowInfo();
|
||||
StringHelp.Br();
|
||||
|
||||
|
||||
Console.WriteLine("============================================");
|
||||
|
||||
pokemon1.TakeDamage(34);
|
||||
pokemon2.Heal(19);
|
||||
|
||||
pokemon1.ShowInfo();
|
||||
StringHelp.Br();
|
||||
|
||||
pokemon2.ShowInfo();
|
||||
StringHelp.Br();
|
||||
|
||||
|
||||
Console.WriteLine($"============================================\nCount of pokemons: {Pokemon.Count}");
|
||||
pokemon1.IsStronger(pokemon2);
|
||||
|
||||
|
||||
Console.WriteLine("\n============================================");
|
||||
pokemon1.Battle(pokemon2);
|
||||
}
|
||||
}
|
||||
|
||||
class Pokemon
|
||||
{
|
||||
// FIELDS
|
||||
private string pokemonName;
|
||||
private byte pokemonLevel;
|
||||
private short pokemonHp;
|
||||
private short pokemonAttack;
|
||||
|
||||
public static byte count;
|
||||
|
||||
|
||||
// CONST
|
||||
private const byte
|
||||
MAX_NAME_LENGTH = 25,
|
||||
MIN_LEVEL = 1,
|
||||
MAX_LEVEL = 100;
|
||||
private const short
|
||||
MIN_HP = 0,
|
||||
MAX_HP = 2500,
|
||||
MIN_ATTACK = 5,
|
||||
MAX_ATTACK = 250;
|
||||
private const string DEFAULT_NAME = "Unknown";
|
||||
|
||||
|
||||
// PROPS
|
||||
public string PokemonName
|
||||
{
|
||||
get => pokemonName;
|
||||
set => pokemonName = StringHelp.CutString(value, MAX_NAME_LENGTH, DEFAULT_NAME);
|
||||
}
|
||||
public byte PokemonLevel
|
||||
{
|
||||
get => pokemonLevel;
|
||||
set
|
||||
{
|
||||
if (value < MIN_LEVEL) pokemonLevel = MIN_LEVEL;
|
||||
else if (value > MAX_LEVEL) pokemonLevel = MAX_LEVEL;
|
||||
else pokemonLevel = value;
|
||||
}
|
||||
}
|
||||
public short PokemonHp
|
||||
{
|
||||
get => pokemonHp;
|
||||
set
|
||||
{
|
||||
if (value < MIN_HP) pokemonHp = MIN_HP;
|
||||
else if (value > MAX_HP) pokemonHp = MAX_HP;
|
||||
else pokemonHp = value;
|
||||
}
|
||||
}
|
||||
public short PokemonAttack
|
||||
{
|
||||
get => pokemonAttack;
|
||||
set
|
||||
{
|
||||
if (value < MIN_ATTACK) pokemonAttack = MIN_ATTACK;
|
||||
else if (value > MAX_ATTACK) pokemonAttack = MAX_ATTACK;
|
||||
else pokemonAttack = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte Count { get; }
|
||||
|
||||
|
||||
// CONSTRUCTORS
|
||||
public Pokemon() : this(DEFAULT_NAME, MIN_HP, MIN_ATTACK, MIN_LEVEL) { }
|
||||
public Pokemon(string pokemonName) : this(pokemonName, MIN_HP, MIN_ATTACK, MIN_LEVEL) { }
|
||||
public Pokemon(string pokemonName, short pokemonHp) : this(pokemonName, pokemonHp, MIN_ATTACK, MIN_LEVEL) { }
|
||||
public Pokemon(string pokemonName, short pokemonHp, short pokemonAttack) : this(pokemonName, pokemonHp, pokemonAttack, MIN_LEVEL) { }
|
||||
public Pokemon(string pokemonName, short pokemonHp, short pokemonAttack, byte pokemonLevel)
|
||||
{
|
||||
PokemonName = pokemonName;
|
||||
PokemonLevel = pokemonLevel;
|
||||
PokemonHp = pokemonHp;
|
||||
PokemonAttack = pokemonAttack;
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
// METHODS
|
||||
public override string ToString() => $"Name: {PokemonName} HP: {PokemonHp} Attack: {PokemonAttack} Level: {PokemonLevel}";
|
||||
public void ShowInfo() => Console.WriteLine($"=== Information ===\nName: {PokemonName}\t(HP: {PokemonHp} | Attack: {PokemonAttack} | Level {PokemonLevel})");
|
||||
public void TakeDamage(short damage) => PokemonHp -= Math.Abs(damage);
|
||||
public void Heal(short value) => PokemonHp += Math.Abs(value);
|
||||
public void IsStronger(Pokemon enemy)
|
||||
{
|
||||
byte scorePlayer1 = 0, scorePlayer2 = 0;
|
||||
|
||||
if (PokemonHp > enemy.PokemonHp) scorePlayer1++;
|
||||
else if (PokemonHp < enemy.PokemonHp) scorePlayer2++;
|
||||
else { scorePlayer1++; scorePlayer2++; }
|
||||
|
||||
if (PokemonLevel > enemy.PokemonLevel) scorePlayer1++;
|
||||
else if (PokemonLevel < enemy.PokemonLevel) scorePlayer2++;
|
||||
else { scorePlayer1++; scorePlayer2++; }
|
||||
|
||||
if (scorePlayer1 > scorePlayer2) Console.WriteLine($"{PokemonName} stronger!");
|
||||
else if (scorePlayer1 < scorePlayer2) Console.WriteLine($"{enemy.PokemonName} stronger!");
|
||||
else Console.WriteLine("Draw!");
|
||||
}
|
||||
public void Battle(Pokemon enemy)
|
||||
{
|
||||
short round = 1;
|
||||
|
||||
Console.WriteLine("The battle has begun!\n");
|
||||
|
||||
while(true)
|
||||
{
|
||||
if (PokemonHp < 1)
|
||||
{
|
||||
Console.WriteLine($"The {PokemonName} is unconscious!\n{enemy.PokemonName} won!");
|
||||
break;
|
||||
}
|
||||
|
||||
if (enemy.PokemonHp < 1)
|
||||
{
|
||||
Console.WriteLine($"The {enemy.PokemonName} is unconscious!\n{PokemonName} won!");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Console.WriteLine($"Round №{round}");
|
||||
if(round % 2 == 0)
|
||||
{
|
||||
if(enemy.PokemonHp - PokemonAttack < 1)
|
||||
{
|
||||
Console.WriteLine($"{PokemonName} attacked {enemy.PokemonName}\t({enemy.PokemonHp} - {PokemonAttack} = 0)\n");
|
||||
enemy.PokemonHp = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
Console.WriteLine($"{PokemonName} attacked {enemy.PokemonName}\t({enemy.PokemonHp} - {PokemonAttack} = {enemy.PokemonHp - PokemonAttack})\n");
|
||||
enemy.PokemonHp -= PokemonAttack;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PokemonHp - enemy.PokemonAttack < 1)
|
||||
{
|
||||
Console.WriteLine($"{enemy.PokemonName} attacked {PokemonName}\t({PokemonHp} - {enemy.PokemonAttack} = 0)\n");
|
||||
PokemonHp = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
Console.WriteLine($"{enemy.PokemonName} attacked {PokemonName}\t({PokemonHp} - {enemy.PokemonAttack} = {PokemonHp - enemy.PokemonAttack})\n");
|
||||
PokemonHp -= enemy.PokemonAttack;
|
||||
}
|
||||
|
||||
round++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{0580ACC5-9C57-48B6-A97B-75103119F024}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Test</RootNamespace>
|
||||
<AssemblyName>Test</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MyDll, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\MyDll.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Binary file not shown.
Reference in New Issue
Block a user