• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C# Brain Hurts: New to C# and cannot work out why this isn't working

Nocturnal_Toker

New Coder
So I'm new to C# by about a week and a half.

I have managed to make myself a half made custom Pokemon game but for some reason it displays the hud but doesnt display the attack after if anyone could give me some pointers to get this working that would be fantastic.

thank you :)

Note: The Damage section is not finished yet so just ignore that section
int userhealth = 100;
int enemyhealth = 100;
Console.WriteLine("Trainer Name: " + userName);
Console.WriteLine("Your Pokemon: " + selectedPokemon);
Console.WriteLine(selectedPokemon + ": " + (char)3 + " Is: " + userhealth);
Console.WriteLine("Enemy: " + (char)3 + " Is: " + enemyhealth);
Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
Random Damage = new Random();

int damage;
//string selectedAttack;
int attackSelect;
attackSelect = Convert.ToInt32(Console.ReadLine()); <--- This seems to stop the console from writing the next line!


while (userhealth >= 0 && enemyhealth >= 0)

{
if (attackSelect == 1)
{

Console.WriteLine("Choose Attack: ");
Console.WriteLine("1: Growl: Lowers the Target's Attack by One HP");
Console.WriteLine("2: Thunder Shock: Deals damage and has a 10HP");
Console.WriteLine("3: Double Kick: Hits twice in one turn");
Console.WriteLine("4: Quick Attack: Inflicts regular damage with no additional effect");
Console.WriteLine("5: Thunder: Deals 20 HP Damage ");
Console.ReadKey();
damage = Damage.Next(1, 10);


}

1602427117535.png
It prints like this


but should look like this

1602427178382.png
 

Krusty the Senile

Active Coder
I've moved the ReadLine() to within the while loop, but maybe there's a better place to put it in that loop, depending on wha you want the order of things to be. Does this help?

Code:
int userhealth = 100;
int enemyhealth = 100;
Console.WriteLine("Trainer Name: " + userName);
Console.WriteLine("Your Pokemon: " + selectedPokemon);
Console.WriteLine(selectedPokemon + ": " + (char)3 + " Is: " + userhealth);
Console.WriteLine("Enemy: " + (char)3 + " Is: " + enemyhealth);
Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
Random Damage = new Random();

int damage;
//string selectedAttack;
int attackSelect;
// attackSelect = Convert.ToInt32(Console.ReadLine()); // <--- This seems to stop the console from writing the next line!

while (userhealth >= 0 && enemyhealth >= 0)
{
    attackSelect = Convert.ToInt32(Console.ReadLine()); // <--- Krusty: moved this to here
    Console.WriteLine("attackSelect: " + attackSelect); // Krusty: debug statement to confirm value.
    if (attackSelect == 1)
    {
        Console.WriteLine("Choose Attack: ");
        Console.WriteLine("1: Growl: Lowers the Target's Attack by One HP");
        Console.WriteLine("2: Thunder Shock: Deals damage and has a 10HP");
        Console.WriteLine("3: Double Kick: Hits twice in one turn");
        Console.WriteLine("4: Quick Attack: Inflicts regular damage with no additional effect");
        Console.WriteLine("5: Thunder: Deals 20 HP Damage ");
        Console.ReadKey();
        damage = Damage.Next(1, 10);
    }
}
 
Top Bottom