Creating A 'Create Your Own Adventure' Game In Java
21 replies, posted
I am currently writing a 'Create Your Own Adventure' game in Java. I know the basics of java, and I know how to write a story. There will be story, choices, then more story. Here is a chunk of the story so far
[quote] The year is 1917, and America has just entered the Great War. It is a cold morning a few miles off of the coast of New York,
and you can see the fog rolling across the water. You shiver and embrace yourself, only to fend off some of the cold. As you stare
off of the bow the fog begins to clear, and Lady Liberty comes into view. Your hear races in excitement, and you shake more.
///////////////////NEXT///////////////////////////
Your nose feels a sharp breeze, and starts to run. You wipe it off on the sleeve of your worn out jacket, the one your father
gave to you. You look around to see if anyone noticed, and you see a little girl around seven holding the hand of her mother. She is
staring right at you. What do you do?
///////////////Choice #1//////////////
1. Give her a look to frighten her.
2. Ignore her.
3. Give her a friendly smile and a wave.
/////////////NEXT/////////////////
The little girl looks embarrassed and turns away, a shy child obviously. You remember that age don't you? Clinging to your
fathers hand wherever you go, shy and afraid of the world. She isn't too different from you, now is she? Let's talk about your father
now, shall we?
//////////////NEXT////////////////////
Unlike most fathers, yours wasn't a drunk. He was all you had, you loved him. But you know that, don't you? He raised you
from birth, and made you into the man you are today. He loved your mother, and even though you killed her in child birth he never
blamed you. Never did he guilt you or look down on you for it, he viewed you as the last living thing of her. He gave you the best life
he could, which wasn't very much.
///////////////CHOICE #2////////////////
Growing up in poverty wasn't always easy, or ever easy. Your father loved you, and kept you out of the factories as long as he
could, but you two could only go so long without two sources of income. The three factories closest to your hometown where the
Steel Mill, the Lumber Mill and the Textile Mill. The working conditions where all terrible and kids died everyday working in these
factories. But you needed the money badly, so you got a job. Where did you work at?
1. Steel Mill
2. Textile Mill
3. Lumber Mill
[/quote]
Now, the problems is (I feel dumb) I have NO clue how to do this, or even how to start. If you can help me with how to write the code, or give me a tutorial (I couldn't find the right kind) it would really help. You've helped me before Facepunch, lets see if you can help me again!
wait wait wait wait, you want to right a game like that in Java but have no idea where to start?
If i read that correctly, best place to start is with the Canvas and Java 2D graphics
I HAZ BOXXYS :D
1. have a string called GameFolder, so you can use this for the gamefolder, when the user creates new game, the app creates a new folder that called as in the GameFolder
2. have a base class that contains the "name" string(name of the textfile), a "text" string, and a function to load the textfile into your "text" string
3. have another base class that contains some strings about the choices, a function to output these texts and a input, and another function for loading from file
4. have a List<"your first base class"> texts; where you can add your texts later
5. have another List that contains the choices
6. have a List<string> files; that contains, the filenames of the files in a sequence
7. have a simple loop for loading the files to the Lists
it's not a best way, but good enough to start, it's up to you...
[QUOTE=Werem00se;25935666]I am currently writing a 'Create Your Own Adventure' game in Java. I know the basics of java, and I know how to write a story. There will be story, choices, then more story. Here is a chunk of the story so far
Now, the problems is (I feel dumb) I have NO clue how to do this, or even how to start. If you can help me with how to write the code, or give me a tutorial (I couldn't find the right kind) it would really help. You've helped me before Facepunch, lets see if you can help me again![/QUOTE]
You need to think of some kind of easy parseable and human readable format.
Have something like sections, which contain a text (that is the stuff the player will read) and choices, that can go to other sections.
Further more you probably want to have the ability to create numeric variables (which could be stored in some Map, possibly Java.util.Hashtable, in your Java app) and the ability to create items or other entities.
In Java you'd open that textfile, read each section and either load it into memory or, probably more scalable, just save the line number and section-name.
Then you search the start-section (you could simply require a specific name for it), print the text and the choices and upon entering a valid choice, look what the file contains so you can take the actions it says (e.g. modifying some variable or jumping to another section).
Or you could embed a scripting language, e.g. Lua, so you don't have to write a parser yourself.
From my understanding CYOA are just about switching to different pages. So for something as simple as that you could load each page into an array and depending on the choice switch to the page in the array. You would just need to do some basic parsing for what the page should display and where the choices go, for example
[code]
start_page 1
blah blah blah blah
choice "Go to the dungeon" 2
end_page
start_page 2
you are in the dungeon
end_page
[/code]
Or something like that, I am not really sure.
Use gotos
Best tool for the job
Heh. I just recently made a site that does the exact same thing. You didn't happen to get the idea from it did you? :v:
[QUOTE=PieClock;25940493]Heh. I just recently made a site that does the exact same thing. You didn't happen to get the idea from it did you? :v:[/QUOTE]
[url]http://www.choiceofgames.com/[/url] ?
[QUOTE=Werem00se;25942167][url]http://www.choiceofgames.com/[/url] ?[/QUOTE]
Nah. No domain or anything, thought you might have seen the video I had posted in the Web Dev section:
[media]http://www.youtube.com/watch?v=w6c-utuJClA[/media]
It's not much to look at (yet) but as far as I can tell it's the same concept. :smile:
Use choicescript (on the above mentioned site, choice of games), it's much easier.
[QUOTE=supersnail11;25945431]Use choicescript (on the above mentioned site, choice of games), it's much easier.[/QUOTE]
I read the tutorial several times. It makes NO sense to me, or tell you how to do anything.
[editline]9th November 2010[/editline]
[QUOTE=PieClock;25944900]Nah. No domain or anything, thought you might have seen the video I had posted in the Web Dev section:
[media]http://www.youtube.com/watch?v=w6c-utuJClA[/media]
It's not much to look at (yet) but as far as I can tell it's the same concept. :smile:[/QUOTE]
Ha, so any help that you can spare on this subject? Advice?
[QUOTE=Werem00se;25952648]Ha, so any help that you can spare on this subject? Advice?[/QUOTE]
Nothing specific. It's not a hard thing to do. Just learn what you need to know and implant it to what you already have and find a good way of storing the data.
[code]
[import java.util.Scanner;
public class ww1HorrorChoiceOf
{
public static void main (String [] args){
int test;
int choice;
Scanner scan = new Scanner (System.in);
Scanner scan1 = new Scanner (System.in);
System.out.println("Would you like to start?");
System.out.print("Yes 1, No 2.");
test = scan.nextInt();
if(test == 1){
System.out.println ("The year is 1917, and America has just entered the Great War."
);
System.out.println("It is a cold morning a few miles off of the coast of New York,and you can see the fog rolling across the water.");
System.out.println("You shiver and embrace yourself, only to fend off some of the cold.");
System.out.println("As you stare off of the bow the fog begins to clear, and Lady Liberty comes into view.");
System.out.println("Your hear races in excitement, and you shake more.");
System.out.print("Press 1 to continue.");
choice = scan.nextInt();
if(choice == 1){
System.out.println(" Your nose feels a sharp breeze, and starts to run."
);
System.out.println("You wipe it off on the sleeve of your worn out jacket,the one your father gave to you.");
System.out.println("You look around to see if anyone noticed, and you see a little girl around seven holding the hand of her mother.");
System.out.println("She is staring right at you. What do you do?");
System.out.println("1. Give her a look to frighten her.");
System.out.println("2. Ignore her.");
System.out.println("3. Give her a friendly smile and a wave.");
System.out.println("Make your choice = 1,2,3");
if(choice == 1);{
if(choice == 2);{
if(choice == 3);{
choice = scan.nextInt();
System.out.print("The little girl looks embarrassed and turns away, a shy child obviously.");
System.out.println("You remember that age don't you? Clinging to your father's hand wherever you go, shy and afraid of the world.");
System.out.println("She isn't too different from you, now is she? Let's talk about your father now, shall we?");
System.out.println("Press 1 to continue.");
if(choice == 1);{
choice = scan.nextInt();
System.out.print("Unlike most fathers, yours wasn't a drunk. He was all you had, you loved him. But you know that, don't you?");
System.out.println("He raised youfrom birth, and made you into the man you are today. He loved your mother, and even though you killed her in child birth he never blamed you.");
System.out.println("Never did he guilt you or look down on you for it, he viewed you as the last living thing of her. He gave you the best life he could, which wasn't very much.");
System.out.println("Press 1 to continue.");
if(choice == 1);{
choice = scan.nextInt();
System.out.print("Growing up in poverty wasn't always easy, or ever easy. Your father loved you,");
System.out.println("and kept you out of the factories as long as he could. But, you two could only go so long without two sources of income.");
System.out.println("The three factories closest to your hometown where the Steel Mill, the Lumber Mill and the Textile Mill. The working conditions where all terrible,");
System.out.println("and kids died everyday working in these factories. But you needed the money badly, so you got a job. Where did you work at?");
System.out.println("1. Steel Mill");
System.out.println("2. Textile Mill");
System.out.println("3. Lumber Mill");
}
}
}
}
}
}
}
}
}[/code]
Am I doing it right?... I mean, it DOES work. :/
It looks quite messy.
[code]
if(choice == 1);{
if(choice == 2);{
if(choice == 3);{[/code]
Also unless I'm mistaken those semicolons should not be there.
Put the output text in an array, you don't need all them [i]System.out.println[/i] you can use the '\n' escape character for a new line.
And use meaningful names for your variables, a variable called test does not tell the programmer much about it.
You only need to use [b]one[/b] Scanner object, you don't need a new one for each input.
Also a large amount of [b]if[/b] statements are quite messy, try use a [b]switch / case statement[/b] instead.
Maybe you should start from the beginning with a good Java tutorial rather than trying to make something before you have a good understanding of the language.
I found [url=http://www.javavideotutes.com/]these video tutorials[/url] to be quite helpful.
[QUOTE=Werem00se;25952648]I read the tutorial several times. It makes NO sense to me, or tell you how to do anything.
[/QUOTE]
Really? I find it an easy to use tutorial.
Did you use this one [url=http://www.choiceofgames.com/blog/choicescript-intro/]here[/url]?
Open [url=http://www.choiceofgames.com/dragon/scenes/startup.txt]the startup file[/url] and edit it. It's easy to learn!
[QUOTE=supersnail11;25979493]Really? I find it an easy to use tutorial.
Did you use this one [url=http://www.choiceofgames.com/blog/choicescript-intro/]here[/url]?
Open [url=http://www.choiceofgames.com/dragon/scenes/startup.txt]the startup file[/url] and edit it. It's easy to learn![/QUOTE]
Yes, I did use that one, but it really confuses me. Which is odd, because the best way I learn is from reading. How do I get the startup file to work like this [url]http://www.choiceofgames.com/dragon/[/url] ?
You have really bad writing, don't make this.
[QUOTE=The_Fly56556;26026621]You have really bad writing, don't make this.[/QUOTE]
Hush, you.
[QUOTE=The_Fly56556;26026621]You have really bad writing, don't make this.[/QUOTE]
I disagree. Have a disagree.
OP, use [url=http://see.stanford.edu/see/courseinfo.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111]this[/url].
[QUOTE=Werem00se;25991717]Yes, I did use that one, but it really confuses me. Which is odd, because the best way I learn is from reading. How do I get the startup file to work like this [url]http://www.choiceofgames.com/dragon/[/url] ?[/QUOTE]
Download ChoiceScript. Extract, and go to Web > mygame > scenes.
Open the file startup.txt. Edit, and run using index.html in the above directory.
[QUOTE=supersnail11;26061485]Download ChoiceScript. Extract, and go to Web > mygame > scenes.
Open the file startup.txt. Edit, and run using index.html in the above directory.[/QUOTE]
You have no idea how much that helped. Thank you so much, this just made my job 2x easier. :D
[editline]15th November 2010[/editline]
[QUOTE=The_Fly56556;26026621]You have really bad writing, don't make this.[/QUOTE]
I know. But you insulting me doesn't make my writing any better.
Sorry, you need to Log In to post a reply to this thread.