Assignment #77 Adventure 2

Code

    /// Name: John Huh
    /// Period: 6
    /// Program Name: Adventure 2
    /// File Name: Adventure2.java
    /// Date Finished: 2/2/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 = "";
    
            System.out.println();
            
    		while ( nextroom != 0 )
    		{
    			if ( nextroom == 1 )
    			{
    				System.out.println( "You are in a creepy house!  Would you like to \"upstairs\" or into the \"kitchen\"?" );
    				System.out.print( "> " );
    				choice = keyboard.nextLine();
    				if ( choice.equals("upstairs") )
    					nextroom = 3;
    				else if ( choice.equals("kitchen") )
    					nextroom = 2;
    				else
                    {
    					System.out.println( choice + " wasn't one of the options. Try again." );
                    }
                    System.out.println();
    			}
    			if ( nextroom == 2 )
    			{
    				System.out.println( "There is a long countertop with dirty dishes everywhere.  Off to one side there is, as you'd expect, a refrigerator.  You may open the \"refrigerator\" or go \"back\"." );
    				System.out.print( "> " );
    				choice = keyboard.nextLine();
    				if ( choice.equals("back") )
    					nextroom = 1;
    				else if ( choice.equals("refrigerator") )
                        nextroom = 4;
    				else
                    {
                        System.out.println( choice + " wasn't one of the options. Try again." );
                    }
                    System.out.println();
                }
                if ( nextroom == 3 )
    			{
    				System.out.println( "Upstairs you see a hallway.  At the end of the hallway is the master \"bedroom\".  There is also a \"bathroom\" off the hallway.  Or, you can go back \"downstairs\". Where would you like to go?" );
    				System.out.print( "> " );
    				choice = keyboard.nextLine();
    				if ( choice.equals("bathroom") )
    					nextroom = 5;
                    else if ( choice.equals("bedroom") )
    					nextroom = 5;
    				else if ( choice.equals("downstairs") )
                        nextroom = 1;
    				else
                    {
                        System.out.println( choice + " wasn't one of the options. Try again." );
                    }
                    System.out.println();
    			}
                if ( nextroom == 4 )
    			{
    				System.out.println( "Inside the refrigerator is a large hole; large enough for you to walk through.  Do you enter ( \"yes\" or \"no\" )" );
    				System.out.print( "> " );
    				choice = keyboard.nextLine();
    				if ( choice.equals("yes") )
    					nextroom = 6;
    				else if ( choice.equals("no") )
                        nextroom = 1;
    				else
                    {
                        System.out.println( choice + " wasn't one of the options. Try again." );
                    }
                        System.out.println();
    			}
                if ( nextroom == 5 )
    			{
    				System.out.println( "As you approach the room, something in the shadows grabs you and everything goes dark." );
    				System.out.println( "You have died" );
    				nextroom = 0;
    			}
                if ( nextroom == 6 )
    			{
    				System.out.println( "As you enter the hole, it begins pitch black. However, as you progress through you see a light. This light eventually leads to an exit." );
    				System.out.println( "You have survived" );
    				nextroom = 0;
    			}
            }
            System.out.println("\nEND.");
            System.out.println();
        }
    }
    

Picture of the output

Assignment 1