Assignment #77 and Adventure 2
Code
/// Name: Lauren Baird
/// Period: 7
/// Program Name: Adventure 2
/// File Name: Adventure2.java
/// Date Finished: 11/16/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 = "";
System.out.println();
System.out.println( "LAUREN'S TINY ADVENTURE pt.2!" );
System.out.println();
while ( nextroom != 0 && nextroom != 7 )
{
System.out.println( "You are in an abondoned house. The main entrance is locked. Would you " );
System.out.println( "like to go \"upstairs\" or down the \"hallway\"? " );
System.out.print( "> " );
choice = keyboard.next();
System.out.println();
if ( choice.equals("upstairs") )
nextroom = 2;
else if ( choice.equals("hallway") )
nextroom = 3;
else
System.out.println( choice + " wasn't one of the options. Try again." );
if ( nextroom == 2 )
{
System.out.println( "There is a \"door\" upstairs. You can always go \"back\". " );
System.out.print( "> " );
choice = keyboard.next();
System.out.println();
if ( choice.equals("door") )
nextroom = 4;
else if ( choice.equals("back") )
nextroom = 1;
else
System.out.println( choice + " wasn't one of the options. Try again." );
}
if ( nextroom == 3 )
{
System.out.println( "At the end of the hallway there is a door. Would you like to go " );
System.out.println( "in the \"bedroom\" to your right? Or would you like to go \"back\" ?" );
System.out.print( "> " );
choice = keyboard.next();
System.out.println();
if ( choice.equals("bedroom") )
nextroom = 5;
else if ( choice.equals("back") )
nextroom = 1;
else
System.out.println( choice + " wasn't one of the options. Try again." );
}
if ( nextroom == 4 )
{
System.out.println( "There is a window in the empty room. You can try to \"climb\" " );
System.out.println( "out through the window, or go \"back\". " );
System.out.print( "> " );
choice = keyboard.next();
System.out.println();
if ( choice.equals("climb") )
nextroom = 7;
else if ( choice.equals("back") )
nextroom = 2;
}
if ( nextroom == 5 )
{
System.out.println( "At the end of the room there is a door that goes \"outside\"." );
System.out.println( "You can also go \"back\". " );
System.out.print( "> " );
choice = keyboard.next();
System.out.println();
if ( choice.equals("outside") )
nextroom = 6;
else if ( choice.equals("back") )
nextroom = 3;
else
System.out.println( choice + " wasn't one of the options. Try again." );
}
if ( nextroom == 6 )
{
System.out.println( "You can either hop the fence and \"escape\", or go \"back\". " );
System.out.print( "> " );
choice = keyboard.next();
System.out.println();
if ( choice.equals("escape") )
nextroom = 0;
else if ( choice.equals("back") )
nextroom = 5;
else
System.out.println( choice + " wasn't one of the options. Try again." );
}
}
if ( nextroom == 0 )
{
System.out.println();
System.out.println( "You hop the fence and escape the abandoned building safely." );
System.out.println( "Congratulations!" );
}
if ( nextroom == 7 )
{
System.out.println();
System.out.println( "As you're climbing out of the window you slip and die." );
System.out.println( "Oops!" );
}
System.out.println();
}
}