Assignemnt #77 and Short Adventure 2: With a Loop
Code
///Name: Brian Phillips
///Period:5
///Project Name: Short Adventure 2: With a Loop
///File Name: AdventureOwn.java
///12/10/15
import java.util.Scanner;
public class AdventureOwn
{
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 running down a dark alley you see a \"door\" and a \"cemetery\" which do you choose.");
System.out.println("");
System.out.print("> ");
choice = keyboard.nextLine();
if (choice.equals("door"))
nextroom = 2;
else if (choice.equals("cemetery"))
nextroom = 3;
else
System.out.println("Sorry that is not one of the options");
}
if (nextroom == 2)
{
System.out.println("You walk through the door and you see lots of valuables");
System.out.println("Do you \"rob\" the house or do you go \"back\" .");
System.out.print("> ");
choice = keyboard.nextLine();
if (choice.equals("rob"))
nextroom = 4;
else if (choice.equals("back"))
nextroom = 1;
else
System.out.println("Sorry that is not one of the options");
}
if (nextroom == 3)
{
System.out.println("You spot some graves and one of them is the grave of smitty werbenjagermanjensen");
System.out.println("Do you \"dig\" up the grave or go \"back\" .");
System.out.print("> ");
choice = keyboard.nextLine();
if (choice.equals("back"))
nextroom = 1;
else if (choice.equals("dig"))
nextroom=5;
else
System.out.println("Sorry that is not one of the options");
}
if (nextroom == 4)
{
System.out.println("You find a computer with reddit open but there are police sirens comming.");
System.out.println("Do you browse \"reddit\" or go \"back\".");
System.out.print("> ");
choice = keyboard.nextLine();
if (choice.equals("reddit"))
{
System.out.println("The cops show you a spicy meme and then leave.");
nextroom = 0;
}
else if (choice.equals("back"))
nextroom=1;
else
System.out.println("Sorry that is not an option.");
}
if (nextroom==5)
{
System.out.println("In the grave you spot a skeleton with a hat on its head.");
System.out.println("Do you \"take\" the hat or go \"back\" .");
choice = keyboard.nextLine();
}
if (choice.equals("take"))
{
System.out.println("Spongebob comes out and says it was his hat Mr Krabs, He was number 1!");
nextroom = 0;
}
else if (choice.equals("back"))
nextroom=1;
}
System.out.println("\nCongrats.");
}
}
Picture of the output