Java 一个小小的文字游戏
我是一个完全的java新手,在过去几天的计算机课上,我一直在做一个有趣的小游戏 我的问题是,当我试图编译它时,它给了我16个错误,我完全不知道如何修复它,我唯一想到的是,可能我的代码顺序不正确。感谢您的帮助,这是我的代码:Java 一个小小的文字游戏,java,compiler-errors,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 TH
/**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个错误:文件:C:\Users\Rod\Desktop\java files\Lame.java
[第116行]错误:表达式文件的启动非法:
C:\Users\Rod\Desktop\java files\Lame.java[line:116]错误:非法
表达式文件的开头:C:\Users\Rod\Desktop\java files\Lame.java
[第116行]错误:';'所需文件:C:\Users\Rod\Desktop\java
files\Lame.java[line:116]错误:';'预期文件:
C:\Users\Rod\Desktop\java files\Lame.java[line:123]错误:非法
表达式文件的开头:C:\Users\Rod\Desktop\java files\Lame.java
[第123行]错误:表达式文件的启动非法:
C:\Users\Rod\Desktop\java files\Lame.java[line:123]错误:';'
预期文件:C:\Users\Rod\Desktop\java files\Lame.java[行:123]
错误:';'预期文件:C:\Users\Rod\Desktop\java files\Lame.java
[行:149]错误:表达式文件的启动非法:
C:\Users\Rod\Desktop\java files\Lame.java[line:149]错误:非法
表达式文件的开头:C:\Users\Rod\Desktop\java files\Lame.java
[第149行]错误:';'所需文件:C:\Users\Rod\Desktop\java
files\Lame.java[行:149]错误:';'预期文件:
C:\Users\Rod\Desktop\java files\Lame.java[行:154]错误:非法
表达式文件的开头:C:\Users\Rod\Desktop\java files\Lame.java
[第154行]错误:表达式文件的启动非法:
C:\Users\Rod\Desktop\java files\Lame.java[line:154]错误:';'
预期文件:C:\Users\Rod\Desktop\java files\Lame.java[行:154]
错误:';'期望
请使用IDE?要检查这些错误,即使像这样的在线工具也足够了。您的方法似乎太懒,无法学习编程。这不是一个好的态度,通常StackOverflow不是为了检查程序的语法,而是为了帮助解决问题
您的错误主要与错位}有关,请检查//您试图在另一个方法main中定义方法Dead1 它不是那样工作的。从那里开始
请记住,一致的缩进或多或少会消除像这样愚蠢的错误。当他们说难以维护时,这就是他们的意思吗;Stackoverflow不是拼写检查器。您的大多数错误都可以通过简单地将代码粘贴到一个像样的IDE中来解决。Netbeans会让您看到红色的噩梦,直到您修复它们,并且它或多或少会以一种人类可读的方式告诉您哪里出了问题。
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");
answer4 = input.nextInt(); // <----- CHANGE answer2 to 4
if (answer4 == 1)
{
Dead1();
}
if (answer4 == 2)
{
Help();
}
} // <---- ADD PARENTHESIS HERE
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();
}
} // <---- ADD PARENTHESIS HERE
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.");
}
//} <- REMOVE THEM
//} <- REMOVE THEM
}