Assignment 77

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 a house. You can go \"upstairs\" or go \"downstairs\"." );
    				System.out.print( "> " );
    				choice = keyboard.nextLine();
    				if ( choice.equals("upstairs") )
    					nextroom = 2;
    				else if ( choice.equals("downstairs") )
    					nextroom = 3;
    				else
    					System.out.println( choice + " wasn't one of the options. Try again." );
    			}
    			if ( nextroom == 2 )
    			{
    				System.out.println( "You reach a bathroom. There's nothing to do here except go \"back\"." );
    				System.out.print( "> " );
    				choice = keyboard.nextLine();
    				if ( choice.equals("back") )
    					nextroom = 1;
    				else
    					System.out.println( choice + " wasn't one of the options. Try again." );
    			}
    			if ( nextroom == 3 )
    			{
    				System.out.println( "You find yourself in a basement. There is another \"door\" at the other end. There is a \"vault\" near the door." );
    				choice = keyboard.nextLine();
    				System.out.print( "> " );
    				if ( choice.equals("door") )
    					nextroom = 1;
    				else if ( choice.equals("vault") )
    					nextroom = 4;
    				else
    					System.out.println( choice + " wasn't one of the options. Try again." );
    			}
    			if ( nextroom == 4 )
    			{
    				System.out.println( "The vault opens up when you get near it, releasing snakes, you can \"fight\" or \"run\"." );
    				choice = keyboard.nextLine();
    				System.out.print( "> " );
    				if ( choice.equals("fight") )
    					nextroom = 5;
    				else if ( choice.equals("run") )
    					nextroom = 6;
    				else
    					System.out.println( choice + " wasn't one of the options. Try again." );
    			}
                if ( nextroom == 5 )
    			{
    				System.out.println( "You kill the snakes and flee the house" );
    				nextroom = 0;
    			}
                if ( nextroom == 6 )
    			{
    				System.out.println( "You try and run away but the snakes catch up to you and eat you" );
    				nextroom = 0;
    			}
    				
    		}
    
    		System.out.println( "\nThe game is over!" );
    	}
    	
    }
    

Picture of the output

Assignment