我正在使用Java开发一个非常简单的文本冒险游戏,我想知道如何将它放入窗口中,使其看起来更像一个真正的游戏。比如说,我能否让用户点击一个图标,然后弹出这个简单的游戏?谢谢你的帮助,如果浪费了你的时间,我很抱歉!
//bored programming
import java.util.*;
public class test {
public static void main(String[] args){
Scanner input = new Scanner (System.in);
String x = "hey";
System.out.println("Welcome to adventure game!");
System.out.println();
System.out.println("Which way do you want to go?: ");
x = input.nextLine();
if (x.equals ("west")){
System.out.println("You walk towards the forest.");
west();
}
else if (x.equals("east"))
System.out.println("You go East!");
else if (x.equals("south"))
System.out.println("You go South!");
else if (x.equals("north"))
System.out.println("You go North!");
else
System.out.println("You cannot go that way!!");
}
public static void west(){
Scanner input = new Scanner (System.in);
System.out.println("Which way shall you go?");
String x = input.nextLine();
}
}
(J)Applet
不是最好的选择,相反,应该把游戏放入JFrame
中(这里的屏幕截图中显示的组件位于JFrame
中)。还要注意,Scanner
适用于从InputStream
获取数据,但与像applet或frame这样的GUI不兼容。可能需要重新考虑方法。如果代码行数不到几千行,那应该不是大问题。 ;) - Andrew Thompson