Assignment #77 and Short Adventure 2
Code
///Name: Tim Gibson
///Period: 6
///Project Name: Short Adventure 2
///File Name: Collatz.java
///Date Finished: 10/29/15
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 are in a dark and creepy House. You can either go into the \"backyard\" or the \"basement\"." );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("backyard") )
nextroom = 2;
else if ( choice.equals("basement") )
nextroom = 3;
else
System.out.println( "ERROR. Try Again" );
}
if ( nextroom == 2 )
{
System.out.println( "In the backyard, there is a \"shed\". You could also turn around and go back \"inside\"." );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("shed") )
nextroom = 4;
else if ( choice.equals("inside") )
nextroom = 1;
else
System.out.println( "ERROR. Try Again" );
}
if ( nextroom == 3 )
{
System.out.println( "In the basement, there is a \"tv\", which you could turn on, and a \"closet\". You can also go \"back\" upstairs if you'd like. What would you like to do?" );
choice = keyboard.nextLine();
if ( choice.equals("back") )
nextroom = 1;
else if ( choice.equals("tv") )
nextroom = 5;
else if ( choice.equals("closet") )
nextroom = 6;
else
System.out.print( "ERROR. Try Again" );
}
if ( nextroom == 4 )
{
System.out.println( "The shed is empty. You can only go back \"inside\". Where would you like to go?" );
choice = keyboard.nextLine();
if ( choice.equals("inside") )
nextroom = 1;
else
System.out.println( "ERROR. Try Again." );
}
if ( nextroom == 5 )
{
System.out.println( "You turn on the TV. You watch Monday Night Football, and after seeing how bad the 49ers management is, you punch the TV, and break your hand." );
nextroom = 0;
}
if ( nextroom == 6 )
{
System.out.println( "You enter the closet. In the closet, there is a giant pile of bars of gold. You become a millionare." );
nextroom = 0;
}
}
System.out.println( "\nEND." );
}
}
Picture of the output