我是这个论坛的新手,并且一般编码。我决定自学Java作为我的第一种编程语言。我有一天订购了一本名为“Head First Java”的书,希望当我得到它时,我将能够更有效地教授自己。无论如何,我认为我会尝试创建一个游戏来帮助我学习Java(因为我的目标是学习编程以构建自己的视频游戏)。我今天开始了一个文本冒险游戏。Java文本冒险 - 你如何为用户做出选择?
这是我到目前为止有:
import java.util.Scanner;
public class Main {
public static void main (String[] args){
// Introduction
System.out.println("The year is 2507...");
System.out.println("");
System.out.println("Years have passed since the war.");
System.out.println("The people lucky enough to survive the invasion migrated\nto the newly discovered planet Rothgar in an attempt to start a new life.");
System.out.println("Will you survive on this new world, or will the human race fall into extinction? \n");
Scanner choice = new Scanner(System.in);
Scanner keyIn = new Scanner(System.in);
System.out.print("Press Enter to continue..");
keyIn.nextLine();
// Main Menu
System.out.println(" Main Menu");
System.out.println("----------------------------------------------------------------------------------------------------------------------------------");
System.out.println("Enter one of the following options:\n");
System.out.println("'Start' to begin.\n");
System.out.println("'Exit' to quit the game.\n");
System.out.println("'Instructions' to learn how to play.\n");
System.out.println("'Credits' to learn more about the game.\n");
}
}
我很抱歉,如果我的编码是丑陋与否尽可能有效,但就像我说的,我试图教我。现在,我的问题是:我如何分解这四个选项?当用户输入其中一个时,我希望我的程序转到代码的相应部分(我还没有写入)。例如,如果用户输入“Credits”,我希望输出成为我游戏的点数,然后我需要程序返回到主菜单,可能在用户再次按下“Enter”后。如果玩家没有从主菜单中输入这四个选项中的任何一个,我希望我的程序说“你没有很好地遵循方向,是吗?让我们再试一次。”
我希望我明确地问我的问题。所有帮助表示赞赏!我刚刚开始学习编程Java,我显然还是一个新手,但我打算最终作为独立游戏开发者发布自己的游戏! :)
继续阅读你的书,你会学到答案。这实际上是一个非常广泛的“如何编写程序”的问题。 – John3136 2014-10-27 01:55:19
您将不得不更多地了解方法,类,OOP(面向对象编程)和对象,从本质上转向下一级编程来解决这个问题。继续阅读你的书和/或教程,并不要放弃。 – 2014-10-27 01:55:41