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
}
-----------------
"Kirok" <Na**@domain.com> wrote in message
news:Wk*****************@fe2.news.blueyonder.co.uk ...
Hey Everyone,
Thanks for reading, heres what I'm trying to do I have an array of say 10
items each item contains the text / description for a room.
Now I would like to create a class (lets call it BookSection) this class
will display the text for the current room the user is in and then have
links to other rooms (left, right, east, west, etc) then dependant upon
the choice made by the user will move to the new room and display 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 idea 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
Any replies are greatly appreciated.