The next problem you will have to over come is what do to when they don't enter what you're expecting Another problem you will face is Scanner next will return the next work, so something like run away won't work.
Improve this answer. MadProgrammer MadProgrammer k 22 22 gold badges silver badges bronze badges. Add a comment. Your logic was off. Look at where the pantry actually was. Kai Arakawa Kai Arakawa 1 1 gold badge 1 1 silver badge 13 13 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks.
Podcast Making Agile work for data science. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled.
Accept all cookies Customize settings. Open 33 added linting workflow, fixed linting issues. Open Create linting Github workflow. Open Create Docker configuration. Find more good first issues. A basic text based adventure game using Java and GUI.
Updated Sep 9, Java. Cartesia, a semester project for EECS Updated Dec 15, Java. Star 0. Updated Mar 2, Java. Simple text adventure game. Updated Jan 24, Java. A simple parser for a Zork-like adventure game. Updated Oct 17, Java. An open-world adventure game made in Java. Updated Aug 13, Java. Updated Jun 16, Java. Updated Jul 6, Java. Updated Jul 14, Java.
Learn more. Java text-based adventure game Ask Question. Asked 3 years, 9 months ago. Active 1 month ago. Viewed 11k times. Improve this question. Liam Liam 73 1 1 gold badge 1 1 silver badge 5 5 bronze badges.
Add a comment. Active Oldest Votes. Let's start with creating the Player class and see why it would be preferable over your current way of handling the player that being public static String Name; public static int HP; public static int maxHP; public static int xp; public static int atk; public static int def; public static int lvl; public static int potion; You currently have just a bunch of different values that are all loose in your program. You can also provide some helper methods in your Player that could look like this.
Let's try and start writing the method out, copying the logic from your current implementation. Misc stuff A lot of your methods throw an InterruptedException.
You could use it like this wait 3 ; will wait for 3 seconds. See the docs on naming conventions here Hopefully this review was helpful for you! Improve this answer. Updated now with! The problem with this approach is that static variables are, in a way, global variables, but most of the variables you define at the beginning of your code are merely properties of the player.
Now, as it is, this might not seem like a problem, because your class TextBasedAdventure is not inside any context whatsoever, so "global" and "property of the player" might not seem like irreconcilable characteristics, but it makes your code very inflexible, in case you want to modify your program in any way, be it reorganizing the code, or extending the functionality of the program, or refining the code that modifies the player's properties.
In fact, even in the current state of your code, I can think of a disadvantage of making all these variables static : Unlike all the other variables, the player's name never changes, which means that the variable Name would lend itself to being declared final.
However, this is not possible if the variable is static , because then its value would already have to be defined at compile time, meaning that it would be impossible for the user to input a name. So I suggest creating a Player class and making all these properties instance variables of Player.
The code to level up or heal the player is littered over the methods StartRoom , combatskel and combatzombie , which not only causes code duplication, but also defies the Single Responsibility Principle in this case, this would mean that, for example, the method combatskel is only responsible for fighting a skeleton, and not for the implementation details of leveling up the player.
I suggest making levelUp and heal methods of their own, which you can then simply call from within StartRoom , combatskel and combatzombie without having to repeat the code that actually does the leveling up.
In case you do create a Player class, then it would seem natural to make heal and levelUp instance methods of Player. On to the method StartRoom : You are calling this method from within itself, or, to put it another way, you are calling it recursively, which I don't think represents what the method is actually supposed to do.
After all, the player doesn't re-enter the starting room, but it's just that the user is prompted again for input. So a better solution would be to put the code prompting the user for input into a loop that continues until the user enters "forward". Stingy Stingy 2, 5 5 silver badges 12 12 bronze badges. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
0コメント