Need help with a bug
Hi, im currently making one of my exercises and i am stuck on a bug. Im making a bossfight thing based on random numbers if it is a critical damage or not. The bug im stuck is the one on the picture. it seems that the damage goes to 200 but the max damage is 100 when critical and 50 when normal. does anyone see the mistake i made?
my code:
class Program
{
static void Main()
{
int attack = 50;
double critChance = 0.33;
int bossHP = 1000;
Random damage = new();
int attackCalc = attack;
do
{
double chance = damage.NextDouble();
if (chance < critChance)
{
attackCalc *= 2;
}
bossHP -= attackCalc;
if (bossHP < 0)
{
bossHP = 0;
}
Console.WriteLine($"Boss HP: {bossHP}");
Console.WriteLine($"Damage: {attackCalc}");
}
while (bossHP > 0);
Console.WriteLine("Boss defeated");
}
}
my code:
class Program
{
static void Main()
{
int attack = 50;
double critChance = 0.33;
int bossHP = 1000;
Random damage = new();
int attackCalc = attack;
do
{
double chance = damage.NextDouble();
if (chance < critChance)
{
attackCalc *= 2;
}
bossHP -= attackCalc;
if (bossHP < 0)
{
bossHP = 0;
}
Console.WriteLine($"Boss HP: {bossHP}");
Console.WriteLine($"Damage: {attackCalc}");
}
while (bossHP > 0);
Console.WriteLine("Boss defeated");
}
}
