Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java I';我组织起来有困难_Java_Code Organization - Fatal编程技术网

Java I';我组织起来有困难

Java I';我组织起来有困难,java,code-organization,Java,Code Organization,我刚刚学习了如何在java中使用不同的类,但我不清楚如何使用。我还想知道如何在代码中设置足够的机制来启动和停止游戏。例如,当有人进入你不应该进入的东西时,它会允许他们再次进入。记住,我还没有完成这个小游戏 package; 导入java.util.Scanner; 公共班机{ 公共静态void main(字符串[]args){ //创建扫描仪以获取用户输入 扫描仪输入=新扫描仪(System.in); //游戏故事|介绍 System.out.println(“你发现自己在一辆车里,但你不知道自

我刚刚学习了如何在java中使用不同的类,但我不清楚如何使用。我还想知道如何在代码中设置足够的机制来启动和停止游戏。例如,当有人进入你不应该进入的东西时,它会允许他们再次进入。记住,我还没有完成这个小游戏

package;
导入java.util.Scanner;
公共班机{
公共静态void main(字符串[]args){
//创建扫描仪以获取用户输入
扫描仪输入=新扫描仪(System.in);
//游戏故事|介绍
System.out.println(“你发现自己在一辆车里,但你不知道自己是怎么到的。外面在下雨,你从冰冷的窗户看到一栋房子。你看到手套箱里有东西。”);
System.out.println(“按任意键继续…”);
String contlol=input.nextLine();
System.out.println(“选项:”);
System.out.println(“'Leave'”);
System.out.println(“打开手套箱”);
String firstchoice=input.nextLine();
//选择在不打开手套箱的情况下离开汽车
if(firstchoice.equalsIgnoreCase(“离开”)){
System.out.println(“你走出车外,天黑多雨,你别无选择,只能进入离你最近的最安全的地方——房子”);
System.out.println(“按任意键继续…”);
String cont1=input.nextLine();
System.out.println(“选项:”);
System.out.println(“Walk”);
字符串in=input.nextLine();
//步行回家的选择
如果(在同等信号情况下(“行走”)){
System.out.println(“你开始朝房子走去。门吱吱地开着,你发现自己身处一个尘土飞扬、冰冷的房子里。房子里似乎已经多年没有人了,还有一个楼上和一个厨房。”);
System.out.println(“按任意键继续…”);
String cont2=input.nextLine();
System.out.println(“选项:”);
System.out.println(“厨房”);
System.out.println(“楼上”);
System.out.println(“客厅”);
字符串gimme=input.nextLine();
如果(给我等信号(“厨房”)){
“你走进黑暗的厨房,你发现旁边有一个电灯开关,房间亮了一点,你看到炉子开着,有人在烧水。”;
System.out.println(“按任意键继续…”);
字符串gay=input.nextLine();
System.out.println(“选择”);
System.out.println('Run');
System.out.println(“'Stay'”);
字符串utts=input.nextLine();
如果(发出相等信号(“运行”)){
System.out.println(“你无助地跑到门口,发现门被锁上了……从外面。”);
System.out.println(“按任意键继续…”);
字符串k=input.nextLine();
System.out.println(“选项:”);
System.out.println(“楼上”);
System.out.println(“客厅”);
字符串kkk=input.nextLine();
if(kkk.同等信号(“楼上”)){
“当你开始上楼的旅程时,楼梯开始吱吱作响,你听到有人说话。过了一会儿,你说服自己这是你的想象。”;
System.out.println(“一旦你上楼,你就会发现一间浴室和一间卧室。”);
System.out.println(“按任意键继续…”);
字符串rape=input.nextLine();
System.out.println(“选项:”);
System.out.println(“浴室”);
System.out.println(“卧室”);
}
}否则如果(完全相等信号(“保持”)){
System.out.println(“你走向沸腾的水壶。在里面,你看到的是某人,但不是你自己……”);
println(“你转过身来,但没有足够快的速度躲开向你扔来的刀子。它卡在你的心里。”);
println(“你开始慢慢死去,看着你上方的生物向下凝视你的眼睛。”);
System.out.println(“你输了…”);
返回;
}
}否则,如果(给我一个同等信号(“客厅”)){
“你走进一间小而宽敞的客厅,里面有电视机、吊扇、唱机、沙发和其他客厅用品。”;
println(“只要你走进客厅,telvesion就会打开新闻频道,吊扇开始旋转。”);
System.out.println(“按任意键继续…”);
字符串dick=input.nextLine();
System.out.println(“选项:”);
System.out.println('Run');
System.out.println(“调查”);
字符串meme=input.nextLine();
if(meme.equalsIgnoreCase(“调查”)){
System.out.println(“你在客厅里转了一圈,你在电视里发现了一盘磁带,你听到身后有什么声音。”);
System.out.println(“你转身,但没人在那里。你转身,盒式磁带就不见了。”);
System.out.println(“按
class State {
  String message;
  Map<String, State> choices = new LinkedHashMap<>();
}
State start = new State();
start.message = "You find yourself in a car...";

State leaveTheCar = new State();
leaveTheCar.message = "You get outside of the car...";

State openGlovebox = new State();
openGlovebox.message = "You find a note...";

State dead = new State();
dead.message = "You're dead.";
start.choices.put("Leave", leaveTheCar);
start.choices.put("Open glovebox", openGlovebox);

leaveTheCar.choices.put("Get back in car", start);
leaveTheCar.choices.put("Blah", dead);

openGlovebox.choices.put("Bloo", dead);
State state = start;
while (true) {
  System.out.println(state.message);
  if (state.choices.isEmpty()) {
    break;  // No choices: game over.
  }

  while (true) {  // Keep going until user enters a valid choice.
    System.out.println("Choices:");
    for (String key : state.choices.keySet()) {
      System.out.println("'%s'%n", key);
    }
    String choice = input.nextLine();
    if (state.choices.containsKey(choice)) {
      state = state.choices.get(choice);  // Go to the next state.
      break;
    }

    System.out.println("Choose again!");
  }
}