AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Question regarding linking and moving - any advice greatly a

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Web-based java games
View previous topic :: View next topic  
Author Message
Kirok
Guest





PostPosted: Thu Nov 10, 2005 12:06 pm    Post subject: Question regarding linking and moving - any advice greatly a Reply with quote



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.
Back to top
Kirok
Guest





PostPosted: Thu Nov 10, 2005 7:37 pm    Post subject: Re: Question regarding linking and moving - any advice great Reply with quote



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" <Name (AT) domain (DOT) com> wrote in message
news:ekCcf.4125$Xz1.2952 (AT) fe2 (DOT) news.blueyonder.co.uk...
Quote:
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.

Back to top
Dave
Guest





PostPosted: Mon Nov 21, 2005 9:25 am    Post subject: Re: Question regarding linking and moving - any advice great Reply with quote



Dude,

It sounds like you are new to Java, and possibly to programming.

You need to start small, and gradually work your way up to bigger and
better things.

#1 - Decide if you are writing a Java Applet or a Java Application. You
probably want to choose Applet, since many things are simplified in that
environment. Learn to use the Applet Runner that came with the JDK.
This will require you to write (or at least edit) a bit of HTML code.

#2 - Find some sample code. Read it and play with it until you
understand it very very well. It is important that you understand every
character of every line of code.

#3 - Shape the sample code to make it do what you want.

I suggest you start with a simple applet which just displays some text.
Add a few buttons to that. Avoid Swing for now, it will complicate your
life, start with simple AWT code. If you find code that uses classes
with names that start with J (like JFrame or JButton or JText), they are
Swing applets, avoid them.

Because you do not understand the basics of how computers work, your
life will be complicated. If you have talent for data, you will
succeed, if not, you should quit now. Less than 5% of the population
has the type of brain required to understand this junk. If you do not
understand, you will be frustrated to an extreme all of the time, and it
will never get easier. This is not a job you can learn by rote, you
have to fully understand what is happening and why.

Once you learn to deal with text, expand your code to read the text in
from a text file, so you can edit the text in a seperate file without
changing the code. This seperation is more efficient in many ways.

Byte arrays are better than Strings, but the String class will be a
better place for you to start.

Get used to reading Java HTML documentation, you will spend a lot of
your time reading it. You should have installed it on your machine as
part of the JDK install. Search for the last part of the name, followed
by .html. For example, to find the Applet documentation, search for
*applet.html.

Read these for starters:
java.applet.Applet.html
java.awt.Panel.html
java.awt.TextArea.html


You may want to start here...
http://home.earthlink.net/~patricia_shanahan/beginner.html
http://mindprod.com/jgloss/gettingstarted.html


Learn what you can from Roedy's site
http://mindprod.com/jgloss/jgloss.html


Reading text files...
http://www.faqs.org/docs/javap/source/TextReader.java

Using a TextArea...
http://javatechniques.com/public/java/docs/basics/jtextpane-font.html

You should also pick up a good reference book on Java, like Schildt's
"Complete Java2 Reference".

People will be willing to help you on the newsgroup boards, but only
after you do your homework (reading), post your code, and ask
intelligent questions. People often post their homework requirements
and ask for help -that is breaking the rules, and they get no help.

Happy reading!

--Dave

BTW - very few people read this newsgroup, you will get a lot more
action on:

51,000 comp.lang.programmer
6,500 comp.lang.java.gui
9,600 comp.lang.java.help
115 comp.lang.java

Java__Dave (AT) NOSPAM_Hotmail (DOT) com

Remove NOSPAM_ to reply...
The 2 underscores in Java__Dave are required...

___________________________________________________________________

In article <7XIcf.9461$Xz1.1181 (AT) fe2 (DOT) news.blueyonder.co.uk>,
"Kirok" <Name (AT) domain (DOT) com> wrote:

Quote:
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" <Name (AT) domain (DOT) com> wrote in message
news:ekCcf.4125$Xz1.2952 (AT) fe2 (DOT) 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.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Web-based java games All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.