Question regarding linking and moving - any advice greatly appreciated

Discussion in 'Java' started by Kirok, Nov 10, 2005.

  1. Kirok

    Kirok Guest

    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
    }

    return text
    }

    this would display the story and the appropriate choices

    Any replies are greatly appreciated.
    Kirok, Nov 10, 2005
    #1
    1. Advertising

  2. Kirok

    Roedy Green Guest

    On Thu, 10 Nov 2005 07:08:30 GMT, "Kirok" <> wrote,
    quoted or indirectly quoted someone who said :

    >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


    In a way your problem resembles a finite state automaton, where the
    rooms are analogous to the states.

    These are often neatly implemented as enums, with an enum constant per
    state.

    Your rooms can implement some methods common to all rooms each in an
    idiosyncratic way and also methods peculiar only to that one room.

    see http://mindprod.com/jgloss/enum.html
    http://mindprod.com/jgloss/finitestate.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 10, 2005
    #2
    1. Advertising

  3. Kirok

    Kirok Guest

    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
    }

    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" <> wrote in message
    news:OlCcf.4128$...
    > 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
    > }
    >
    > return text
    > }
    >
    > this would display the story and the appropriate choices
    >
    > Any replies are greatly appreciated.
    >
    >
    >
    Kirok, Nov 10, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Harvey
    Replies:
    1
    Views:
    328
    Guest
    Apr 2, 2004
  2. Tom
    Replies:
    3
    Views:
    2,495
  3. windandwaves

    feedback greatly appreciated

    windandwaves, Oct 6, 2005, in forum: HTML
    Replies:
    12
    Views:
    691
  4. N3TB1N
    Replies:
    4
    Views:
    577
    Stephen Waits
    May 10, 2004
  5. Replies:
    5
    Views:
    163
    HughPugh
    Feb 24, 2008
Loading...

Share This Page