Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active April 21, 2025 15:19
Show Gist options
  • Select an option

  • Save Strelok78/89f2f20256a2ade5082a9f72f958b0ea to your computer and use it in GitHub Desktop.

Select an option

Save Strelok78/89f2f20256a2ade5082a9f72f958b0ea to your computer and use it in GitHub Desktop.
Boss fight
using System.Collections;
using System.Diagnostics;
namespace iJuniorPractice;
class Program
{
static void Main(string[] args)
{
const int PlayerBaseAttack = 1;
const int PlayerFireBall = 2;
const int PlayerExplosionAttack = 3;
const int PlayerHealing = 4;
Random random = new Random();
int minBossHp = 10;
int maxBossHp = 20;
int minBossDamage = 10;
int maxBossDamage = 20;
int bossHp = random.Next(minBossHp, maxBossHp);
int bossDamage;
int minPlayerHp = 50;
int maxPlayerHp = 100;
int minPlayerMp = 10;
int maxPlayerMp = 25;
int playerHp = random.Next(minPlayerHp, maxPlayerHp);
int playerMp = random.Next(minPlayerMp, maxPlayerMp);
int playerBaseAttackDamage = 1;
int playerFireBallDamage = 2;
int playerExplosionDamage = 3;
int playerHealingValue = 1;
int manaPerSkill = 3;
int healCount = 5;
string playerMenuText = $"{PlayerBaseAttack} - base attack ({playerBaseAttackDamage} damage)\n" +
$"{PlayerFireBall} - fire ball attack ({playerFireBallDamage} damage)\n" +
$"{PlayerExplosionAttack} - explosion attack ({playerExplosionDamage} damage)\n" +
$"{PlayerHealing} - healing ({playerHealingValue} healing power)\n";
while (bossHp > 0 && playerHp > 0)
{
Console.Clear();
Console.WriteLine(playerMenuText);
Console.WriteLine("Boss HP = {0}\n" +
"Player HP = {1} (max:{2})\n" +
"Player MP = {3} (max: {4})", bossHp, playerHp, maxPlayerHp, playerMp, maxPlayerMp);
Console.WriteLine("Player healing skill count: {0}", healCount);
Console.Write("Pick your action: ");
int.TryParse(Console.ReadLine(), out int playerInput);
switch (playerInput)
{
case PlayerBaseAttack:
Console.WriteLine("Ypu use Base Attack");
bossHp -= playerBaseAttackDamage;
playerMp -= manaPerSkill;
break;
case PlayerFireBall:
Console.WriteLine("Ypu use Fire ball Attack");
bossHp -= playerFireBallDamage;
playerMp -= manaPerSkill;
break;
case PlayerExplosionAttack:
Console.WriteLine("Ypu use Explosion Attack");
bossHp -= playerExplosionDamage;
playerMp -= manaPerSkill;
break;
case PlayerHealing:
Console.WriteLine("Ypu use Healing");
if (healCount > 0)
{
healCount--;
if (playerHp < maxPlayerHp)
{
int healValue = playerHealingValue + playerHp;
playerHp = maxPlayerHp < healValue ? maxPlayerHp : healValue;
}
if (playerMp < maxPlayerMp)
{
int healValue = playerHealingValue + playerMp;
playerMp = maxPlayerHp < healValue ? maxPlayerMp : healValue;
}
}
else
{
Console.WriteLine("You have {0} healing skill left, you lost your action!", healCount);
}
break;
default:
Console.WriteLine("Incorrect command, you miss your action!");
break;
}
if (bossHp > 0)
{
bossDamage = random.Next(minBossDamage, maxBossDamage);
playerHp -= bossDamage;
Console.WriteLine("You get {0} damage from boss attack", bossDamage);
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
if (bossHp > 0)
{
Console.WriteLine("You lose!");
}
else
{
Console.WriteLine("You win!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment