java - 一点文字游戏

标签 java compiler-errors

我是一个完全的Java新手,在过去几天的业余时间里,我一直在做一个小型游戏,很有趣。

我的问题是,当我尝试编译它时,它给了我16条错误,我完全不知道如何解决它,唯一想到的是,也许我的代码顺序不正确。任何帮助表示赞赏,这是我的代码:

/**RULES AND TIPS:
* IF YOU INPUT AN ANSWER THAT IS NOT ONE OF THE CHOICES YOU WILL DIE AND RESTART
* DO NOT LOOK AT THE CODE, IT KILLS THE FUN MY DUDE:/
* SOMETIMES THERE IS MORE THAN ONE CORRECT ANSWER =)
* WEAPONS AND ARMOR WILL AID IN FIGHTING SITUATIONS
********IN PROGRESS RIGHT NOW, WILL ADD THESE ALL SOME DAY********
* ITEM LIST:
* IRON DAGGER +1 STRENGTH
* IRON SWORD +2 STRENGTH
* IRON BROADSWORD +3 STRENGTH
* STEEL DAGGER +2 STRENGTH
* STEEL SWORD +3 STRENGTH
* STEEL BROADSWORD +4 STRENGTH
* MYTHRIL DAGGER +3 STRENGTH
* MYTHRIL SWORD +4 STRENGTH
* MYTHRIL BROADSWORD +5 STRENGTH
* 
* CLOAK +1 DODGE
* MAGIC CLOAK +3 DODGE
*/

import java.util.Scanner;

public class Lame
{
  public static void main(String[] args)
  {
    Scanner input = new Scanner(System.in);
    int answer;

    System.out.println("Welcome to Rod's java game");
    System.out.println("Have fun!");
    System.out.println("*****RULES AND TIPS ARE IN THE FIRST AND ONLY COMMENT*****");
    System.out.println("You come to a fork in the road. Which way do you go?");
    System.out.println("Enter 1 for left or 2 for right");
    answer = input.nextInt();

    if (answer == 1)
    {
      Dead();
    }
    if (answer == 2)
    {
      Right();
    }
  }
  public static void Dead()
  {
    Scanner input = new Scanner(System.in);
    System.out.println("Wrong decision, you died. Recompile and try a different path!");
  }
  public static void Right()
  {
    int answer1;

    Scanner input = new Scanner(System.in);
    System.out.println("");
    System.out.println("You walk down the right path and come to a peculiar house.");
    System.out.println("It's getting dark outside and the sign says beware of wolves.");
    System.out.println("Do you stay in the house for the night or sleep under a tree?");
    System.out.println("Enter 1 for the house or 2 for the tree");
    answer1 = input.nextInt();

    if (answer1 == 1)
    {
      House();
    }
    if (answer1 == 2)
    {
      Tree();
    }
  }
  public static void House()
  {
    int answer2;

    Scanner input = new Scanner(System.in);
    System.out.println("");
    System.out.println("You survived the night and continue your adventure!");
    System.out.println("");
    System.out.println("Beyond the house there is a man being robbed by a thug");
    System.out.println("What do you do?");
    System.out.println("Enter 1 to continue walking or 2 to help him");
    answer2 = input.nextInt();

    if (answer2 == 1)
    {
      Dead1();
    }
    if (answer2 == 2)
    {
      Help();
    }
  }
  public static void Tree()
  {
    int answer4;

    Scanner input = new Scanner(System.in);
    System.out.println("");
    System.out.println("You survived the night and continue your adventure!");
    System.out.println("");
    System.out.println("Beyond the house there is a man being robbed by a thug");
    System.out.println("What do you do?");
    System.out.println("Enter 1 to continue walking or 2 to help him");
    answer2 = input.nextInt();

    if (answer4 == 1)
    {
      Dead1();
    }
    if (answer4 == 2)
    {
      Help();
    }
    public static void Dead1()
    {
      Scanner input = new Scanner(System.in);
      System.out.println("As you attempt to continue walking, the thug stops you");
      System.out.println("Before you can say anything, he unsheaths his sword and kills               you!");
      System.out.println("Wrong decision, you died. Recompile and try a different path!");
    }
    public static void Help()
    {
      int answer3;

      Scanner input = new Scanner(System.in);
      System.out.println("");
      System.out.println("As you run over to help the man, the thug attacks you!");
      System.out.println("You defeat the thug easily, and he drops his Iron Sword!");
      System.out.println("****IRON SWORD OBTAINED****");
      System.out.println("");
      System.out.println("");
      System.out.println("You continue your journey.");
      System.out.println("After a few hours of walking, you get to a dark castle.");
      System.out.println("Your sense of adventure draws you towards the castle");
      System.out.println("You enter, and are immediately greeted by a spiral staircase.");
      System.out.println("Enter 1 to go up the staircase or 2 to continue walking");
      answer3 = input.nextInt();

      if (answer3 == 1)
      {
        Staircase();
      }
      if (answer3 == 2)
      {
        Continuewalking();
      }
     public static void Staircase()
     {
       Scanner input = new Scanner(System.in);
       System.out.println("You die. The end.");
     }
     public static void Continuewalking()
     {
       Scanner input = new Scanner(System.in);
       System.out.println("You die. The end.");
     }
    }
  }
}

感谢您提前提供的帮助,我尝试快速完成游戏,以便获得一些帮助:)

编辑:这些是我得到的错误:

16 errors found: File: C:\Users\Rod\Desktop\java files\Lame.java [line: 116] Error: illegal start of expression File: C:\Users\Rod\Desktop\java files\Lame.java [line: 116] Error: illegal start of expression File: C:\Users\Rod\Desktop\java files\Lame.java [line: 116] Error: ';' expected File: C:\Users\Rod\Desktop\java files\Lame.java [line: 116] Error: ';' expected File: C:\Users\Rod\Desktop\java files\Lame.java [line: 123] Error: illegal start of expression File: C:\Users\Rod\Desktop\java files\Lame.java [line: 123] Error: illegal start of expression File: C:\Users\Rod\Desktop\java files\Lame.java [line: 123] Error: ';' expected File: C:\Users\Rod\Desktop\java files\Lame.java [line: 123] Error: ';' expected File: C:\Users\Rod\Desktop\java files\Lame.java [line: 149] Error: illegal start of expression File: C:\Users\Rod\Desktop\java files\Lame.java [line: 149] Error: illegal start of expression File: C:\Users\Rod\Desktop\java files\Lame.java [line: 149] Error: ';' expected File: C:\Users\Rod\Desktop\java files\Lame.java [line: 149] Error: ';' expected File: C:\Users\Rod\Desktop\java files\Lame.java [line: 154] Error: illegal start of expression File: C:\Users\Rod\Desktop\java files\Lame.java [line: 154] Error: illegal start of expression File: C:\Users\Rod\Desktop\java files\Lame.java [line: 154] Error: ';' expected File: C:\Users\Rod\Desktop\java files\Lame.java [line: 154] Error: ';' expected

最佳答案

您正在尝试定义一个方法(Dead1),同时仍在另一个方法(main)中。

它不是那样工作的。从那里开始。

请记住,一致的缩进或多或少消除了这种愚蠢的错误。

关于java - 一点文字游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21151184/

相关文章:

java - 难以将原始 PCM 输出代码从 Java 移植到 Android AudioTrack API

java - 敌人破坏 slick2d

c++ - 编译器找不到头文件中声明的函数

c++ - 如何使用 fmt 库格式化指针?

iphone - Facebook 图形 API 出现 "Duplicate status message"错误

java - 为不同的列表对话框项设置不同的操作

java - Controller 的 Spring Boot 测试 @WebMvcTest 似乎在上下文中加载其他 Controller

java - Eclipse 字体看起来很奇怪

c++ - 模板化 ctor 上的编译器错误(这是编译器错误吗?)

java - 构造函数未发现编译错误