Assignment #77
Code
///Name: Cody Swain
///Period: 6
///Project Name: Adventure2
///File Name: Adventure2.java
///Date: 1/11/16
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 facing a door. Do you [enter] or walk out to 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 inside a house. Do you want to go [up] the staircase to your right, or head [down] the hallway in front of you? You may also go [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 stand in the street and see a penny on the ground. Do you [grab] the penny, or head [back] to the door? " );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("grab") )
nextroom = 6;
else if ( choice.equals("back") )
nextroom = 1;
else
System.out.println( "ERROR." );
}
if ( nextroom == 4 )
{
System.out.println( "You are in a large room with two doors. You can go through the [right] one or the [left] one. You may also go [back]. " );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("right") )
nextroom = 7;
else if ( choice.equals("left") )
nextroom = 8;
else if ( choice.equals("back") )
nextroom = 2;
else
System.out.println( "ERROR." );
}
if ( nextroom == 5 )
{
System.out.println( "You enter small room. There is a ladder that goes [up], and a giant hole that you can go [down]. You may also go [back]. " );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("up") )
nextroom = 9;
else if ( choice.equals("down") )
nextroom = 10;
else if ( choice.equals("back") )
nextroom = 2;
else
System.out.println( "ERROR." );
}
if ( nextroom == 6 )
{
System.out.println( "You bend down to pick up the penny, and get rammed by a large truck... You die instantly. " );
nextroom = 0;
}
if ( nextroom == 7 )
{
System.out.println( "You enter the room and walk in on a man changing. He yells in rage, picks up a lamp, and throws it at you. You head cracks open and you die instantly. " );
nextroom = 0;
}
if ( nextroom == 8 )
{
System.out.println( "You are in a room with a ladder that goes [down]. You may also go [back]. " );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("down") )
nextroom = 5;
else if ( choice.equals("back") )
nextroom = 4;
else
System.out.println( "ERROR." );
}
if ( nextroom == 9 )
{
System.out.println( "You are in a room with a single [door]. You may also go [back]. " );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("door") )
nextroom = 4;
else if ( choice.equals("back") )
nextroom = 5;
else
System.out.println( "ERROR." );
}
if ( nextroom == 10 )
{
System.out.println( "You fall down a pit into a large room with a lot of fire ants. They are extremely hungry and decided to eat you slowly. With no escape, you succumb to a slow death as a human picnic." );
nextroom = 0;
}
}
System.out.println( "\nEND." );
}
}
Picture of the output