Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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_Java_Oop - Fatal编程技术网

我试图让我的游戏类调用我的库存类。JAVA

我试图让我的游戏类调用我的库存类。JAVA,java,oop,Java,Oop,存货类别 这是我试图得到的类,用来显示调用时播放器拥有的内容 游戏课 这是拥有大部分信息的类 Runner类具有main方法 这个类有main方法,用于运行游戏 试着把生锈的剑和灯从故事课传到存货课。 您仍然需要调整if条件的顺序 package textadventure; public class inventory { public inventory(boolean rustedsword, boolean lamp) { if (lamp == true) {

存货类别

这是我试图得到的类,用来显示调用时播放器拥有的内容 游戏课

这是拥有大部分信息的类 Runner类具有main方法

这个类有main方法,用于运行游戏
试着把生锈的剑和灯从故事课传到存货课。 您仍然需要调整if条件的顺序

package textadventure;

public class inventory {
    public inventory(boolean rustedsword, boolean lamp) {
        if (lamp == true) {
            System.out.println("You have a Lamp");
        } else if (rustedsword == true && lamp == true) {
            System.out.println("You have a Rusted Sword");
            System.out.println("You have a Lamp");
        } else if (rustedsword == true) {
            System.out.println("You have a Rusted Sword");
        } else {
            System.out.println("You have Nothing in your inventory");
        }
    }

}

问题是什么?新库存;
package textadventure;

import java.util.Scanner;

public class Story
{
public boolean isAlive;
public boolean rustedsword;
public boolean lamp;
public int hunger;
private inventory newinv;
public Scanner input = new Scanner(System.in);
public void thestory()  {
    inventory newinv = new inventory();
    System.out.println("You are in a dark room");
    System.out.println("There is a light switch, would you like to turn it on?");
    String choice1 = input.nextLine();
    if (choice1.contains("yes")) {
        System.out.println("The lights sparked to life for a second then went dead.");
        System.out.println("While The lights were on You saw a lamp in the corner");
        System.out.println("Would you like to pick it up?");
        String choice6 = input.nextLine();
        if (choice6.contains("yes")) {
            lamp = true;
            System.out.println("The Lamp Blazed to life, The little light and heat that it gives out rejuvinates your soul");
            System.out.println("Lamp added to inventory, You can press 9 to view your inventory.");
        }
    }
    System.out.println("You hear the sound of motion to your left");
    System.out.println("1: Go investigate the sound");
    System.out.println("2: Stay put");
    String choice2 = input.nextLine();
    if (choice2.contains("9")) {
        inventory();
    if (choice2.contains("1")) {
        System.out.println("You slowly walk towards the sound. You find a hallway along with a rusted sword.");
        System.out.println("Would you like to pick up the sword?");
        String choice3 = input.nextLine();
        if (choice3.contains("yes")) {
            rustedsword = true;
            System.out.println("You picked up the rusted sword, you can feel the evil this blade has slain");
            System.out.println("Sword Added to Inventory, You can press 9 to view your inventory");
        }
        System.out.println("You see a Beast that is at least 8 feet tall");
        if (choice3.contains("yes")) {
            System.out.println("1: Stabby Stabby");
            System.out.println("2: Throw The Sword");
        }
        System.out.println("3: Stand Frozen In Fear");
        String choice4 = input.nextLine();
        if (choice4.contains("1")) {
            hunger = 9999;
            isAlive = false;
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("The Sword wasnt long enough...");
            System.out.println("OH NO! YOU DIED");

            System.out.println("                    ███████████████████████████");
            System.out.println("                    ███████▀▀▀░░░░░░░▀▀▀███████");
            System.out.println("                    ████▀░░░░░░░░░░░░░░░░░▀████");
            System.out.println("                    ███│░░░░░░░░░░░░░░░░░░░│███");
            System.out.println("                    ██▌│░░░░░░░░░░░░░░░░░░░│▐██");
            System.out.println("                    ██░└┐░░░░░░░░░░░░░░░░░┌┘░██");
            System.out.println("                    ██░░└┐░░░░░░░░░░░░░░░┌┘░░██");
            System.out.println("                    ██░░┌┘▄▄▄▄▄░░░░░▄▄▄▄▄└┐░░██");
            System.out.println("                    ██▌░│██████▌░░░▐██████│░▐██");
            System.out.println("                    ███░│▐███▀▀░░▄░░▀▀███▌│░███");
            System.out.println("                    ██▀─┘░░░░░░░▐█▌░░░░░░░└─▀██");
            System.out.println("                    ██▄░░░▄▄▄▓░░▀█▀░░▓▄▄▄░░░▄██");
            System.out.println("                    ████▄─┘██▌░░░░░░░▐██└─▄████");
            System.out.println("                    █████░░▐█─┬┬┬┬┬┬┬─█▌░░█████");
            System.out.println("                   ████▌░░░▀┬┼┼┼┼┼┼┼┬▀░░░▐████");
            System.out.println("                   █████▄░░░└┴┴┴┴┴┴┴┘░░░▄█████");
            System.out.println("                    ███████▄░░░░░░░░░░░▄███████");
            System.out.println("                    ██████████▄▄▄▄▄▄▄██████████");
            System.out.println("");                  

        }
        if (choice4.contains("3")) {
            hunger = 9999;
            isAlive = false;
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("A Vicious Beast Leaps toward you and you feel its claws rip and tear through");
            System.out.println("your chest!OH NO! YOU DIED");

            System.out.println("                    ███████████████████████████");
            System.out.println("                    ███████▀▀▀░░░░░░░▀▀▀███████");
            System.out.println("                    ████▀░░░░░░░░░░░░░░░░░▀████");
            System.out.println("                    ███│░░░░░░░░░░░░░░░░░░░│███");
            System.out.println("                    ██▌│░░░░░░░░░░░░░░░░░░░│▐██");
            System.out.println("                    ██░└┐░░░░░░░░░░░░░░░░░┌┘░██");
            System.out.println("                    ██░░└┐░░░░░░░░░░░░░░░┌┘░░██");
            System.out.println("                    ██░░┌┘▄▄▄▄▄░░░░░▄▄▄▄▄└┐░░██");
            System.out.println("                    ██▌░│██████▌░░░▐██████│░▐██");
            System.out.println("                    ███░│▐███▀▀░░▄░░▀▀███▌│░███");
            System.out.println("                    ██▀─┘░░░░░░░▐█▌░░░░░░░└─▀██");
            System.out.println("                    ██▄░░░▄▄▄▓░░▀█▀░░▓▄▄▄░░░▄██");
            System.out.println("                    ████▄─┘██▌░░░░░░░▐██└─▄████");
            System.out.println("                    █████░░▐█─┬┬┬┬┬┬┬─█▌░░█████");
            System.out.println("                   ████▌░░░▀┬┼┼┼┼┼┼┼┬▀░░░▐████");
            System.out.println("                   █████▄░░░└┴┴┴┴┴┴┴┘░░░▄█████");
            System.out.println("                    ███████▄░░░░░░░░░░░▄███████");
            System.out.println("                    ██████████▄▄▄▄▄▄▄██████████");
            System.out.println("");                  
            {}
               if (choice4.contains("2")) {
                    System.out.println("The Beast falls to the ground dead.");
                    System.out.println("You see light and the outline of a small village");
                    System.out.println("Do you want to greet the villagers?");
                    String choice5 = input.nextLine();
                    choice5 = input.nextLine();
                    if (choice5.contains("yes")) {
                        System.out.println("They greet you kindly");
                        System.out.println("YOU WON");

                    }
                    if (choice5.contains("no")) {
                        hunger = 9999;
                        isAlive = false;
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("");
                        System.out.println("A Vicious Beast Leaps toward you and you feel its claws rip and tear through");
                        System.out.println("your chest!OH NO! YOU DIED");

                        System.out.println("                    ███████████████████████████");
                        System.out.println("                    ███████▀▀▀░░░░░░░▀▀▀███████");
                        System.out.println("                    ████▀░░░░░░░░░░░░░░░░░▀████");
                        System.out.println("                    ███│░░░░░░░░░░░░░░░░░░░│███");
                        System.out.println("                    ██▌│░░░░░░░░░░░░░░░░░░░│▐██");
                        System.out.println("                    ██░└┐░░░░░░░░░░░░░░░░░┌┘░██");
                        System.out.println("                    ██░░└┐░░░░░░░░░░░░░░░┌┘░░██");
                        System.out.println("                    ██░░┌┘▄▄▄▄▄░░░░░▄▄▄▄▄└┐░░██");
                        System.out.println("                    ██▌░│██████▌░░░▐██████│░▐██");
                        System.out.println("                    ███░│▐███▀▀░░▄░░▀▀███▌│░███");
                        System.out.println("                    ██▀─┘░░░░░░░▐█▌░░░░░░░└─▀██");
                        System.out.println("                    ██▄░░░▄▄▄▓░░▀█▀░░▓▄▄▄░░░▄██");
                        System.out.println("                    ████▄─┘██▌░░░░░░░▐██└─▄████");
                        System.out.println("                    █████░░▐█─┬┬┬┬┬┬┬─█▌░░█████");
                        System.out.println("                   ████▌░░░▀┬┼┼┼┼┼┼┼┬▀░░░▐████");
                        System.out.println("                   █████▄░░░└┴┴┴┴┴┴┴┘░░░▄█████");
                        System.out.println("                    ███████▄░░░░░░░░░░░▄███████");
                        System.out.println("                    ██████████▄▄▄▄▄▄▄██████████");
                        System.out.println("");                  
                        if (choice2.contains("2")) {
                            hunger = 9999;
                            isAlive = false;
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("");
                            System.out.println("A Vicious Beast Leaps toward you and you feel its claws rip and tear through");
                            System.out.println("your chest!OH NO! YOU DIED");

                            System.out.println("                    ███████████████████████████");
                            System.out.println("                    ███████▀▀▀░░░░░░░▀▀▀███████");
                            System.out.println("                    ████▀░░░░░░░░░░░░░░░░░▀████");
                            System.out.println("                    ███│░░░░░░░░░░░░░░░░░░░│███");
                            System.out.println("                    ██▌│░░░░░░░░░░░░░░░░░░░│▐██");
                            System.out.println("                    ██░└┐░░░░░░░░░░░░░░░░░┌┘░██");
                            System.out.println("                    ██░░└┐░░░░░░░░░░░░░░░┌┘░░██");
                            System.out.println("                    ██░░┌┘▄▄▄▄▄░░░░░▄▄▄▄▄└┐░░██");
                            System.out.println("                    ██▌░│██████▌░░░▐██████│░▐██");
                            System.out.println("                    ███░│▐███▀▀░░▄░░▀▀███▌│░███");
                            System.out.println("                    ██▀─┘░░░░░░░▐█▌░░░░░░░└─▀██");
                            System.out.println("                    ██▄░░░▄▄▄▓░░▀█▀░░▓▄▄▄░░░▄██");
                            System.out.println("                    ████▄─┘██▌░░░░░░░▐██└─▄████");
                            System.out.println("                    █████░░▐█─┬┬┬┬┬┬┬─█▌░░█████");
                            System.out.println("                   ████▌░░░▀┬┼┼┼┼┼┼┼┬▀░░░▐████");
                            System.out.println("                   █████▄░░░└┴┴┴┴┴┴┴┘░░░▄█████");
                            System.out.println("                    ███████▄░░░░░░░░░░░▄███████");
                            System.out.println("                    ██████████▄▄▄▄▄▄▄██████████");
                            System.out.println("");                  
                        }

                    }
                }
            }
        }
    }
 }
}
package textadventure;

public class Runner
{

private int hunger;


private boolean isAlive;

public static void main(String[] args){

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     int bathroom = 0;
     int hunger = 0;
     int sleep = 0;
    Story yaboi = new Story();


        yaboi.thestory();
    }
}
package textadventure;

public class inventory {
    public inventory(boolean rustedsword, boolean lamp) {
        if (lamp == true) {
            System.out.println("You have a Lamp");
        } else if (rustedsword == true && lamp == true) {
            System.out.println("You have a Rusted Sword");
            System.out.println("You have a Lamp");
        } else if (rustedsword == true) {
            System.out.println("You have a Rusted Sword");
        } else {
            System.out.println("You have Nothing in your inventory");
        }
    }

}