generated from admin/template
lab-03 done
This commit is contained in:
+159
-166
@@ -1,201 +1,194 @@
|
|||||||
//==================== Main
|
using System;
|
||||||
//==============================================
|
using HelpMethods;
|
||||||
IsReady();
|
|
||||||
//==================== System fun
|
|
||||||
//==============================================
|
|
||||||
static void PrintError(Exception e)
|
|
||||||
{
|
|
||||||
//Console.BackgroundColor = ConsoleColor.Gray;
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
|
||||||
Console.WriteLine($"Error: {e.Message}");
|
|
||||||
Console.ResetColor();
|
|
||||||
|
|
||||||
Console.WriteLine("Press any key to continue...\n");
|
namespace Test
|
||||||
Console.ReadKey();
|
|
||||||
Console.Clear();
|
|
||||||
}
|
|
||||||
static void ShowTask(byte number, bool isStart = false)
|
|
||||||
{
|
{
|
||||||
if (isStart == false)
|
internal class Program
|
||||||
{
|
{
|
||||||
Console.WriteLine("\nPress any key to continue...");
|
static void Main(string[] args)
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine($"Task №{number}");
|
|
||||||
}
|
|
||||||
static void Br(byte counter = 1)
|
|
||||||
{
|
{
|
||||||
for (byte i = 0; i < counter; i++)
|
byte roundNumber;
|
||||||
Console.WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ==================== Modul1 fun
|
|
||||||
// ==============================================
|
|
||||||
static void StartFight()
|
|
||||||
{
|
|
||||||
string
|
|
||||||
pokemonName1
|
|
||||||
,pokemonName2;
|
|
||||||
|
|
||||||
short
|
short
|
||||||
hp1
|
pokemon1Hp,
|
||||||
,hp2
|
pokemon2Hp,
|
||||||
,attack1
|
pokemon1Attack,
|
||||||
,attack2;
|
pokemon2Attack;
|
||||||
|
|
||||||
InputParams(out pokemonName1, out hp1, out attack1, out pokemonName2, out hp2, out attack2);
|
string
|
||||||
ShowTimeCounting();
|
pokemon1Name,
|
||||||
GetPokemonInfo(pokemonName1, hp1, attack1, pokemonName2, hp2, attack2);
|
pokemon2Name;
|
||||||
|
|
||||||
|
Battle(out pokemon1Hp,
|
||||||
|
out pokemon2Hp,
|
||||||
|
out pokemon1Attack,
|
||||||
|
out pokemon2Attack,
|
||||||
|
out roundNumber,
|
||||||
|
out pokemon1Name,
|
||||||
|
out pokemon2Name);
|
||||||
}
|
}
|
||||||
static void ShowTimeCounting()
|
|
||||||
|
/// <summary>
|
||||||
|
/// Метод для задания №3.
|
||||||
|
/// </summary>
|
||||||
|
static void Battle(out short pokemon1Hp,
|
||||||
|
out short pokemon2Hp,
|
||||||
|
out short pokemon1Attack,
|
||||||
|
out short pokemon2Attack,
|
||||||
|
out byte roundNumber,
|
||||||
|
out string pokemon1Name,
|
||||||
|
out string pokemon2Name,
|
||||||
|
byte startType = 0)
|
||||||
{
|
{
|
||||||
const byte counter = 3;
|
pokemon1Hp = 0;
|
||||||
const short ticks = 1000;
|
pokemon2Hp = 0;
|
||||||
|
pokemon1Attack = 0;
|
||||||
|
pokemon2Attack = 0;
|
||||||
|
roundNumber = 0;
|
||||||
|
|
||||||
Console.WriteLine("Ready!");
|
pokemon1Name = string.Empty;
|
||||||
for (byte i = 1; i <= counter; Console.Write($"\r{i++}..."))
|
pokemon2Name = string.Empty;
|
||||||
Thread.Sleep(ticks);
|
|
||||||
|
|
||||||
Br(2);
|
if (startType == 0)
|
||||||
Console.WriteLine("=== THE FIGHT BEGINS ===");
|
SetSeedData(out pokemon1Hp,
|
||||||
|
out pokemon2Hp,
|
||||||
|
out pokemon1Attack,
|
||||||
|
out pokemon2Attack,
|
||||||
|
out roundNumber,
|
||||||
|
out pokemon1Name,
|
||||||
|
out pokemon2Name);
|
||||||
|
// else: methods for initialization
|
||||||
|
|
||||||
}
|
if (!ReadyQuestion(pokemon1Hp,
|
||||||
static void GetPokemonInfo(string pokemonName1, short hp1, short attack1, string pokemonName2, short hp2, short attack2)
|
pokemon2Hp,
|
||||||
{
|
pokemon1Attack,
|
||||||
Console.WriteLine($"{pokemonName1} (HP: {hp1} | Attack: {attack1}) VS {pokemonName2} (HP: {hp2} | Attack: {attack2})");
|
pokemon2Attack,
|
||||||
}
|
pokemon1Name,
|
||||||
static void InputParams(out string pokemonName1, out short hp1, out short attack1, out string pokemonName2,
|
pokemon2Name))
|
||||||
out short hp2, out short attack2)
|
return;
|
||||||
{
|
|
||||||
const short
|
|
||||||
maxHp = 2000
|
|
||||||
,maxAttack = 500
|
|
||||||
,minHp = 0
|
|
||||||
,minAttack = 1;
|
|
||||||
|
|
||||||
|
string
|
||||||
|
WIN_P1 = $"Winner: {pokemon1Name}!",
|
||||||
Console.Write("Enter Pokemon name for player one!\nName1: ");
|
WIN_P2 = $"Winner: {pokemon2Name}!",
|
||||||
pokemonName1 = Console.ReadLine() ?? "Player1";
|
BATTLE_END = "=== The end of the battle ===\n";
|
||||||
|
|
||||||
if (pokemonName1 == string.Empty)
|
|
||||||
pokemonName1 = "Player1";
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
try
|
Console.WriteLine($"=== Round №{roundNumber} ===");
|
||||||
|
|
||||||
|
if (roundNumber % 2 == 1)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"{pokemon1Name} наносит {pokemon1Attack} урона по {pokemon2Name}!");
|
||||||
Console.Write("\nEnter the attack power for Pokemon1!\nAttack: ");
|
pokemon2Hp -= pokemon1Attack;
|
||||||
attack1 = short.Parse(Console.ReadLine());
|
if (pokemon2Hp < 0) pokemon2Hp = 0;
|
||||||
|
|
||||||
if (attack1 < minAttack || attack1 > maxAttack)
|
|
||||||
throw new Exception($"The attack can be between {minAttack} and {maxAttack}.");
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {PrintError(e);}
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{pokemon2Name} наносит {pokemon2Attack} урона по {pokemon1Name}!");
|
||||||
|
pokemon1Hp -= pokemon2Attack;
|
||||||
|
if (pokemon1Hp < 0) pokemon1Hp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true)
|
Console.WriteLine($"The round result: {pokemon1Name} HP: {pokemon1Hp} | {pokemon2Name} HP: {pokemon2Hp}\n");
|
||||||
|
roundNumber++;
|
||||||
|
|
||||||
|
if (pokemon2Hp < 1)
|
||||||
{
|
{
|
||||||
try
|
Console.WriteLine(BATTLE_END + WIN_P1);
|
||||||
{
|
|
||||||
Console.Write("\nEnter the number of hp for Pokemon1!\nHP: ");
|
|
||||||
hp1 = short.Parse(Console.ReadLine());
|
|
||||||
|
|
||||||
if (hp1 < minHp || hp1 > maxHp)
|
|
||||||
throw new Exception($"The hp can be between {minHp} and {maxHp}.");
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
catch (Exception e) {PrintError(e);}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Console.Clear();
|
|
||||||
|
|
||||||
|
|
||||||
Console.Write("Enter Pokemon name for player two!\nName2: ");
|
|
||||||
pokemonName2 = Console.ReadLine() ?? "Player2";
|
|
||||||
|
|
||||||
if (pokemonName2 == string.Empty)
|
|
||||||
pokemonName2 = "Player2";
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("\nEnter the attack power for Pokemon2!\nAttack: ");
|
|
||||||
attack2 = short.Parse(Console.ReadLine());
|
|
||||||
|
|
||||||
if (attack2 < minAttack || attack2 > maxAttack)
|
|
||||||
throw new Exception($"The attack can be between {minAttack} and {maxAttack}.");
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
catch (Exception e) {PrintError(e);}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("\nEnter the number of hp for Pokemon2!\nHP: ");
|
|
||||||
hp2 = short.Parse(Console.ReadLine());
|
|
||||||
|
|
||||||
if (hp2 < minHp || hp2 > maxHp)
|
|
||||||
throw new Exception($"The hp can be between {minHp} and {maxHp}.");
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
catch (Exception e) {PrintError(e);}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Console.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ==================== Modul2 fun
|
|
||||||
// ==============================================
|
|
||||||
static void IsReady()
|
|
||||||
{
|
|
||||||
if (IsCorrect())
|
|
||||||
{
|
|
||||||
StartFight();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (pokemon1Hp < 1)
|
||||||
Console.WriteLine("Are you giving up!");
|
|
||||||
}
|
|
||||||
static bool IsCorrect()
|
|
||||||
{
|
{
|
||||||
const byte
|
Console.WriteLine(BATTLE_END + WIN_P2);
|
||||||
fixValue1 = 0
|
return;
|
||||||
,fixValue2 = 1;
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
do
|
/// <summary>
|
||||||
|
/// Метод для задания №1.
|
||||||
|
/// </summary>
|
||||||
|
static void StartBattle(short pokemon1Hp,
|
||||||
|
short pokemon2Hp,
|
||||||
|
short pokemon1Attack,
|
||||||
|
short pokemon2Attack,
|
||||||
|
string pokemon1Name,
|
||||||
|
string pokemon2Name)
|
||||||
|
{
|
||||||
|
string message =
|
||||||
|
$@"=== The battle begins ===
|
||||||
|
{pokemon1Name} (HP: {pokemon1Hp} | Attack: {pokemon1Attack}) VS {pokemon2Name} (HP: {pokemon2Hp} | Attack: {pokemon2Attack})
|
||||||
|
";
|
||||||
|
|
||||||
|
TimeHelp.ShowTimer("Ready!");
|
||||||
|
Console.WriteLine(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Метод для задания №2.
|
||||||
|
/// </summary>
|
||||||
|
static bool ReadyQuestion(short pokemon1Hp,
|
||||||
|
short pokemon2Hp,
|
||||||
|
short pokemon1Attack,
|
||||||
|
short pokemon2Attack,
|
||||||
|
string pokemon1Name,
|
||||||
|
string pokemon2Name)
|
||||||
|
{
|
||||||
|
if (SetValue() == 1)
|
||||||
|
{
|
||||||
|
StartBattle(pokemon1Hp,
|
||||||
|
pokemon2Hp,
|
||||||
|
pokemon1Attack,
|
||||||
|
pokemon2Attack,
|
||||||
|
pokemon1Name,
|
||||||
|
pokemon2Name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("You canceled the battle!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static byte SetValue()
|
||||||
|
{
|
||||||
|
const string
|
||||||
|
MESSAGE = "You are ready to start the battle?\t[1 - \"Yes\" | 0 - \"No\"]\n[Player]: ",
|
||||||
|
ERROR = $"The value must be equal to 1 or 0";
|
||||||
|
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.Write("You are ready to start?\t[1 - Yes | 0 - No]\n[Player]: ");
|
Console.Write(MESSAGE);
|
||||||
byte isReady = byte.Parse(Console.ReadLine());
|
byte value = byte.Parse(Console.ReadLine());
|
||||||
|
|
||||||
if (isReady != fixValue1 && isReady != fixValue2)
|
if (value != 0 && value != 1)
|
||||||
throw new Exception($"Incorrect input. Value must be {fixValue1} or {fixValue2}.");
|
throw new Exception(ERROR);
|
||||||
|
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
|
|
||||||
if (isReady == fixValue1)
|
return value;
|
||||||
return false;
|
}
|
||||||
|
catch (Exception e) { SystemHelp.PrintError(e); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
static void SetSeedData(out short pokemon1Hp,
|
||||||
|
out short pokemon2Hp,
|
||||||
|
out short pokemon1Attack,
|
||||||
|
out short pokemon2Attack,
|
||||||
|
out byte roundNumber,
|
||||||
|
out string pokemon1Name,
|
||||||
|
out string pokemon2Name)
|
||||||
|
{
|
||||||
|
pokemon1Hp = 50;
|
||||||
|
pokemon2Hp = 55;
|
||||||
|
pokemon1Attack = 12;
|
||||||
|
pokemon2Attack = 10;
|
||||||
|
roundNumber = 1;
|
||||||
|
|
||||||
|
pokemon1Name = "Пикачу";
|
||||||
|
pokemon2Name = "Булбазавр";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {PrintError(e);}
|
|
||||||
} while (true);
|
|
||||||
}
|
}
|
||||||
@@ -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