-1
Scanner reader = new Scanner(System.in);
    String continue;
    do {
        if (eHealth > 0 && pHealth > 0) {
            if (ranAway != true && stuck = true){
                stuck = false;
                System.out.println("You are now stuck with the monster forever. Good job.\n"
                + "Would you like to fight again?\n");
                continue = reader.nextLine();
                if ("Yes".equals(continue) || "yes".equals(continue)){
                    pHealth = 1500;
                    assignHealth();
                    Fight();
                }else if ("No".equals(continue) || "no".equals(continue)) {
                    System.exit(0);
                }
            }else if (ranAway = true && stuck != true) {
                ranAway = false;
                System.out.println("You ran away from your problems like the coward you are.\n"
                                    + "Do you want to fight again\n");
                continue = reader.nextLine();
                if ("Yes".equals(continue) || "yes".equals(continue)){
                    pHealth = 1500;
                    assignHealth();
                    Fight();
                }else if ("No".equals(continue) || "no".equals(continue)) {
                    System.exit(0);
                }
            }else {
                Fight();
            }
        }else if (eHealth > 0 && pHealth <= 0){
            System.out.println("Oh noes. You got de_stroyed by the monster! What a shame.\n"
                                + "Would you like to fight again?\n");
            continue = reader.nextLine();
            if ("Yes".equals(continue) || "yes".equals(continue)){
                    pHealth = 1500;
                    assignHealth();
                    Fight();
                }else if ("No".equals(continue) || "no".equals(continue)) {
                    System.exit(0);
                }
        }else if (eHealth <= 0 && pHealth > 0){
            System.out.println("Congrats! You killed the troll!\n"
                                + "Would you like to play again?\n");
            continue = reader.nextLine();
            if ("Yes".equals(continue) || "yes".equals(continue)){
                    pHealth = 1500;
                    assignHealth();
                    Fight();
                }else if ("No".equals(continue) || "no".equals(continue)) {
                    System.exit(0);
                }
        }
    }

This is the section throwing errors. The context is just a small fight against a troll. The option to restart is given. Some items will activate the booleans you end up seeing. The main lines that seem to be giving errors are the IF statements as well as the String continue;. How can I solve this?

assembler
  • 2,552
  • 8
  • 34
  • 65
  • 3
    **1)** `continue` is a reserved word, you can use a variable with that name, check [What is the “continue” keyword and how does it work in Java?](https://stackoverflow.com/questions/389741/what-is-the-continue-keyword-and-how-does-it-work-in-java) **2)** you have a `do` but no `while(condition);` – AxelH Nov 16 '17 at 21:06
  • 3
    `continue` is a keyword in Java - you can't use it as a variable name! – Nir Alfasi Nov 16 '17 at 21:08
  • Many errors there... – m0skit0 Nov 16 '17 at 21:15

1 Answers1

1
if (ranAway = true && stuck != true)

This condition is wrong ( "ranAway = true" is actually an assignment), and for this section you can simply state:

if (ranAway && !stuck)

as you probably know, you should have used "==" for the condition if it was necessary. I'm not sure if this fixes your issue because there's a lot of code missing, but it might be the problem with your program.

rick_rez
  • 26
  • 1