Assignment #77

Code

/// Name: Jonathan Stine
/// Period: 5
/// Program Name: Adventure 2
/// File Name: Adventure2.java

    
    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( "Welcome to the second installment of JONATHAN's ADVENTURE!" );
    
    		while ( nextroom != 0 ) {
                
    			if ( nextroom == 1 ) {
                    
    				System.out.println( "You are inside a broomcloset.. Try to escape the house! Would you like to use the trap door and go into the \"basement\" or the normal door and go into the \"livingroom\"?" );
    				System.out.print( "> " );
    				choice = keyboard.nextLine();
    				if ( choice.equals("basement") ) {
    					nextroom = 2;
                    }
    				else if ( choice.equals("livingroom") ) {
    					nextroom = 3;
                    }
    				else {
    					System.out.println( "ERROR." );
                    }
    			}
                
    			else if ( nextroom == 2 ) {
                    
    				System.out.println( "In the basement you find a tunnel that seems to lead far away. Do you take the \"tunnel\" or go \"back\" to the broomcloset?" );
    				System.out.print( "> " );
    				choice = keyboard.nextLine();
    				if ( choice.equals("back") ) {
    					nextroom = 1;
                    }
                    else if ( choice.equals("tunnel") ) {
                        nextroom = 0;
                    }
    				else {
    					System.out.println( "ERROR." );
                    }
    			}
                
                else if ( nextroom == 3 ) {
                    
                    System.out.println( "The livingroom is filled with corpses. Do you go \"back\" into the closet or take your chances and try the \"frontdoor\"?" );
                    System.out.print( "> " );
                    choice = keyboard.nextLine();
                    if ( choice.equals("back") ) {
                        nextroom = 1;
                    }
                    else if ( choice.equals("frontdoor") ) {
                        nextroom = 0;
                    }
                }
                
    		}
    
    		System.out.println( "\nYou have fled. Only time will tell if you make it out alive..." );
    	}
    	
    }
 
    

Code Output