• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interactive Fiction / Text Based Adventure

 
Kirok korik
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Long time lurker, first time poster. Wondering if I could ask on some advice and help on a group project.

What we have to do is to put together an:

Interactive Fiction / Text Based Adventure games with say
- 10 Story Sections / Rooms
- An Item System
- A Combat System
- A save system
- And perhaps the ability to change the rooms (editing the story)

Now we've had no problems so far with the combat system and are currently upgrading the code to add more complex options, as for the Item system I think we're going to do something simple with say giving each item a true or false state and changing certain things depending on what state each items variable is in (just need to work out how to integrate it)

We have a fairly good idea for the save system also just dump some relevant information to say a txt file on where the user is within the game and what items they have picked up etc

The main problem we are having is coming up with the rooms thinking of using an ArrayList with different rooms / sections then having a class to implement each section of the Array with the text associated with that rooms and then links to different rooms... only problem is we're not sure how to code it...

Anyway I was wondering if anyone had any suggestions or ideas on any part of project particularly how to implement the rooms, if someone could post some code or link to an existing project that would great.

Thanks in advance for any advice given
 
Jean-Sebastien Abella
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What if you have a class 'Room' that as an Arraylist of objects of type 'Connector'. When you are in a room you have the possibility to use any of the 'Connector'. And the 'Connector' would simply be a class containing 2 'Room's.
So when you build your world you first create the Rooms and then associate them with Connectors.
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kris Davidson:

Anyway I was wondering if anyone had any suggestions or ideas on any part of project particularly how to implement the rooms, if someone could post some code or link to an existing project that would great.



Hi,

You might like to check out SLAGE that I help work on. It is a game engine written in Java specifically tailored to easily write adventure games. It sounds like it is designed to do a lot of the things that you mentioned. It is not finished by any means, but you can certainly download the code from CVS, and if you are interested, even join the project. Maybe you can get some ideas from it for your own project.

Cheers, Jared.
 
Kirok korik
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone for replying... I'll definately take a look at Slage

Just wondering if I could trouble everyone for some more advice. So I'm using an array list to store the text / descriptions for various rooms. and I'm thinking a class called something like BookSection So I think the BookSection class should display the text / description associated with the current room and that it should also have links to 1 or more rooms and depending on user input (left, right etc) it should move the user to that room and change the text

I've come up with the following code and after searching the books I have (Head First Java, Just Java 2 and How to Program Java) and checking online I'm at a loss and was wondering if anyone had any idead how to code this (based on the bad and very limited code I have below)

class booksection{
int index //page number
string text //the story
int[]choices // the pages links
}

to display a page the program would display the string and the choices
and then load the choice the user made

method getchoices(page, thispage){
string text = "choises are"
thispage.choices.length
for (int i=0; i<2, i++){
text = text+thispage.choice[i]
}

return text
}

this would display the story and the appropriate choices
 
Kirok korik
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone,

someone I know gave me some advice but I'm not entirely sure what to do

You should have a booksection class. This class can only contain methods and variables related to a booksection so,

a booksection can have an int ID, String text, ArrayList or array of choices: int[] choice;
and the methods it can implement are for example although there may be more)

public String getText(){
return text;
}

public String getchoices(){ <----- see the difference between this and yours. No parameters
String response = "choices are";
for (int i=0; i<choices.length, i++){
response = response+choice[i]
}

So each booksection can now output its text and choices.
In the main section not the booksection class we can (assuming we have created a booksection object called myBookSection) get the choices for a specific booksection by using for example:

String choices= myBookSection.getchoices();

The important point here is that each booksection object can now return the text and choices that it contains. In the main java file, you have to find the right booksection id from your ArrayList and then use its methods.

In the main program you should create around 10 booksection objects (read from file or hard coded) and add these to an ArrayList of type <booksection>.

The functionality for operating the book and turning to different booksections should be implemented in the main java file.

If the user selects page 10 for example, you should find the booksection with id 10 from your ArrayList of booksections and display the text and the links for this page. This is then a recursive process.

Pseudo code for navigating the book:

create an empty booksection object
get the first page from your book arraylist and assign it to the booksection object created above

While (number of links in booksection is not equal to 0)

{
Display the booksection id
Display the booksection text
Get the user to input the id of the next booksection -(use getchoice method)
Get the user selected page from your book arraylist and assign it to the booksection object created above
}
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using an array or arraylist why not use a graph/tree structure to hold the rooms? Where the edges represent the connections between "rooms"?

I'm trying to implement something similiar myself (just for fun) where the rooms can be read/manipulated in xml files.

Ideally I want to make the rules and characters in external xml files too and basically just have an underlying game engine written in java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!