Assignemnt #77 Short Adventure 2: With a Loop
Code
/// Name: Jake Johnson
/// Period: 7
/// Program Name: Adventure2
/// File Name: Adventure2.java
/// Date Finished: 2/3/2016
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( "You wake up in a strange place, and its snowing. You see an old house in the distance. Do you go into the house?" );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("yes") )
nextroom = 2;
else if ( choice.equals("no") )
{
System.out.println("You freeze in the snow storm. The end");
nextroom = 0;
}
else
System.out.println( "ERROR." );
}
if ( nextroom == 2 )
{
System.out.println( "You walk in the front door, and you see a dark hallway in front of you, and a closed door with light coming out from under it. Do you \"forward\" into the hallway \"back\" or open the \"door\"?");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("back") )
nextroom = 1;
else if (choice.equals("forward"))
{
System.out.println( "you go down the dark hallway, and you never see the light again." );
nextroom = 0;
}
else if (choice.equals("door"))
{
System.out.println("You open the door but its just an empty room. Do you go \"back\" or \"stay\" in the room?");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("back") )
{
nextroom = 2;
}
else if (choice.equals("stay"))
{
System.out.println("You stay in the room for the rest of eternity");
nextroom = 0;
}
}
}
if ( nextroom == 3 )
{
System.out.println( "" );
}
}
System.out.println( "\nEND." );
}
}
Picture of the output