generated from admin/template
lab-02 done.
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,240 @@
|
||||
using System;
|
||||
using HelpMethods;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
short initialBalance = 1500;
|
||||
|
||||
PokemonLeveling();
|
||||
BuyPotion(initialBalance);
|
||||
ShowCondition();
|
||||
TUI();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод для задания №1.
|
||||
/// </summary>
|
||||
static void PokemonLeveling()
|
||||
{
|
||||
const sbyte MARGIN_1 = -16;
|
||||
|
||||
short pokemonAttack = SetPokemonAttack();
|
||||
byte ernedLevels = LevelsRequest();
|
||||
|
||||
string message =
|
||||
$@"=== Pokemon leveling ===
|
||||
{"Initial attack:",MARGIN_1}{pokemonAttack}
|
||||
{"Earned levels:",MARGIN_1}{ernedLevels}
|
||||
|
||||
Final attack: {pokemonAttack + ernedLevels * 5}
|
||||
------------------------
|
||||
";
|
||||
|
||||
Console.WriteLine(message);
|
||||
SystemHelp.Waiting(true);
|
||||
|
||||
|
||||
static short SetPokemonAttack()
|
||||
{
|
||||
const short
|
||||
MAX_ATTACK = 250
|
||||
, MIN_ATTACK = 1;
|
||||
|
||||
string ERROR = $"The attack power must be between {MIN_ATTACK} and {MAX_ATTACK}.";
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write("Set the attack strength.\nAttack strength: ");
|
||||
short attack = short.Parse(Console.ReadLine());
|
||||
|
||||
if (attack < MIN_ATTACK || attack > MAX_ATTACK)
|
||||
throw new Exception(ERROR);
|
||||
|
||||
Console.Clear();
|
||||
|
||||
return attack;
|
||||
}
|
||||
catch (Exception e) { SystemHelp.PrintError(e); }
|
||||
}
|
||||
}
|
||||
static byte LevelsRequest()
|
||||
{
|
||||
const short MAX_COUNT = 5;
|
||||
|
||||
string ERROR = $"The number of levels cannot exceed {MAX_COUNT}.";
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write("How many levels have been earned?\nCount: ");
|
||||
byte lvl = byte.Parse(Console.ReadLine());
|
||||
|
||||
if (lvl > MAX_COUNT)
|
||||
throw new Exception(ERROR);
|
||||
|
||||
Console.Clear();
|
||||
|
||||
return lvl;
|
||||
}
|
||||
catch (Exception e) { SystemHelp.PrintError(e); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод для задания №2.
|
||||
/// </summary>
|
||||
/// <param name="balance"></param>
|
||||
static void BuyPotion(short balance)
|
||||
{
|
||||
const byte COST_POTION = 200;
|
||||
|
||||
byte countPotions = GetCountPotions(balance, COST_POTION);
|
||||
PrintCheque(balance, countPotions, COST_POTION);
|
||||
SystemHelp.Waiting(true);
|
||||
|
||||
|
||||
static byte GetCountPotions(short balance, byte costPotion)
|
||||
{
|
||||
const string ERROR = "The purchase amount cannot exceed your balance.";
|
||||
string message = $"Your balance: {balance}\nHow many potions do you want to buy?\nCount: ";
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write(message);
|
||||
byte count = byte.Parse(Console.ReadLine());
|
||||
|
||||
if (balance - costPotion * count < 0)
|
||||
throw new Exception(ERROR);
|
||||
|
||||
return count;
|
||||
}
|
||||
catch (Exception e) { SystemHelp.PrintError(e); }
|
||||
}
|
||||
}
|
||||
static short PrintCheque(short balance, byte countPotions, byte costPotion)
|
||||
{
|
||||
const sbyte MARGIN_1 = -10;
|
||||
|
||||
string cheque =
|
||||
$@"
|
||||
====== Cheque ======
|
||||
{"Balance:",MARGIN_1}{balance}
|
||||
{"Purchase:",MARGIN_1}{costPotion} X{countPotions}
|
||||
Amount to be paid:{costPotion * countPotions}
|
||||
|
||||
Remains:{balance - costPotion * countPotions}
|
||||
---------------------
|
||||
|
||||
";
|
||||
|
||||
Console.Write(cheque);
|
||||
|
||||
return (short)(balance - costPotion * countPotions);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод для задания №3.
|
||||
/// </summary>
|
||||
static void ShowCondition()
|
||||
{
|
||||
const string
|
||||
MESSAGE_1 = "Pokemon lost consciousness!"
|
||||
, MESSAGE_2 = "The Pokemon is in critical condition!"
|
||||
, MESSAGE_3 = "The Pokemon is wounded!"
|
||||
, MESSAGE_4 = "The Pokemon has full HP!";
|
||||
|
||||
short pokemonHp = GetPokemonHp();
|
||||
|
||||
if (pokemonHp == 0)
|
||||
Console.WriteLine(MESSAGE_1);
|
||||
else if (pokemonHp < 21)
|
||||
Console.WriteLine(MESSAGE_2);
|
||||
else if (pokemonHp < 51)
|
||||
Console.WriteLine(MESSAGE_3);
|
||||
else
|
||||
Console.WriteLine(MESSAGE_4);
|
||||
|
||||
StringHelp.Br();
|
||||
|
||||
SystemHelp.Waiting(true);
|
||||
|
||||
static short GetPokemonHp()
|
||||
{
|
||||
const short
|
||||
MIN_HP = 0
|
||||
, MAX_HP = 5000;
|
||||
|
||||
string ERROR = $"Hp should be between {MIN_HP} and {MAX_HP}";
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write("Enter the number of HP.\nHP: ");
|
||||
short hp = short.Parse(Console.ReadLine());
|
||||
|
||||
if (hp <MIN_HP || hp > MAX_HP)
|
||||
throw new Exception(ERROR);
|
||||
|
||||
return hp;
|
||||
}
|
||||
catch (Exception e) { SystemHelp.PrintError(e); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод для задания №4.
|
||||
/// </summary>
|
||||
static void TUI()
|
||||
{
|
||||
const string hotBar =
|
||||
@"
|
||||
====== Actions ======
|
||||
Attack [1]
|
||||
Backpack [2]
|
||||
Change the Pokemon [3]
|
||||
Escape [4]
|
||||
-----------------------
|
||||
|
||||
";
|
||||
|
||||
Console.Write(hotBar);
|
||||
|
||||
ModuleAction(Console.ReadLine() ?? String.Empty);
|
||||
|
||||
StringHelp.Br();
|
||||
|
||||
static void ModuleAction(string action)
|
||||
{
|
||||
const string
|
||||
ACTION_1 = "The Pokemon delivers a quick strike!"
|
||||
, ACTION_2 = "You open the backpack!"
|
||||
, ACTION_3 = "You choose other Pokemon!"
|
||||
, ACTION_4 = "You escape!"
|
||||
, DEFAULT_ACTION = "You didn’t do anything!";
|
||||
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case "1": Console.WriteLine(ACTION_1); break;
|
||||
case "2": Console.WriteLine(ACTION_2); break;
|
||||
case "3": Console.WriteLine(ACTION_3); break;
|
||||
case "4": Console.WriteLine(ACTION_4); break;
|
||||
default: Console.WriteLine(DEFAULT_ACTION); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user