如何在Java中结束这个游戏?

huangapple go评论65阅读模式
英文:

How do I end this game in java?

问题

我试图结束这个游戏,它一直在循环,有人知道要添加哪个语句吗?这是我为学校做的一个问答游戏。

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    /* 游戏规则 */
    System.out.println("这里是游戏规则:");
    System.out.println("1. 你没有任何道具可用");
    System.out.println("2. 你只能答错一次问题");
    System.out.println("3. 如果你答错了任何问题,你将获得你赢得的东西,游戏将结束");
    System.out.println("尽力回答问题");
    System.out.println("输入 Start 开始");
    String start = input.next();
    String Question = null;
    String Questions = null;
    String word3 = null;
    if (start.equalsIgnoreCase("Start")) {
        System.out.println("你想选择哪个运动?"); // 询问用户想要选择哪个运动
        System.out.println("A. 篮球     B. 足球   C. 羽毛球");
        String sport = input.next();
        if (sport.equalsIgnoreCase("羽毛球")) { // 如果用户想要羽毛球
            Badminton(Question); // 调用方法
        }
        if (sport.equalsIgnoreCase("篮球")) { // 如果用户想要篮球
            Basketball(Questions); // 调用篮球方法
        }
        if (sport.equalsIgnoreCase("足球")) { // 如果用户想要足球
            Soccer(word3); // 调用足球方法
        }
    }
}
英文:

I am trying to end this game, it's in a loop, does anyone know which statement to add? This is a quiz game I am doing for a school.

		Scanner input = new Scanner (System.in);
		/* Game rules */
		System.out.println("Here are the game rules: ");
		System.out.println("1. You do not have any power ups to use");
		System.out.println("2. You may only get one question wrong");
		System.out.println("3.If you get any question wrong, you will get what you win, and the game will end");
		System.out.println("Try your best to answer the questions");
		System.out.println("Type Start to begin");
		String start = input.next();
		String Question = null;
		String Questions = null;
		String word3 = null;
		if (start.equalsIgnoreCase("Start")) {
			System.out.println("What sport would you like to choose?");   // ask user what sport he wants
			System.out.println("A. Basketball     B. Soccer   C. Badminton");
			String sport = input.next();
			if (sport.equalsIgnoreCase("Badminton")) {  // if user wants Badminton 
				Badminton(Question);  // call method
			}
			if (sport.equalsIgnoreCase("Basketball")) {  // If user wants Basketball
				Basketball(Questions);  // call basketball method
			}
			if (sport.equalsIgnoreCase("Soccer")) {  // if user wants soccer
				Soccer(word3);  // call soccer method
			}
        }

</details>


# 答案1
**得分**: 0

你每次询问用户问题时,都会添加一个```return```语句。所以当他们回答问题错误时,游戏会立即结束并输出奖品。

<details>
<summary>英文:</summary>

You would add a ```return``` statement each time you ask the user a question.  So when they get a question wrong, the game ends immediately and the prize is outputted.

</details>



# 答案2
**得分**: 0

你可以添加一个按钮,当用户点击按钮时,游戏将退出并显示得分。

在按钮上,您可以添加以下函数:

```java
System.exit(0);
英文:

you can add a button and when user click on button so game will exit and score will be shown.

On button you add function like below..

System.exit(0);

huangapple
  • 本文由 发表于 2020年8月31日 01:39:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63660287.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定