Skip to content

Instantly share code, notes, and snippets.

@IvanEnginer
Created September 1, 2024 15:07
Show Gist options
  • Select an option

  • Save IvanEnginer/9b5b75c177643266a0b8c2a5eb7a5540 to your computer and use it in GitHub Desktop.

Select an option

Save IvanEnginer/9b5b75c177643266a0b8c2a5eb7a5540 to your computer and use it in GitHub Desktop.
using System;
namespace HW_03_2
{
class Boss
{
public int Health { get;private set; }
public bool IsLive { get; private set; }
private int _minHealth = 10;
private int _maxHealth = 100;
private Random _random = new Random();
public Boss()
{
Health = _random.Next(_minHealth, _maxHealth);
IsLive = true;
}
public void TakeDamage(int damage)
{
Health -= damage;
if (Health <= 0)
{
IsLive = false;
}
}
}
class Player
{
private int _baseDamage = 1;
private int _multiplicationLightAttack = 1;
private int _multiplicationMediumAttack = 5;
private int _multiplicationHardAttack = 10;
public int AttackLight()
{
return _baseDamage * _multiplicationLightAttack;
}
public int AttackMedium()
{
return _baseDamage * _multiplicationMediumAttack;
}
public int AttackHard()
{
return _baseDamage * _multiplicationHardAttack;
}
}
class Battle
{
private Player _player;
private Boss _boss;
private bool _isFight = true;
private const string _lightAttackCommand = "1";
private const string _mediumAttackCommand = "2";
private const string _hardAttackCommand = "3";
public Battle(Player player, Boss boss)
{
_player = player;
_boss = boss;
}
public void Fight()
{
Console.WriteLine($"Перед тобой босс, у него {_boss.Health} здоровья");
while (_isFight)
{
Console.WriteLine($"У боса {_boss.Health} здоровья");
Console.WriteLine("Какую атаку желаете проветси?");
Console.WriteLine($"{_lightAttackCommand} - легкая атака ({_player.AttackLight()})");
Console.WriteLine($"{_mediumAttackCommand} - средняя атака ({_player.AttackMedium()})");
Console.WriteLine($"{_hardAttackCommand} - сильная атака ({_player.AttackHard()})");
string userInput = Console.ReadLine();
switch (userInput)
{
case _lightAttackCommand:
_boss.TakeDamage(_player.AttackLight());
break;
case _mediumAttackCommand:
_boss.TakeDamage(_player.AttackMedium());
break;
case _hardAttackCommand:
_boss.TakeDamage(_player.AttackHard());
break;
default:
Console.WriteLine("Неверная команда, попробуйте еще раз");
continue;
}
Console.Clear();
if (!_boss.IsLive)
{
Console.WriteLine("Вы победили, босс повержен");
_isFight = false;
}
}
}
}
internal class Program
{
static void Main(string[] args)
{
Player player = new Player();
Boss boss = new Boss();
Battle battle = new Battle(player, boss);
battle.Fight();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment