Hi guys, i downloaded visual c# 2008 about a month ago and have been trying stuff out for myself.
I'm attempting to make a text based RPG, i made big progress but i'm stuck now.
Basically i want to show the player's HP in green whenever he has 51 to 100% of the maximum HP for his level, yellow from 26 - 50HP and red when below 25%.
My code shows the HP in green from 100% all the way down to 25%, going directly to red and bypassing yellow, how do i fix this?
here's the code.
if (ok.player > 51% ok.maxhp)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("{0}/{1} HP", ok.player, ok.maxhp);
Console.ForegroundColor = ConsoleColor.White;
}
else
if ((ok.player >= 26% ok.maxhp) && (ok.player <= 50% ok.maxhp))
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("{0}/{1} HP", ok.player, ok.maxhp);
Console.ForegroundColor = ConsoleColor.White;
}
else
if (ok.player < 25% ok.maxhp)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("{0}/{1} HP", ok.player, ok.maxhp);
Console.ForegroundColor = ConsoleColor.White;
}
a person in another forum gave me the following solution, but it didn't work, instead it showed the HP in green from 100 to 0% never changing color.
decimal one_percent = (decimal)(ok.maxhp / 100);
decimal value = (decimal)ok.player;
if (value > (one_percent * 51))
{
// ok.player is greater than 51% of ok.maxhp
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("{0}/{1} HP", ok.player, ok.maxhp);
Console.ForegroundColor = ConsoleColor.White;
}
else if (value >= (one_percent * 26) && value <= (one_percent * 50))
{
// ok.player is between 26% and 50% of ok.maxhp
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("{0}/{1} HP", ok.player, ok.maxhp);
Console.ForegroundColor = ConsoleColor.White;
}
else if (value < (one_percent * 25))
{
// ok.player is less than 25% of ok.maxhp
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("{0}/{1} HP", ok.player, ok.maxhp);
Console.ForegroundColor = ConsoleColor.White;
}