Assignemnt #77
Code
/// Name: Ryan Volko
/// Period: 7
/// Program Name: Loop
/// File Name: Loop.java
/// Date Finished: 2/16/2015
import java.util.Scanner;
public class Loop
{
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( "You are in a big room. There is a door to a \"room\" and a open doorway to the \"hall\"." );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("room") )
nextroom = 2;
else if ( choice.equals("hall") )
nextroom = 3;
else
System.out.println( choice + " wasn't one of the options. Try again." );
}
if ( nextroom == 2 )
{
System.out.println( "You're in a empty room with no door. There's nothing to do here except go \"back\"." );
System.out.print( "> " );
choice = keyboard.nextLine();
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( "You are in the hallway and almost fall through the hole.\n do you go \"in\" or do you continue \"down\" the hall" );
choice = keyboard.nextLine();
System.out.print( "> " );
if ( choice.equals("in") )
nextroom = 1;
else if ( choice.equals("down") )
nextroom = 4;
else
System.out.println( choice + " wasn't one of the options. Try again." );
}
if ( nextroom == 4 )
{
System.out.println( "You go to the end of the hall and see a door on each side and a hole.\n Do you go \"left\" , \"right\" , or \"jump\" into the hole" );
choice = keyboard.nextLine();
System.out.print( "> " );
if ( choice.equals("left") )
nextroom = 1;
else if ( choice.equals("right") )
nextroom = 5;
else if ( choice.equals("jump") )
nextroom = 8;
else
System.out.println( choice + " wasn't one of the options. Try again." );
}
if ( nextroom == 5 )
{
System.out.println( "You enter a room with a mirror and a ladder. Do you go up the \"ladder\" or do you go to the \"mirror\" " );
choice = keyboard.nextLine();
System.out.print( "> " );
if ( choice.equals("ladder") )
nextroom = 1;
else if ( choice.equals("mirror") )
nextroom = 6;
else
System.out.println( choice + " wasn't one of the options. Try again." );
}
if ( nextroom == 6 )
{
System.out.println( "You walk up to the mirror and it moves like liquid. Do you \"touch\" the mirror or do you run \"away\" " );
choice = keyboard.nextLine();
System.out.print( "> " );
if ( choice.equals("away") )
nextroom = 2;
else if ( choice.equals("touch") )
nextroom = 7;
else
System.out.println( choice + " wasn't one of the options. Try again." );
}
if ( nextroom == 7 )
{
System.out.println( "A clown jumps from the mirror and starts chasing you through the house, then you wake up." );
System.out.println("");
nextroom = 0;
}
if ( nextroom == 8 )
{
System.out.println( "You jump into the hole and get impaled by spikes.\n You are found in your bed with a hole in your chest but nothing sticking out" );
System.out.println("");
nextroom = 0;
}
}
System.out.println( "\nSometimes Your dreams are real" );
}
}
Picture of the output