Assignemnt #77 and Short Adventure 2: With a Loop
Code
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 front of a candy store. Do you [enter]? Or do you walk across the [street]?");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("enter") )
nextroom = 2;
else if ( choice.equals("street") )
nextroom = 3;
else
System.out.println( "ERROR." );
}
if ( nextroom == 2 )
{
System.out.println( "You are in a very very colorful candy store. Do you want to go [up], [down], or [back]?");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("back") )
nextroom = 1;
else if ( choice.equals("up") )
nextroom = 4;
else if ( choice.equals("down") )
nextroom = 5;
else
System.out.println( "ERROR." );
}
if ( nextroom == 3 )
{
System.out.println( "You see a purse in the middle of the street. Do you [grab] the purse or walk [past] it?");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("grab") )
nextroom = 6;
else if ( choice.equals("past" ) )
nextroom = 1;
else
System.out.println( "ERROR." );
}
if ( nextroom == 4 )
{
System.out.println( "You are upstairs, where all the chocolate sweets are. Do you want a [snickers], [toblerone], or go [back] downstairs?");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("snickers" ) )
nextroom = 7;
else if ( choice.equals("toblerone" ) )
nextroom = 8;
else if ( choice.equals("back") )
nextroom = 2;
else
System.out.println( "ERROR." );
}
if ( nextroom == 5 )
{
System.out.println( "You are now on the bottom floor, where the sour candies are. Do you want to get [warheads], [toxic_waste], or go [back] upstairs.");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("warheads" ) )
nextroom = 9;
else if ( choice.equals("toxic_waste" ) )
nextroom = 10;
else if ( choice.equals("back") )
nextroom = 2;
else
System.out.println( "ERROR." );
}
if ( nextroom == 6 )
{
System.out.println( "You pick up the purse and find a huge diamond. But you quickly get arrested and thrown in prison for 30 years.");
nextroom = 0;
}
if ( nextroom == 7 )
{
System.out.println( "You buy the snickers bar. And eat it. Afterwards, you transform into leonardo dicaprio.");
nextroom = 0;
}
if ( nextroom == 8 )
{
System.out.println( "After you buy and eat the toblerone. You find yourself craving something else. Do you go to the [bottom] floor or [upstairs]?");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("bottom") )
nextroom = 5;
else if ( choice.equals("upstairs") )
nextroom = 4;
else
System.out.println( "ERROR." );
}
if ( nextroom == 9 )
{
System.out.println( "You buy and eat the warheads.But now you want something else. Do you go [upstairs] or to the [bottom] floor?");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("upstairs") )
nextroom = 4;
else if ( choice.equals("bottom") )
nextroom = 5;
else
System.out.println( "ERROR." );
}
if ( nextroom == 10 )
{
System.out.println( "You buy and eat the toxic waste. But your toxic waste was mixed up with actual toxic waste. You eat it and then suddenly implode.");
nextroom = 0;
}
}
}
}
Picture of the output