-4

我在课堂上做的这个项目需要帮助。这就是我所拥有的!

public class Game {

public static void main(String[] args) {
        // TODO Auto-generated method stub
        int Naruto = 0;
        int DragonBallZ = 1;
        int Batman = 0;
        int Freedom = 0;
        int righthand = 1;
        int lefthand = 1;

        if (Naruto == 0) {
            if (lefthand == 0) {
                System.out.println("The command 0 has been used...");
                System.out.println("Processing...");
                System.out.println("Accessing Game Server...");
                System.out.println("Success!");
                System.out.println("You have been given the 'Kunai'");
            } else if (righthand == 1) {
                System.out.println("The command 1 has been used...");
                System.out.println("Processing...");
                System.out.println("Accessing Game Server...");
                System.out.println("Success!");
                System.out.println("You have been given the 'Shurikan'");
            }
            if (DragonBallZ == 1) {
                if (lefthand == 0) {
                    System.out.println("The command 2 has been used...");
                    System.out.println("Processing...");
                    System.out.println("Accessing Game Server...");
                    System.out.println("Success!");
                    System.out.println("You have been given the 'Kaioken' Ability");
                } else if (righthand == 1) {
                    System.out.println("The command 3 has been used...");
                    System.out.println("Processing...");
                    System.out.println("Accessing Game Server...");
                    System.out.println("Success!");
                    System.out.println("You have been given the 'Super Saiyan 4'     Ability");
                }
                if (Batman == 2) {
                    if (lefthand == 0) {
                        System.out.println("The command 4 has been used...");
                        System.out.println("Processing...");
                        System.out.println("Accessing Game Server...");
                        System.out.println("Success!");
                        System.out.println(" You have been given the 'Batarang' ");
                    } else if (righthand == 1) {
                        System.out.println("The command 5 has been used...");
                        System.out.println("Processing...");
                        System.out.println("Accessing Game Server...");
                        System.out.println("Success!");
                        System.out.println(" You have been given the 'Keen Eyes'     Ability");
                    }
                    if (Freedom == 3) {
                        if (lefthand == 0) {
                            System.out.println("The command 6 has been used...");
                            System.out.println("Processing...");
                            System.out.println("Accessing Game Server...");
                            System.out.println("Success!");
                            System.out.println(" You have been given the 'Rope' ");
                        } else if (righthand == 1) {
                            System.out.println("The command 7 has been used...");
                            System.out.println("Processing...");
                            System.out.println("Accessing Game Server...");
                            System.out.println("Success!");
                            System.out.println(" You have been given the 'Knife' ");
                        }
                    }
                }
            }
        }
    }
}

因此,如果有人可以帮助我,我正在尝试制作 4 款游戏,每款游戏都有 2 种武器。当我运行程序时,我需要该游戏的 1 武器。我不断得到该武器编号的所有游戏的结果。因此,如果有人可以提供帮助,那就太棒了!谢谢!

  • 编辑 - 我也在使用 Eclipse 来编写 java 程序!
4

1 回答 1

0

即使您的问题不是那么清楚,我想您希望您的代码返回

已使用命令 1...

加工...

访问游戏服务器...

成功!

你获得了“手里剑”

这不会发生,因为您正在嵌套不同类型的游戏。

else-if从“火影忍者”到“龙珠Z”时,您应该使用该语句。

这是固定代码,希望我能理解您的问题。

public class Game {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int Naruto = 0;
        int DragonBallZ = 1;
        int Batman = 0;
        int Freedom = 0;
        int righthand = 1;
        int lefthand = 1;

        if (Naruto == 0) {
            if (lefthand == 0) {
                System.out.println("The command 0 has been used...");
                System.out.println("Processing...");
                System.out.println("Accessing Game Server...");
                System.out.println("Success!");
                System.out.println("You have been given the 'Kunai'");
            } else if (righthand == 1) {
                System.out.println("The command 1 has been used...");
                System.out.println("Processing...");
                System.out.println("Accessing Game Server...");
                System.out.println("Success!");
                System.out.println("You have been given the 'Shurikan'");
            }
        } else if (DragonBallZ == 1) { //Changed if to else if
            if (lefthand == 0) {
                System.out.println("The command 2 has been used...");
                System.out.println("Processing...");
                System.out.println("Accessing Game Server...");
                System.out.println("Success!");
                System.out.println("You have been given the 'Kaioken' Ability");
            } else if (righthand == 1) {
                System.out.println("The command 3 has been used...");
                System.out.println("Processing...");
                System.out.println("Accessing Game Server...");
                System.out.println("Success!");
                System.out.println("You have been given the 'Super Saiyan 4'     Ability");
            }
        } else if (Batman == 2) { //Changed if to else if
            if (lefthand == 0) {
                System.out.println("The command 4 has been used...");
                System.out.println("Processing...");
                System.out.println("Accessing Game Server...");
                System.out.println("Success!");
                System.out.println(" You have been given the 'Batarang' ");
            } else if (righthand == 1) {
                System.out.println("The command 5 has been used...");
                System.out.println("Processing...");
                System.out.println("Accessing Game Server...");
                System.out.println("Success!");
                System.out.println(" You have been given the 'Keen Eyes'     Ability");
            }
        } else if (Freedom == 3) { //Changed if to else if
            if (lefthand == 0) {
                System.out.println("The command 6 has been used...");
                System.out.println("Processing...");
                System.out.println("Accessing Game Server...");
                System.out.println("Success!");
                System.out.println(" You have been given the 'Rope' ");
            } else if (righthand == 1) {
                System.out.println("The command 7 has been used...");
                System.out.println("Processing...");
                System.out.println("Accessing Game Server...");
                System.out.println("Success!");
                System.out.println(" You have been given the 'Knife' ");
            }
        }
    }
}

请记住,即使我在回答,这也不是使用本网站的正确方式!

于 2013-09-29T17:34:30.327 回答