Last active
February 10, 2024 09:54
-
-
Save tsk-arh/6aba4ee64cf651842b9cbf3abbe61c80 to your computer and use it in GitHub Desktop.
Гладиаторы урезанные
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Threading; | |
namespace ConsoleApp4 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Arena arena = new Arena(); | |
arena.Work(); | |
} | |
} | |
class Arena | |
{ | |
public void Work() | |
{ | |
DestriantFabric destriantFabric = new DestriantFabric(); | |
List<Fighter> fighters = new List<Fighter>(); | |
fighters.Add(new Warlord("Варик четкий")); | |
fighters.Add(destriantFabric.Create("Петрович пьяный")); | |
Console.WriteLine("Выбрать первого бойца:"); | |
Fighter firstFighter = GetFighter(fighters); | |
Console.WriteLine("Выбрать второго бойца:"); | |
Fighter secondFighter = GetFighter(fighters); | |
Console.WriteLine("\n\nНачинается битва!\n\n"); | |
FightUntilDeath(firstFighter, secondFighter); | |
Console.ReadLine(); | |
} | |
private void ShowAllFighters(List<Fighter> fighters) | |
{ | |
for (int i = 0; i < fighters.Count; i++) | |
{ | |
int fighterNumber = i + 1; | |
Console.WriteLine(new string('#', 25)); | |
Console.WriteLine($"{fighterNumber}. Боец: "); | |
fighters[i].ShowStats(); | |
} | |
} | |
private Fighter GetFighter(List<Fighter> fighters) | |
{ | |
while (true) | |
{ | |
Console.Clear(); | |
ShowAllFighters(fighters); | |
Console.WriteLine("\nВведите номер бойца, которого хотите выбрать:"); | |
if (int.TryParse(Console.ReadLine(), out int userInput) && userInput > 0 && userInput <= fighters.Count) | |
{ | |
int fighterIndex = userInput - 1; | |
Fighter fighter = fighters[fighterIndex]; | |
fighters.RemoveAt(fighterIndex); | |
Console.WriteLine($"\n{fighter.Name} выбран для боя"); | |
return fighter; | |
} | |
else | |
{ | |
Console.WriteLine("Необходимо вводить корректный номер бойца из списка доступных"); | |
} | |
} | |
} | |
private void FightUntilDeath(Fighter firstFighter, Fighter secondFighter) | |
{ | |
while (firstFighter.Health > 0 && secondFighter.Health > 0) | |
{ | |
int attackTimePointsScore = 100; | |
firstFighter.TryAttack(attackTimePointsScore, secondFighter); | |
secondFighter.TryAttack(attackTimePointsScore, firstFighter); | |
Thread.Sleep(attackTimePointsScore); | |
} | |
WriteWinner(firstFighter, secondFighter); | |
} | |
private void WriteWinner(Fighter firstFighter, Fighter secondFighter) | |
{ | |
if (firstFighter.Health > 0) | |
{ | |
WriteWinnerFighter(firstFighter); | |
} | |
else if (secondFighter.Health > 0) | |
{ | |
WriteWinnerFighter(secondFighter); | |
} | |
else | |
{ | |
Console.WriteLine("Никто не победил"); | |
} | |
} | |
private void WriteWinnerFighter(Fighter fighter) | |
{ | |
Console.WriteLine("Победил " + fighter.Name); | |
fighter.ShowStats(); | |
} | |
} | |
class Fighter | |
{ | |
protected string Description; | |
protected int Damage; | |
public Fighter(string name, string description, int health, int damage) | |
{ | |
Name = name; | |
Description = description; | |
Health = health; | |
Damage = damage; | |
} | |
public string Name { get; private set; } | |
public int Health { get; protected set; } | |
public void ShowStats() | |
{ | |
string frame = new string('-', 25); | |
Console.WriteLine(frame + $"" + | |
$"\nИмя бойца: {Name} " + | |
$"\nОписание класса: {Description} " + | |
$"\nТекущее здоровье: {Health} \nУрон: {Damage} " + | |
$"\n" + frame); | |
} | |
public virtual bool TakeDamage(int attackDamage) | |
{ | |
int damageTaken = attackDamage; | |
if (damageTaken > 0) | |
{ | |
Console.WriteLine($"\n{Name} ({Health} здоровья) получает {damageTaken} урона\n"); | |
Health -= damageTaken; | |
} | |
else | |
{ | |
Console.WriteLine($"{Name} Ухмыляется. Столь жалкая атака не способна пробить его броню"); | |
} | |
return true; | |
} | |
public virtual bool TryAttack(int attackTimePoints, Fighter fighter) | |
{ | |
Console.WriteLine($"{Name} проводит атаку"); | |
fighter.TakeDamage(Damage); | |
return true; | |
} | |
} | |
class Warlord : Fighter | |
{ | |
private static string s_description = "Варлорд имеет повышенный рейтинг атаки, повышенное здоровье и шанс уклонения"; | |
private static int s_health = 150; | |
private static int s_damage = 20; | |
public Warlord(string name) : base(name, s_description, s_health, s_damage) { } | |
} | |
class Destriant : Fighter | |
{ | |
private int _countDamageTakenTimes = 0; | |
private int _healAbility = 20; | |
public Destriant(string name, string description, int health, int damage) : base(name, description, health, damage) { } | |
public override bool TakeDamage(int attackDamage) | |
{ | |
if (base.TakeDamage(attackDamage)) | |
{ | |
_countDamageTakenTimes++; | |
if (_countDamageTakenTimes >= 4) | |
{ | |
Console.WriteLine($"{Name} Лечится на {_healAbility} здоровья"); | |
Health += _healAbility; | |
_countDamageTakenTimes = 0; | |
} | |
return true; | |
} | |
return false; | |
} | |
} | |
abstract class FighterFabric | |
{ | |
public abstract Fighter Create(string name); | |
} | |
class DestriantFabric : FighterFabric | |
{ | |
private string s_description = "Дестриант имеет повышенный рейтинг атаки, повышенную защиту и повышенный урон, а также способность к исцелению"; | |
private int s_health = 100; | |
private int s_damage = 25; | |
public override Fighter Create(string name) | |
{ | |
Fighter fighter = new Destriant(name, s_description, s_health, s_damage); | |
return fighter; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment