This is a game that allows you to pick your path.
Here is an example:
2. Make a new folder to hold your game.
3. Paste this code in Java. Save it as CYOA. Save it to the folder.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CYOA extends Applet implements ActionListener
{
Panel p_screen;
Panel s1, s2; //add more screens here
CardLayout cdLayout = new CardLayout ();
public void init ()
{
p_screen = new Panel ();
p_screen.setLayout (cdLayout);
//make the screens here
screen1 ();
screen2 ();
resize (400, 400);
setLayout (new BorderLayout ());
add ("Center", p_screen);
}
public void screen1 ()
{
s1 = new Panel ();
s1.setBackground (Color.white);
JLabel title = new JLabel ("Choose your own adventure.");
JLabel pic = new JLabel (createImageIcon ("title.jpg"));
JButton next = new JButton ("Next");
next.setActionCommand ("2");
next.addActionListener (this);
s1.add (title);
s1.add (pic);
s1.add (next);
p_screen.add ("1", s1);
}
public void screen2 ()
{
s2 = new Panel ();
s2.setBackground (Color.yellow);
JLabel title = new JLabel ("You wake up...");
title.setFont (new Font ("Jokerman", Font.PLAIN, 20));
JTextArea text = new JTextArea (5,20);
text.append ("You wake up in the morning and find you are late.\n");
text.append ("You grab your stuff and rush out the door, \nback pack in hand.\n");
text.append ("\nDo you: ");
JButton optA = new JButton ("a) grab some granola bars");
optA.setActionCommand ("3");
optA.addActionListener (this);
JButton optB = new JButton ("b) grab an apple");
optB.setActionCommand ("4");
optB.addActionListener (this);
s2.add (title);
s2.add (text);
s2.add (optA);
s2.add (optB);
p_screen.add ("2", s2);
}
public void actionPerformed (ActionEvent e)
{
if (e.getActionCommand ().equals ("1"))
cdLayout.show (p_screen, "1");
else if (e.getActionCommand ().equals ("2"))
cdLayout.show (p_screen, "2");
}
protected static ImageIcon createImageIcon (String path)
{ //change the red to your class name
java.net.URL imgURL = CYOA.class.getResource (path);
if (imgURL != null)
return new ImageIcon (imgURL);
else
{
System.err.println ("Couldn't find file: " + path);
return null;
}
}
}
4. Edit the code to make your first screen.
Screen 1The title of your game. Picture. Button that leads to screen 2. |
5. Edit the code to make your second screen. It should be something like this, but change it so that it has your own story in it.
Screen 2You are a student at Turner Fenton Secondary School. One Monday morning, you wake up late and you you rush to get ready. You grab a fist full of granola bars and your back pack and you run out the door, slamming it shut behind you. That's when it hits you. This isn't your street! And where did your house go? Where are you? You appear to be standing on a path in the middle of a jungle. To the north, you can see a clearing ahead. To the south, there is a deeper, darker section of the jungle. What do you do? If you choose to go north on the path, go to screen 3. If you choose to go south on the path, go to screen 4. |
6. Make all of your other screens.
Screen 3You decide that the clearing in the jungle looks more inviting than the deeper, darker jungle. As you walk towards it, you hear noises in the jungle. It is hard to tell what they are. As you approach the clearning, you notice that the cleaning has been caused by a fire. Surrounding you are charred logs and ashes. You start to rethink your decision. If you choose to go south on the path, go to screen 4. If you choose to continue, go to screen 5. |
| Leve 1-2 | Level 3 | Level 4 | Level 4+ | |
| Screens | less than 15 screens. | 15-20 screens. | 20+ screens. | Screens are reused in the story. There is one game over screen, for example. |
| Pictures, Formatting. | 10 pictures. | Changed fonts, writing, background colours. | Resized the screen to a good size. | Outstanding layout, picture on every page. |
| Widgets | Labels and buttons appear. | Every button works. | Labels are used well. No text runs off the page. | A new widget is used (radio buttons are a great option). |
| Grammar | Many grammar and spelling errors. | Few grammar and spelling errors. | No grammar and spelling errors. | Outstanding spelling and grammer. Story is clear and is well written. |