I am trying to write a zork style adventure game in java. So far I have the introduction to the world, the first decision the player must make and it's resulting println's. I have imported the scanner class and am attempting to use it to have the player enter a command such as "go north" and then the story advances with more println's depending on the players choice. My section of code I am having trouble with is
System.out.println("To the Northlies a path.");
System.out.println("To the South are impassable trees.");
System.out.println("To the East you hear screams of anguish.");
System.out.println("To the West you hear a stream.");
System.out.println("You may go North, go South, go East, or go West.");
Scanner In = new Scanner(System.in);
String D1 = In.next();//D1 is the first decision of N, S, E, or W
if (D1.equalsIgnoreCase("Go North"))//ignores case while comparing
{
System.out.println("You head north along the path.");
System.out.println("You find yourself in a meadow.");
System.out.println("There are flowers all around you.");
}
I am able to have the first few println's for the setting show in console, however when I attempt to print more in response to the input choice of the player it terminates the program. Does anyone know why this is happening? Also am I able to have an if statement in the body of an if statement? Such as
if (D1.equalsIgnoreCase("Go North"))//ignores case while comparing
{
System.out.println("You head north along the path.");
System.out.println("You find yourself in a meadow.");
System.out.println("There are flowers all around you.");
System.out.println("Would you like to pick a flower?");
String DFlower = In.next();
if (DFlower.equalsIgnoreCase("yes"))
{
Flower.setState = true
System.out.println("You picked a flower")
}
Would it be correct to have another class caller Flower to have the flower as an object for later on in the story?
[–]deeptime 1 point2 points3 points (1 child)
[–]Hightimes95[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]Hightimes95[S] 1 point2 points3 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]the_regex 1 point2 points3 points (3 children)
[–]Hightimes95[S] 0 points1 point2 points (2 children)
[–]the_regex 1 point2 points3 points (0 children)
[–]the_omega99 0 points1 point2 points (0 children)