-1
using System;
using System.Collections.Generic;

namespace Learning_C__Program
{
    class Program
    {
        static void Main(string[] args)
        {
            int enemyHealth = 1000;
            int playerHealth = 1000;

            string[] limbPicked = {"","","",""};

            string[] enemyTypes = {"Ogre","Beast","Dragon"};

            Random enemyPick = new Random();
            int pickEnemy = enemyPick.Next(2);

            // Below is the if statements for when an ogre is picked

            int i = 1;

            while(i == 1) {
                
                if (pickEnemy == 0||pickEnemy == 1||pickEnemy == 2) {

                    string enemyUsing;

                    if (pickEnemy == 0) {
                        enemyUsing = enemyTypes[0];
                    }
                    else if (pickEnemy == 1) {
                        enemyUsing = enemyTypes[1];
                    }
                    else {
                        enemyUsing = enemyTypes[2];
                    }

                    Console.WriteLine("You encounter an unhappy " + enemyUsing + "! It starts a fight!\nSelect a limb to hit: ");
                    limbPicked[0] = Convert.ToString(Console.ReadLine());

                    if (limbPicked[0] == "Head"||limbPicked[0] == "head"||limbPicked[0] == "Torso"||limbPicked[0] == "torso"||limbPicked[0] == "Arms"||limbPicked[0] == "arms"||limbPicked[0] == "Legs"||limbPicked[0] == "legs") {

                    Random hitAmount = new Random();
                    int damage1 = hitAmount.Next(1,300);

                    Console.WriteLine("You attempted to strike the " + enemyUsing + " in the " + limbPicked[0] + " doing " + damage1 + " damage to the " + enemyUsing + "! They now have " + (enemyHealth - damage1) + " health!");

                    enemyHealth = enemyHealth - damage1;

                    Random enemyHitAmount = new Random();
                    int damage2 = enemyHitAmount.Next(1,300);
                    
                    Console.WriteLine("The enemy attacks! They do " + damage2 + " damage to you! You now have " + (playerHealth - damage2) + " health!");

                    playerHealth = playerHealth - damage2;

                    if (playerHealth == 0) {

                         Random deathSentence = new Random();
                         int words = deathSentence.Next(7);

                         string[] wordsSaying = {"slain","slaughtered","murdered","defeated","beheaded","impaled","shredded"};

                            if (words == 0) {
                                Console.WriteLine("The enemy has slain you\nPress any key to exit");
                            }
                            else if (words == 1) {
                                Console.WriteLine("The enemy has slaughtered you\nPress any key to exit");
                            }
                            else if (words == 2) {
                                Console.WriteLine("The enemy has murdered you\nPress any key to exit");
                            }
                            else if (words == 3) {
                                Console.WriteLine("The enemy has defeated you\nPress any key to exit");
                            }
                            else if (words == 4) {
                                Console.WriteLine("The enemy has beheaded you\nPress any key to exit");
                            }
                            else if (words == 5) {
                                Console.WriteLine("The enemy has impaled you\nPress any key to exit");
                            }
                            else {
                                Console.WriteLine("The enemy has shredded you\nPress any key to exit");
                            }
                            
                            Console.ReadKey();
                            
                            if (enemyHealth == 0) {

                            Random deathSentence2 = new Random();
                            int words2 = deathSentence2.Next(7);

                            string[] wordsSaying2 = {"slain","slaughtered","murdered","defeated","beheaded","impaled","shredded"};

                            if (words2 == 0) {
                                Console.WriteLine("You have slain the enemy\nPress any key to exit");
                            }
                            else if (words2 == 1) {
                                Console.WriteLine("You have slaughtered the enemy\nPress any key to exit");
                            }
                            else if (words2 == 2) {
                                Console.WriteLine("You have murdered the enemy\nPress any key to exit");
                            }
                            else if (words2 == 3) {
                                Console.WriteLine("You have defeated the enemy\nPress any key to exit");
                            }
                            else if (words2 == 4) {
                                Console.WriteLine("You have beheaded the enemy\nPress any key to exit");
                            }
                            else if (words2 == 5) {
                                Console.WriteLine("You have impaled the enemy\nPress any key to exit");
                            }
                            else {
                                Console.WriteLine("You have shredded the enemy\nPress any key to exit");
                            }
                            
                            Console.ReadKey();

                        }

                    }
                    else {
                        Console.WriteLine("That is not one of the available limbs, please select one of the following:\nHead\nTorso\nArms\nLegs");
                    }                
                }
             break;

            }

            Console.ReadKey();

        }
    }
}
}

My code is starting, and then when I go to input the area I want to try to hit, it moves on to line 48, where it starts to print out "You attempted to strike the " + enemyUsing + " in the " etc But it types Y then ends for some reason! Please help!

Mihir Dave
  • 3,954
  • 1
  • 12
  • 28

1 Answers1

1

just remove break; at line 150, which exits the while (i == 1) loop

Also looks like you misplaced else block, it should be after checking user input, not after if (playerHealth == 0)

else
{
    Console.WriteLine("That is not one of the available limbs, please select one of the following:\nHead\nTorso\nArms\nLegs");
}

The location of the break; actually should be after one of your exit conditions

else
{
    Console.WriteLine("You have shredded the enemy\nPress any key to exit");
}

Console.ReadKey();
break; // exit while loop or return; if you want to stop game 
Yehor Androsov
  • 4,885
  • 2
  • 23
  • 40