Last active
August 27, 2023 20:54
-
-
Save ShamilAitov/a65dcacb4c60da2b6b79c4f6b561f32d 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; | |
namespace ООП10Задание | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Battle battle = new Battle(); | |
battle.Play(); | |
} | |
} | |
class Warrior | |
{ | |
public Warrior(string name, int armor, int damage, int healt) | |
{ | |
Name = name; | |
Armor = armor; | |
Damage = damage; | |
Health = healt; | |
} | |
public string Name { get; private set; } | |
public int Armor { get; private set; } | |
public int Damage { get; private set; } | |
public int Health { get; private set; } | |
public bool IsAlive => Health > 0; | |
public void ShowStats() | |
{ | |
Console.WriteLine($"{Name}: Здоровье - {Health}, Брони - {Armor}, Урон - {Damage}"); | |
} | |
public void ShowCurrentStats() | |
{ | |
Console.WriteLine($"Боец - {Name}: Здоровье - {Health}"); | |
} | |
public void TakeDamage(int damage) | |
{ | |
int specificsArmor = 2; | |
if (Armor > 0) | |
{ | |
Armor -= damage / specificsArmor; | |
Health -= damage / specificsArmor; | |
} | |
else | |
{ | |
Health -= damage; | |
} | |
} | |
} | |
class Platoon | |
{ | |
private List<Warrior> _warriors = new List<Warrior>(); | |
public Platoon(List<Warrior> warriors) | |
{ | |
_warriors = warriors; | |
} | |
public bool FightersRemained => _warriors.Count > 0; | |
public void ShowWarriors() | |
{ | |
for (int i = 0; i < _warriors.Count; i++) | |
{ | |
_warriors[i].ShowStats(); | |
} | |
} | |
public void Attack(Platoon platoon) | |
{ | |
platoon.TakeDamage(_warriors); | |
} | |
public void TakeDamage(List<Warrior> enemyWarriors) | |
{ | |
if (enemyWarriors.Count > 0) | |
{ | |
Warrior warrior = _warriors[0]; | |
Warrior enemyWarrior = enemyWarriors[0]; | |
warrior.TakeDamage(enemyWarrior.Damage); | |
Console.Write($"{enemyWarrior.Name} - нанест урон {enemyWarrior.Damage} -> "); | |
warrior.ShowCurrentStats(); | |
if (warrior.IsAlive == false) | |
{ | |
Console.WriteLine($"{warrior.Name} - ушел в нокаут!"); | |
_warriors.Remove(warrior); | |
if (_warriors.Count > 0) | |
{ | |
warrior.ShowStats(); | |
Console.WriteLine($" || пришел\n"); | |
} | |
} | |
} | |
} | |
} | |
class Battle | |
{ | |
private List<Platoon> _platoons = new List<Platoon>(); | |
private Platoon _leftPlatoon; | |
private Platoon _rightPlatoon; | |
public Battle() | |
{ | |
CreatePlatoon(); | |
} | |
public void Play() | |
{ | |
Console.WriteLine($"Привет, ты попал на стрелку, у нас есть {_platoons.Count} взвода:\n"); | |
ShowPlatoons(); | |
Fight(); | |
} | |
private void CreatePlatoon() | |
{ | |
_platoons.Add(new Platoon(FillWarriors())); | |
_platoons.Add(new Platoon(FillWarriors())); | |
} | |
private List<Warrior> FillWarriors() | |
{ | |
List<Warrior> warriors = new List<Warrior>(); | |
List<Warrior> reserve = new List<Warrior>() | |
{ new Warrior("Боксер", 100,70,100), new Warrior("Борец", 90,80,100), new Warrior("Кикер", 70,70,100), | |
new Warrior("Колхозник", 30,30,100), new Warrior("Каратист", 60,60,100), new Warrior("Самбист", 100,90,100)}; | |
int minWarriors = 6; | |
int maxWarriors = 10; | |
int countWarriors = UserUtils.GetRandomNumber(minWarriors, maxWarriors); | |
int numberWarriors; | |
for (int i = 0; i < countWarriors; i++) | |
{ | |
numberWarriors = UserUtils.GetRandomNumber(reserve.Count); | |
warriors.Add(reserve[numberWarriors]); | |
} | |
return warriors; | |
} | |
private void ShowPlatoons() | |
{ | |
for (int i = 0; i < _platoons.Count; i++) | |
{ | |
_platoons[i].ShowWarriors(); | |
Console.WriteLine(); | |
} | |
} | |
private void Fight() | |
{ | |
_leftPlatoon = _platoons[0]; | |
_rightPlatoon = _platoons[1]; | |
while (_leftPlatoon.FightersRemained && _rightPlatoon.FightersRemained) | |
{ | |
_leftPlatoon.Attack(_rightPlatoon); | |
_rightPlatoon.Attack(_leftPlatoon); | |
} | |
if (_leftPlatoon.FightersRemained == false) | |
{ | |
Console.WriteLine("Правый взвод победил"); | |
} | |
else if (_rightPlatoon.FightersRemained == false) | |
{ | |
Console.WriteLine("Левый взвод победил"); | |
} | |
else | |
{ | |
Console.WriteLine("Ничья"); | |
} | |
} | |
} | |
class UserUtils | |
{ | |
private static Random _random = new Random(); | |
public static int GetRandomNumber(int min, int max) | |
{ | |
return _random.Next(min, max); | |
} | |
public static int GetRandomNumber(int max) | |
{ | |
return _random.Next(max); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment