Java text based game tutorials

Hello people of this forum. I am more experienced in web based languages such as PHP, RoR and a couple system languages however I need to learn Java for one of my university classes. I figured the best way to learn the language would be to have a little fun doing so.

I would like to create a text based rpg style game linking multiple classes and dealing with strings as user inputs which act as triggers.

Does anyone have any recommendation, tutorials or advice for someone like myself?

Caleb.

You’re going to need to interact with native code if you’re going to get fancy (colors, “movies” things like that).

I know of two resources (that i’ve never used) using ncurses:

http://www.pitman.co.za/projects/charva/ (swing on the console)

http://sourceforge.net/projects/javacurses/ (ncurses binding)

I would just pretend it’s the console and fashion a big JTextArea to look like it. You’ll get a lot more control a lot more easily.

There is also
libcaca (for color on the console too). I’m not aware of any java binding.

If by text RPG, you mean something like the old console adventure games like Zork, then I’d suggest using the console and keeping things simple. Writing text is easy using print.out.println(…); However input takes a bit more work. I’d look at wrapping the console input stream System.in, within a java.io.BufferedReader class. This will allow you to grab one line at a time, rather than just a stream of characters. This could be wrapped in a java.io.StreamTokenizer to split the stream into words. You will need to set it to return eoln as a token, after which you can call it repeatedly for each line until you get the eoln token. At this point you would need to parse the tokens. Probably best to keep it simple . You will also need arrays of room objects, including data fields for description, exit destinations (NSEW) etc. Also a collection of game objects that can be located in rooms or on the player. It might be easiest to make the player a sub-class of room. Objects will need fields defining their description and various attributes.

Commands
N,S,E & W: Look up appropriate destination room number in current room and set player location. Print room description
Get : Search collection of objects for one with this name. Check it is in the same room as player; Set object location to player.
Drop : Search collection of objects for one with this name: Check it is on player; Set location to player’s current location

Write code to support other verbs as needed by the game’s puzzles. These normally check conditions (e.g. is player carrying a key; is player in the room with a locked door; is the door locked => unlock door - write success text, modify room description, modify room exits.

If however you want RPG style character classes and battle system, then console i/o will probably be too limiting and you will need to write a GUI application. At this point it is best to use an IDE with a form editor (e.g. Netbeans), as this will make life easier. Having said that, the degree of difficulty has increased a level if you haven’t used java before, and it might be too much for a time-limited project.

For the RPG version, the main difference is that each action has a success probabilty based on players stats. You also need to keep the player constantly informed of their health points, ailments etc. and this is where a pure console approach tends to be inadequate

Thank you everyone for your replies! When I get home from work I will start working on it.
I think I will go with a big java console style text box to run something like Zork. If I want to get all fancy later I can add some objects. I’m really glade about the quality of posts and feedback I received back.

When I was first learning Java I used a package called TerminalIO for console input. I found this after a quick Google search, but I’m not sure if it’s the same. I never looked at TerminalIO’s source, I only used its functions.

Actually, it’s likely that this is probably it.