Assignemnt #77, Adventure 2

Code

      /// Name: Alex Pinder
      /// Period: 5
      /// Program Name: Adventure 2
      /// File Name: Adventure2.java
      /// Date Complete: 2/1/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 = "";
              int counter = 0;
              
              System.out.println( "Welcome to Alex's Adventure! \nRemember you may go back to a previous room at any time!" );
      
      		while ( nextroom != 0 )
      		{
                  if ( nextroom == 1 )
      			{
      				System.out.println( "\nYou find yourself in a small room. There looks to be a \"door\" in front of you and a \"window\" behind you. Where will you go?" );
      				System.out.print( "> " );
      				choice = keyboard.nextLine();
      				if ( choice.equals("door") )
      					nextroom = 2;
      				else if ( choice.equals("window") )
      					nextroom = 3;
      				else
      					System.out.println( "ERROR." );
      			}
                  else if ( nextroom == 2 )
                  {
                  System.out.println( "\nYou are in a kitchen. There is a \"fridge\" next to a small \"hole\" in the wall. Will what do you do? " );
                      System.out.print( "> " );
                      choice = keyboard.nextLine();
                      if ( choice.equals("fridge") )
      				    nextroom = 4;
                      else if ( choice.equals("hole") )
                          nextroom = 5;
                      else if ( choice.equals("back") )
                          nextroom = 1;
                      else
      				    System.out.println( "ERROR." );
                      }
                  else if ( nextroom == 3 )
                  {
                      System.out.println( "\n You are outside and it is very dark. You look around and see a \"cooler\" next to you and a \"light\" off in the distance. What will you do? " );
                      System.out.print( "> " );
                          choice = keyboard.nextLine();
                      if ( choice.equals("cooler") )
                          nextroom = 6;
                      else if ( choice.equals("light") )
                      {
                          System.out.println( "\nYou walk towards the light to find that it is a massive truck heading right at you! You end up being run over and you eventually die of blood loss." );
                          nextroom = 0;
                      }
                      else if ( choice.equals("back") )
                          nextroom = 1;
                      else 
                          System.out.println( "ERROR" );
                  }
                  else if ( nextroom == 4 )
                  {
                      System.out.println( "\nYou open the fridge door to see a bottle of what looks like \"ketchup\" and a bottle of what looks like \"mustard\". What will you do?" );
                      choice = keyboard.nextLine();
                  
                      if ( choice.equals("ketchup") )
                      {
                          System.out.println( "\nYou open the bottle but it releases a toxic gas that kills you instantly." );
                          nextroom = 0;
                      }
                      else if ( choice.equals("mustard") )
                      {
                          System.out.println( "\nYou open the bottle and drink the yellow liquid. You are killed instantly." );
                          nextroom = 0;
                      }
                      else if ( choice.equals("back") )
                          nextroom = 2;
                      else
                          System.out.println( "ERROR" );
                  }
                  else if ( nextroom == 5 )
                  {
                      System.out.println( "\nYou crawl through the small hole in the wall and see that it diverges at two paths. Do you go \"left\" or \"right\"?" );
                      choice = keyboard.nextLine();
                      if ( choice.equals("left") )
                      {
                          System.out.println( "\nYou crawl to the left and fall into a hole. You starve to death." );
                          nextroom = 0;
                      }
                      else if ( choice.equals("right") )
                      {
                          System.out.println( "\nYou crawl into the right room and are instantly vaporized by a super mega death lazer." );
                          nextroom = 0;
                      }
                      else if ( choice.equals("back") )
                          nextroom = 2;
                      else
                          System.out.println( "ERROR" );
                  }
                  else if ( nextroom == 6 )
                  {
                      System.out.println( "\nYou open the cooler to find two containers. Do you open the \"red\" container or \"blue\" container?" );
                      choice = keyboard.nextLine();
                  
                      if ( choice.equals("red") )
                      {
                          System.out.println( "\nYou open the red container and you instantly explode due to the bomb from within it." );
                          nextroom = 0;
                      }
                      else if ( choice.equals("blue") )
                      {
                          if ( counter == 0 )
                          {
                              System.out.println( "\nYou get warped back to the beginning due to a worm hole." );
                              counter++;
                              nextroom = 1;
                          }
                          else if ( counter == 1 )
                          {
                              System.out.println( "\nCongradulations! You Won!" );
                              nextroom = 0;
                          }
                      }
                      else if ( choice.equals("back") )
                          nextroom = 3;
                      else
                          System.out.println( "ERROR" );
                  }
              }
              
      		System.out.println( "\nEND." );
      
          }
      }
    

Picture of the output

Assignment 77