Creating a Java Text-Based RPG: Questions & Experiences

  • Thread starter MysticDude
  • Start date
  • Tags
    Java
In summary, Inform is a programming language designed for writing text-based games, and there is a large "Interactive Fiction" community online of people who create and enjoy text-based games.
  • #1
MysticDude
Gold Member
142
0
Hey guy, I was just thinking about making a simple Java text-based game. You know, the ones where you do everything in the command prompt or terminal and no GUI involved. I want to make something that a person can make and "account" where the pass and username are both saved in a text file since I don't know how else to save a file in Java. If I was to make an RPG (role playing game for those of you who don't know), how would I map out stores and things like that? Or make the people with quests on coordinates where monsters won't come out or anything? Would I need to make a separate file for the inventory of the person? So many questions!

I already have previous Java experience, as I already took AP Comp Sci and got a 4 on the test, so no need to lecture me on the basics :D.

Have any of you done this? If you had, was it hard to plan out things?

I apologize if there is already another thread like this :D
 
Technology news on Phys.org
  • #2
Maybe you should consider looking into Inform.

Alternately there is a rather large "Interactive Fiction" community on the internet of people who create and enjoy text based games, maybe some of them would have some tips as to how to get started.
 
  • #3
Coin said:
Maybe you should consider looking into Inform.

Alternately there is a rather large "Interactive Fiction" community on the internet of people who create and enjoy text based games, maybe some of them would have some tips as to how to get started.


Looks like an interesting thing, but is written in Fortran? I ask because I read on a part of their site and it included some Fortran. I want to write my program in Java.
 
  • #5
MysticDude said:
Looks like an interesting thing, but is written in Fortran? I ask because I read on a part of their site and it included some Fortran. I want to write my program in Java.

Inform is actually its own programming language designed for writing text based games. I do not think it is related to Fortran.
 
  • #6
rcgldr said:
One of the early text based games:

http://en.wikipedia.org/wiki/Colossal_Cave_Adventure


Do you know where I can actually play a modern version of it? By that I mean like a flash version of it.

Coin said:
Inform is actually its own programming language designed for writing text based games. I do not think it is related to Fortran.

So, do you know or have any tips for me since I want to write my program/game in Java? I don't want to learn a new language because of one game.
 
  • #7
well google provides a few links that let you play it (not necessarily online however).

It could be useful to look at the source code to that game (and others). While you may not know the language it is written in you still should be able to get an idea of how things work. Using this knowledge you can apply it to your java code.
 
  • #8
MysticDude said:
Do you know where I can actually play a modern version of it? By that I mean like a flash version of it.

You should be able to find a pre-compiled version that runs under Windows or Linux or whatever. Starting from the Wikipedia page I quickly found one that runs under Mac OS X. It displays a window that looks just like a text-only CRT display from the 1970s, with green text and a hint of a pixel raster in the background. Ah, nostalgia! :cool: I wasted a lot of time with this game when I was a graduate student. I wish I still had the three-page map that I drew of the cave.

If you look at the original FORTRAN code, or probably better, the C version written a few years later with the approval of the original authors, you should be able to figure out the general structure well enough to write your own game in Java. It's purely procedural code, with no fancy object-oriented stuff (it's from the mid 1970s, remember!).
 

Attachments

  • adventure.jpg
    adventure.jpg
    55.5 KB · Views: 479
Last edited:
  • #9
jtbell said:
You should be able to find a pre-compiled version that runs under Windows or Linux or whatever. Starting from the Wikipedia page I quickly found one that runs under Mac OS X. It displays a window that looks just like a text-only CRT display from the 1970s, with green text and a hint of a pixel raster in the background. Ah, nostalgia! :cool: I wasted a lot of time with this game when I was a graduate student. I wish I still had the three-page map that I drew of the cave.

If you look at the original FORTRAN code, or probably better, the C version written a few years later with the approval of the original authors, you should be able to figure out the general structure well enough to write your own game in Java. It's purely procedural code, with no fancy object-oriented stuff (it's from the mid 1970s, remember!).

But,but,but...Java is an OOP. The first thing that came up to my head was make a large 2d array of the map. I'm really used to using Java and objects because that was the first language I actually went in to.

By the way, I found of http://www.wesleyholland.com/misc/adventure/adventure.html" but I have no clue on how to pick things up. In your attachment I saw you type "take diamonds" but I can't even do take food in this version.

Oh and jtbell, would you leave your computer on all night so you wouldn't lose the game's current state?
 
Last edited by a moderator:
  • #10
MysticDude said:
But,but,but...Java is an OOP. The first thing that came up to my head was make a large 2d array of the map. I'm really used to using Java and objects because that was the first language I actually went in to.

It's not all that difficult to write an RPG, depending on how in-depth you want to make it. I made a very simple one in JavaScript from scratch in a week or so WAY back in 2001:

http://www.suave.net/~dave/squirrel6.html

The tricky part is making sure you leave yourself room to do all the wacky things you're going to want to do. "Only monsters X,Y,Z will attack you on this square", or "you can't kill this NPC unless you already completed task C", or "this NPC will be hostile and then switch to non-hostile after X", or "change the terrain at this space when something happens".

You're going to want to break 90% of your rules with some bizarro exception clause at some point. So make sure you plan for it in advance!

Anyway, it's only as difficult as you want it to be. You might be able to make a game more easily using a pre-existing library, but if that's the case, don't expect Java. I don't think you'll find too many libraries explicitly for text-based Java games, but if you can't find any, it's not all that hard to do from scratch, unless you're expecting to publish either your library or your game. On that note, who's your target audience? How will they play?

DaveE
 
  • #11
davee123 said:
It's not all that difficult to write an RPG, depending on how in-depth you want to make it. I made a very simple one in JavaScript from scratch in a week or so WAY back in 2001:

http://www.suave.net/~dave/squirrel6.html

The tricky part is making sure you leave yourself room to do all the wacky things you're going to want to do. "Only monsters X,Y,Z will attack you on this square", or "you can't kill this NPC unless you already completed task C", or "this NPC will be hostile and then switch to non-hostile after X", or "change the terrain at this space when something happens".

You're going to want to break 90% of your rules with some bizarro exception clause at some point. So make sure you plan for it in advance!

Anyway, it's only as difficult as you want it to be. You might be able to make a game more easily using a pre-existing library, but if that's the case, don't expect Java. I don't think you'll find too many libraries explicitly for text-based Java games, but if you can't find any, it's not all that hard to do from scratch, unless you're expecting to publish either your library or your game. On that note, who's your target audience? How will they play?

DaveE
Thanks for the advice! I want to make a simple game for practicing as I want to do something with software and maybe after this get more into GUIs. I guess my audience would be anyone really. They will play by compiling the Java code, in other words, they have to have Java installed and what not. I was thinking of doing this from scratch, that is why I am asking for help.
 
  • #12
MysticDude said:
But,but,but...Java is an OOP. The first thing that came up to my head was make a large 2d array of the map. I'm really used to using Java and objects because that was the first language I actually went in to.

Well, I never learned Java so I can't help with that. However, I'm somewhat familiar with C++. It would seem natural to represent each location as an object so you can store other objects in it. The challenge would be representing the collection of locations and the connections between them.

In C++ the first thing that comes to mind for connecting two objects is pointers, but that leads to a problem in initializing all the pointers at the beginning of the game. You can't set a pointer to point to an object before the object itself exists, so you have to create the locations first and then set up the pointers to them.

So that leads me to the "map" class in the C++ standard library. In C++, a "map" isn't a graph-like structure like you might think. It's a collection of data items, all of the same type, e.g. "locations", each identified by a "key" which in this case might be simply be the name of the location, as a string ("bird chamber", "top of pit", etc.). If the map is named 'locations', the bird chamber would simply be locations["bird chamber"]. It looks rather like an array, but with strings instead of integers as indexes. Each location-object would contain a list of possible directions, associated with the names of the locations they lead to. Maybe Java has something like this.

By the way, I found of http://www.wesleyholland.com/misc/adventure/adventure.html" but I have no clue on how to pick things up. In your attachment I saw you type "take diamonds" but I can't even do take food in this version.

It looks like that version uses 'get' instead of 'take'. It's probably based on an earlier version than the one I have, which goes up to 550 points, not 350.

Oh and jtbell, would you leave your computer on all night so you wouldn't lose the game's current state?

My version has a "Save Game" option in the program's Mac OS menus, which probably saves the state variables in a file. The computers that I originally played "Adventure" on (Digital Equipment Corp.'s PDP-10 and VAX computers) had a feature that saved to disk a complete memory dump of a running program, that could be loaded and resumed later. One invoked it from the game by typing 'save' at the command prompt, followed by a name which became the file name that it was saved as. This was basically an EXE file that you could load and run from the system command prompt. This was a common tactic when you were about to do something that might get you killed for good. :wink:
 
Last edited by a moderator:
  • #13
I was thinking about having around three 2D arrays. One for the location of the person, one for the text when the player goes onto a specific location, and one for items that can be picked up. Does that seem okay? For testing I'm thinking about having a simple 4x4, or maybe a 2x2 (to make things easier) 2D array. I haven't written any code yet since I want to know what I'm tackling ahead.
 
  • #14
MysticDude said:
I was thinking about having around three 2D arrays.

I'd advise doing arrays of "map square" objects. Each map square might have something like:

1) Description of that square
2) List of valid exit objects. Each exit contains:
a) pointer/id to which square it will take you to
b) description of that exit
c) other junk like "you need a key" or "is invisible" or "is blocked by NPC"
3) List of references to NPCs also on this square
4) List of references to items also on this square

No need to actually make the array a 2-D array. That way (because you KNOW you'll want to break the rule at some point), you can make a non-traditional doorway that jumps you to another location.

You probably also want things like:

- A global array of static NPCs
NPCs that might be unique and wander around, or ones that need to maintain state (for example a guard standing at a door who needs to maintain his hit points, etc). You can also have non-static NPCs, if you want some of your NPCs to appear and disappear (for example a rat that appears in a room, but is gone when you return), and you wouldn't need to put them in the static NPC list. I would guess it might contain something like:

1) NPC Name
2) NPC Hostility flag?
3) List of references to items carried (that will assumably drop when killed or whatever)
4) Reference to map location of NPC
5) Hit Points (and other stats like skill, strength, etc)
6) Other whatevers (what they will say to you, what items you can give them, etc)

- A global list of items
Again, items may need to maintain state, like a safe that's open or closed, a bag with N coins in it, or whatever. Might look like:
1) Item Name
2) Reference to location of Item (could be in an NPC or player inventory, a map square, or even in another item!)
3) Other stuff (item state (broken, etc), item value, equip bonuses, etc)

===

If you do a map array of items, a map array of texts, etc, then that's not very object-oriented, for starters. Also, you're potentially using a lot of space that you won't need. If (for example) you have a large, inaccessible area of the map, no items will ever appear there, and you're using memory that's not really needed. Even then, most of the time, many of your rooms will probably be empty.

I WOULD recommend, however, that you INITIALIZE your map using something handy-dandy like a series of text-based arrays or something. That way, it's easy to change things intuitively when it comes time to modify your adventure.

DaveE
 
Last edited:
  • #15
Ok so DaveE (hey, my name is David :D), what you are saying is to make one array that contains all of my information for that square?

Also, for starters, I just want to make an exploring game. Where you just walk around and collect things.
 
  • #16
MysticDude said:
Ok so DaveE (hey, my name is David :D), what you are saying is to make one array that contains all of my information for that square?

I would go that way-- it's the object oriented approach. You probably want things like a "map square object" that contains all the information about that map square.

Mostly, it's handy when you want to add new things-- you don't have to worry about having big global variables (or passing lots of non-globals), and you can add a property to an object without requiring it to be set for EVERYTHING.

MysticDude said:
Also, for starters, I just want to make an exploring game. Where you just walk around and collect things.

Again, making it more object oriented means that you'll have a FAR easier time when/if you want to do things like add NPCs or other complex things.

DaveE
 

1. How do I get started with creating a Java text-based RPG?

To get started, you will need to have a basic understanding of Java programming language. You can start by learning the fundamentals of Java, such as syntax, data types, and control structures. Once you have a good understanding of these concepts, you can start designing your game and implementing it using Java code.

2. What tools or software do I need to create a Java text-based RPG?

You will need a Java development environment, such as Eclipse or IntelliJ, to write and run your code. You may also want to use a text editor for writing code and a graphics editor for creating any visual elements for your game. Additionally, you will need to have a Java Development Kit (JDK) installed on your computer for compiling and running your code.

3. Can I incorporate graphics or sound into my Java text-based RPG?

Yes, you can incorporate graphics and sound into your game by using libraries such as JavaFX or Swing. These libraries allow you to create graphical user interfaces and add images, animations, and sound effects to your game. However, keep in mind that a text-based RPG primarily relies on text-based interactions, so the use of graphics and sound should be minimal.

4. How do I handle player input and game logic in a Java text-based RPG?

To handle player input, you can use the Scanner class in Java to read user input from the console. As for game logic, you can use conditional statements and loops to create a flow for the game, such as moving between different locations, making decisions, and updating player stats.

5. What are some common challenges when creating a Java text-based RPG?

Some common challenges include designing a compelling and engaging story, balancing game difficulty, and creating a user-friendly interface. It can also be challenging to keep track of and manage different game states and variables. Additionally, debugging and troubleshooting errors in your code can be time-consuming but essential for creating a functioning game.

Similar threads

  • Programming and Computer Science
Replies
5
Views
945
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
13
Views
4K
  • Programming and Computer Science
Replies
33
Views
8K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
12
Views
4K
Back
Top