Assignment # 77 and Short Adventure
Code
/// Name: Tommy Oyuntseren
/// Period: 7
/// Program Name: Adv2
/// File Name: Adv2.java
/// Date: 1/27/2016
import java.util.Scanner;
public class Adv2
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int nextroom = 1;
String choice = "";
System.out.println("Welcome to an adventure!");
while ( nextroom != 0 )
{
if ( nextroom == 1 )
{
System.out.println( "You enter a vacant haunted house in the middle of the night. The door closes and locks behind you.");
System.out.println( "You enter a vacant haunted house in the middle of the night. The door closes and locks behind you.");
System.out.println("Do you go to the \"living room\" or go \"upstairs\"?" );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("living room") )
nextroom = 2;
else if ( choice.equals("upstairs") )
nextroom = 3;
else
System.out.println("Error. "+ choice +" was not an option." );
}
if ( nextroom == 2 )
{
System.out.println( "As you're walking into the living room you notice a journal on the coffee table.");
System.out.println("Do you read the \"journal\", or go \"back\"." );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("journal") )
nextroom = 4;
else if
( choice.equals("back") )
nextroom = 1;
else
System.out.println("Error. "+ choice +" was not an option." );
}
if ( nextroom == 4 )
{
System.out.println("You read a journal entry dated from yesterday. You know the house has been vacant for months.");
System.out.println("Do you wander into the \"kitchen\" or go \"back\" to the entry way?" );
choice = keyboard.nextLine();
System.out.print( "> " );
if ( choice.equals("back") )
nextroom = 1;
else if ( choice.equals("kitchen") )
nextroom = 5;
else
System.out.println("Error. "+ choice +" was not an option." );
}
if ( nextroom == 5 ) //Ending 1
{
System.out.println( "You find fresh soup on the stove. You go to smell it as a knock comes from the front door..." );
nextroom = 0;
}
if ( nextroom == 3 ) //upstairs
{
System.out.println( "You hear a door creak down the hall way. Do you go \"towards\" the sound or \"back\" downstairs?" );
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("towards") )
nextroom = 6;
else if
( choice.equals("back") )
nextroom = 1;
else
System.out.println("Error. "+ choice +" was not an option." );
}
if ( nextroom == 6 )
{
System.out.println( "You reach the last door but it's locked.");
System.out.println("Do you \"break\" the door handle, go into \"another room\", or \"back\" downstairs?");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("break") )
nextroom = 7;
else if
( choice.equals("another room") )
nextroom = 8;
else if
( choice.equals("back") )
nextroom = 1;
else
System.out.println("Error. "+ choice +" was not an option." );
}
if ( nextroom == 8 )
{
System.out.println( "There's nothing useful in this room. Go break into the \"other room\".");
System.out.print( "> " );
choice = keyboard.nextLine();
if ( choice.equals("other room") )
nextroom = 8;
else
System.out.println("Error. "+ choice +" was not an option." );
}
if ( nextroom == 7 ) //Ending 2
{
System.out.println( "You go in and find nothing. The window was open. You found a way out.");
nextroom=0;
}
}
System.out.println( "\nThanks for playing!");
}
}
Picture of the output