I need assistance with an RPG-type inventory… (JAV

2020-08-01 19:17发布

Before you minus-vote this, I can't even wrap my mind around how to do this.

How would you make a .java or class that you could add text from a different class into it to store information MID-EXECUTION?

Technically, what I'm trying to accomplish is an inventory system for a text-based RPG, where it could say, "hey, you got a sword!" and "sword" appears in the inventory. and you can type in "INVENTORY" and see "You have 1X Sword". It can't be a println because I need the player to be able to access it anytime.

I have searched it on the web, and nothing came up. How can I proceed further?

The code below will display my current inventory system, and why it needs to be fixed:

    import java.util.Scanner;

    public class Class
    {

    public static void main(String[] args)
    {
        String choice;
        Scanner scan = new Scanner(System.in);
        System.out.println("COPYRIGHT 2016 HARBNGER STUDIOS\nTYPE AN 'option' TO GO TO THAT LOCATION\n\nSTART: You awake in a broken-down alabaster\nhouse with no knowledge of who\nyou are or where you came from. You are hungry and\ncold, and there is no food nor flammable material\nnearby. You decide to go look for some.\nWhich direction do you want to head? (options: NORTH, SOUTH, EAST, WEST)");
        choice = scan.nextLine();{

            if(choice.equals("NORTH")){
            System.out.println("\n\n\n\n--TERMINAL_LOG--                JAN 16, 2644\n\nI FOUND THIS HANDHELD TERMINAL LOG. FIGURED I'D\nPUT IT TO SOME USE.\n\nI TRAVELED NORTH TO A RUN-DOWN VILLAGE. CARCASSES EVERYWHERE.\nNO SURVIVORS. I WONDER WHAT HAPPENED HERE.\nI LOOTED THE BODIES, TALOS BLESS MY SOUL. I FOUND A PISTOL\nAND SOME GAUZE. I CAN VIEW MY INVENTORY, HIT THE ROAD, OR LINGER AROUND.\n\n(options: INVENTORY1,ROAD,LINGER)");
            }   else if(choice.equals("SOUTH")){
            System.out.println("\n\n\n\n--TERMINAL_LOG--                JAN 16, 2644\n\nI FOUND THIS HANDHELD TERMINAL LOG FIGURED I'D\nPUT IT TO SOME USE. TODAY IS, ACCORDING TO THIS, THE 15TH OF JAN, 2644\n\nI TRAVELED SOUTH AND STOPPED AT AN ABANDONED\nOUTPOST. IT HAS SOME SUPPLIES. I PICKED\nUP A PISTOL AND SOME NANITE SYRINGES. I CAN CHECK\nMY INVENTORY, MOVE FARTHER SOUTH, OR EXPLORE.\n\n(options: INVENTORY3,FARTHER,EXPLORE)");
            }   else if(choice.equals("WEST")){
            System.out.println("\n\n\n\n--TERMINAL_LOG--                JAN 16, 2644\n\nI FOUND THIS HANDHELD TERMINAL LOG FIGURED I'D\nPUT IT TO SOME USE. TODAY IS, ACCORDING TO THIS, THE 15TH OF JAN, 2644.\n\nI TRAVELED WEST AND FOUND AN ABANDONED SHACK.\nSHOULD I SEARCH IT FOR LOOT OR MOVE ON?\n\n(options: SEARCH,MOVE)");
            }if(choice.equals("EAST")){
            System.out.println("\n\n\n\n--TERMINAL_LOG--                JAN 16, 2644\n\nI FOUND THIS HANDHELD TERMINAL LOG FIGURED I'D\nPUT IT TO SOME USE. TODAY IS, ACCORDING TO THIS, THE 15TH OF JAN, 2644.\n\nI TRAVELED EAST AND STOPPED BY A DIRTY STREAM.\nIT'S FILLED WITH GARBAGE, BUT THERE ARE ALSO PLASTIC BOTTLES.\nSHOULD I FILL THEM WITH WATER OR MOVE ON?\n\n(options: FILL,MOVE)");}}
            choice = scan.nextLine();

            //North Diologue Options
            if(choice.equals("INVENTORY1")){
            System.out.println("\n\n\n\n--INVENTORY--\n\n1X PISTOL (12/12)\n\n3X GAUZE (HEALS FOR 120)\n\n(options: ROAD,LINGER)");
            }   else if(choice.equals("ROAD")){
            System.out.println("\n\n\n\n--TERMINAL_LOG--\n\nI HOPPED ON THE ROAD. SAW SOME DESTROYED\nSKYSCRAPERS. WONDER WHAT HAPPENED TO THESE PEOPLE.\nI FOUND AN ABANDONED GAS STATION WITH SOME FOOD. IT HAS\nCLEAN WATER AS WELL, SO I MIGHT AS WELL FILL\nUP.\nI NOTICED A TERMINAL IN THE CORNER OF THE\nSHOP. MAYBE IT CAN HELP ME FIND ITEMS,\nLOCATIONS, OR CIVILIZATION.\nSHOULD I CHECK THE TERMINAL OR LEAVE?\n\n(options: TERMINAL,LEAVE)");
            }   else if(choice.equals("LINGER")){
            System.out.println("\n\n\n\n--TERMINAL_LOG--\n\nI STAYED FOR ABOUT 4 HOURS OR SO. GATHERED AN AXE\nAND SOME WOOD.\nJUST HEARD SOME GUNSHOTS. BETTER GET MOVING BEFORE WE\nFIND TROUBLE. I CAN CHECK MY INVENTORY, DITCH THE SCENE, OR\nSTAY, AND HOPE THE GUNNERS ARE FRIENDLY.\n\n(options: INVENTORY2,DITCH,STAY)");
            //South Diologue Options
            }   else if(choice.equals("INVENTORY3")){
            System.out.println("\n\n\n\n--INVENTORY--\n\n1X PISTOL (12/12)\n\n2X NANITE SYRINGE (HEALS FOR 200)\n\n(options: FARTHER,EXPLORE)");
            }   else if(choice.equals("EXPLORE")){
            System.out.println("\n\n\n\n--TERMINAL_LOG--\n\nI WANDERED OFF FROM THE OUTPOST, AND I BELIEVE\nI LOST IT. IT'S A LITTLE PAST FIVE O'CLOCK. THERE ARE SOME\nGUNSHOTS NEARBY, HIDING IN AN ABANDONED SHACK.\n\nTHE SHACK KEEPS ME HIDDEN AS A LARGE ROBOT ROLLED PAST. THE SHACK,\nMEANWHILE, HAS SOME NICE SUPPLIES. HOWEVER, IF I SEARCH\nIT, I MAY NOT BE READY FOR THE NIGHT.\n\n(options: SEARCH,MOVE)");
            }   else if(choice.equals("FARTHER")){
            System.out.println("\n\n\n\n--TERMINAL_LOG--\n\nI WANDERED FURTHER ON DOWN SOUTH. IT GETS A LITTLE COLDER EACH TIME I SEE A DEAD CARCASS. THEY ARE LITERALLY LAYING EVERYWHERE. I'M COMING UP TO A LARGE MOUNTAINOUS AREA. IF I ATTEMPT TO CLIMB IT, I MAY NOT BE PREPARED FOR THE NIGHT. I CAN, HOWEVER, SEARCH FOR A TEMPORARY SHELTER AND MAYBE SOME FOOD AND WATER. WHICH SHOULD I DO?\n\n(options: CLIMB,FORAGE)");}
            choice = scan.nextLine();
    }
}

Note the "Inventory1" and "Inventory3."

Once the player catches on to my method, they could be able to skip right through the game with the best weapons and armor, if they knew the inventory number.

Thank you for helping. I appreciate it.

标签: java
0条回答
登录 后发表回答