Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active May 16, 2023 16:02
Show Gist options
  • Save Strelok78/5623bc8a90c2251f21dc04f61932a55f to your computer and use it in GitHub Desktop.
Save Strelok78/5623bc8a90c2251f21dc04f61932a55f to your computer and use it in GitHub Desktop.
Simple fighting console menu
namespace MyCode
{
internal class Program
{
static void Main(string[] args)
{
const string CommandExit = "0";
const string CommandHeroHP = "1";
const string CommandHeroDamage = "2";
const string CommandEnemyHP = "3";
const string CommandEnemyDamage = "4";;
const string CommandStartFight = "5";
const string CommandMenu = "9";
Random random = new Random();
int maxRandomValue = 100;
int minRandomValue = 1;
int heroHP = 0;
int heroDamage = 0;
int enemyHP = 0;
int enemyDamage = 0;
string enteredCode;
bool isActive = true;
Console.WriteLine("You are in fight simulator!\n" +
"Enter number according your need: \n" +
"By default stats are at 0 \n" +
"Stat that equal 0 will be randomized \n\n" +
$"{CommandHeroHP} - Set your character health \n" +
$"{CommandHeroDamage} - Set your character damage \n" +
$"{CommandEnemyHP} - Set your enemy health \n" +
$"{CommandEnemyDamage} - Set your enemy damage \n" +
$"{CommandStartFight} - Fight! \n" +
$"{CommandMenu} - Show menu\n" +
$"{CommandExit} - Exit \n" +
"\nEnter command: ");
while (isActive)
{
enteredCode = Console.ReadLine();
switch (enteredCode)
{
case CommandExit:
Console.WriteLine("Exit");
isActive = false;
break;
case CommandHeroHP:
Console.WriteLine("Enter amount of your character HP: ");
heroHP = int.Parse(Console.ReadLine());
Console.WriteLine("\nEnter next command: ");
break;
case CommandHeroDamage:
Console.WriteLine("Enter your character damage power: ");
heroDamage = int.Parse(Console.ReadLine());
Console.WriteLine("\nEnter next command: ");
break;
case CommandEnemyHP:
Console.WriteLine("Enter amount of your enemy HP: ");
enemyHP = int.Parse(Console.ReadLine());
Console.WriteLine("\nEnter next command: ");
break;
case CommandEnemyDamage:
Console.WriteLine("Enter your enemy damage power: ");
enemyDamage = int.Parse(Console.ReadLine());
Console.WriteLine("\nEnter next command: ");
break;
case CommandMenu:
Console.WriteLine("Enter number according your need: \n" +
"By default stats are at 0 \n" +
"Stat that equal 0 will be randomized \n" +
$"{CommandHeroHP} - Set your character health \n" +
$"{CommandHeroDamage} - Set your cgaracter damage \n" +
$"{CommandEnemyHP} - Set your enemy health \n" +
$"{CommandEnemyDamage} - Set your enemy damage \n" +
$"{CommandStartFight} - Fight! \n" +
$"{CommandMenu} - Show menu\n" +
$"{CommandExit} - Exit \n" +
"\nEnter command: ");
break;
case CommandStartFight:
int round = 0;
int zero = 0;
if (heroHP == zero)
{
heroHP = random.Next(minRandomValue, maxRandomValue);
}
if (heroDamage == zero)
{
heroDamage = random.Next(minRandomValue, maxRandomValue);
}
if (enemyHP == zero)
{
enemyHP = random.Next(minRandomValue, maxRandomValue);
}
if (enemyDamage == zero)
{
enemyDamage = random.Next(minRandomValue, maxRandomValue);
}
Console.WriteLine("FIGHT!");
while (heroHP != zero || enemyHP != zero)
{
round++;
Console.WriteLine($"Round: {round}");
heroHP -= enemyDamage;
enemyHP -= heroDamage;
Console.WriteLine($"Hero HP: {heroHP}, Enemy HP: {enemyHP}\n");
if (heroHP <= zero)
{
Console.WriteLine("Hero died! You lose!");
Console.WriteLine("Start new game!\n");
heroHP = zero;
enemyHP = zero;
heroDamage = zero;
enemyDamage = zero;
Console.WriteLine($"{CommandMenu} - Show menu\n");
break;
}
if (enemyHP <= zero && heroHP > zero)
{
Console.WriteLine("You win! Enemy died!");
Console.WriteLine("Start new game!\n");
heroHP = zero;
enemyHP = zero;
heroDamage = zero;
enemyDamage = zero;
Console.WriteLine($"{CommandMenu} - Show menu\n");
break;
}
}
break;
default:
Console.WriteLine("Error");
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment