Assignment #77 and Adventure 2
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: Adventure 2
/// File Name: Adventure2.java
/// Date Finished: 10/20/2015
import java.util.Scanner;
public class Adventure2
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int nextroom = 1;
String choice = "";
while ( nextroom != 0 )
{
if ( nextroom == 1 )
{
System.out.println( "\nYou are in a mysterious old house. Would you like to go up to the \"attic\" or down to the \"cellar\"?" );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("attic") )
nextroom = 2;
else if ( choice.equals("cellar") )
nextroom = 3;
else
System.out.println( "\nThat's not a choice, silly!" );
}
else if ( nextroom == 2 )
{
System.out.println( "\nIn the attic, there is an old chest. You may either open the \"chest\" or go \"back\"." );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("back") )
nextroom = 1;
else if ( choice.equals("chest") )
nextroom = 4;
else
System.out.println( "\nThat's not a choice, silly!" );
}
else if ( nextroom == 3 )
{
System.out.println( "\nYou go down the stairs into the cellar. In the cellar, you can hear growls and scratching sounds behind a tall door. Nearby, there is a large painting which has fallen off the wall to reveal a passageway behind it! Do you want to open the \"door\", explore the \"passageway\", or go \"back\"?" );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("back") )
nextroom = 1;
else if ( choice.equals("door") )
nextroom = 5;
else if ( choice.equals("passageway") )
nextroom = 6;
else
System.out.println( "\nThat's not a choice, silly!" );
}
else if ( nextroom == 4 )
{
System.out.println( "\nYou open the chest to find a large pile of gold and jewels. You take the treasure and run away! You're rich! Hopefully noone comes looking for it..." );
nextroom = 0;
}
else if ( nextroom == 5 )
{
System.out.println( "\nCautiously, you open the door. It's a puppy! Yay! A new pet!" );
nextroom = 0;
}
else
{
System.out.println( "\nYou enter the dark, damp passageway. After walking down the twisting, turning hall for a long time, you end up back outside the house! Oh well..." );
nextroom = 0;
}
}
System.out.println( "\nTHE END\n" );
}
}
Picture of the output