Assignment 77: While Loop Adventure
Code
/// Name: Ryan McAteer
/// Period: 5
/// Program Name: Adventure 2
/// File Name: Assignment77.java
/// Date Finished: 2/23/16
import java.util.Scanner;
public class Assignment77
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String answer1, answer2, answer3;
int c;
System.out.println("Ryan's Adventure Mk. II!");
System.out.println();
c = 1;
do
{
System.out.println("You are at the gate of Castle Wolfenstein. Do you take the [tram] or [enter] the gate?");
System.out.print("> ");
answer1 = keyboard.next();
if ( answer1.equals("tram"))
{
System.out.println("You enter the tram after dodging some Nazi scum. Do you [take] the tram, pick up a [gun], or go [back]?");
System.out.print("> ");
answer2 = keyboard.next();
if ( answer2.equals("take"))
{
System.out.println("You take the tram, only to be ambushed by a sentry bot! It shoots the tram. BOOM!! Do you [jump] to end your mission or do you [walk] on the cables back?");
System.out.print("> ");
answer3 = keyboard.next();
if ( answer3.equals("jump"))
{
System.out.println("You plummet to you death. GAME OVER!");
c = 0;
}
else if ( answer3.equals("walk"))
{
c = 1;
}
else
{
c = 1;
}
}
else if ( answer2.equals("gun"))
{
System.out.println("You pick up the mp-50 and get found by a patrol. Would you like to [run] or to [fire]?");
System.out.print("> ");
answer3 = keyboard.next();
if ( answer3.equals("run"))
{
System.out.println("You run away only to be shot in the back. GAME OVER!");
c = 0;
}
else if ( answer3.equals("fire"))
{
System.out.println("You fire your weapon, kill the patrol, and have time to think of a plan.");
c = 1;
}
else
{
c = 1;
}
}
}
else if ( answer1.equals("enter"))
{
System.out.println("You enter Castle Wolfenstein. Looks creepy. Do you [continue] further or go [back]?");
System.out.print("> ");
answer2 = keyboard.next();
if (answer2.equals("continue"))
{
System.out.println("You continue into Castle Wolfenstein and get attacked by a Panzerhund. GAME OVER!");
}
else if (answer2.equals("back"))
{
c = 1;
}
else
{
c = 1;
}
}
} while ( c != 1);
}
}
Picture of the output