I need to write a code in java that goes through a multiple choice story, but I am having trouble getting my code to read the user input and have it continue the story. Hers the code I have written so far. (I think the line spacing in the code is correct if not I'm sorry it might have gotten messed up when I put my code here)
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Wlelcome to survive The desert. Made by Thomas Reinhardt");
// The first choice for the user
System.out.println("You find your self stranded in the desert. you need to find food and water quickly. Right now you have two opptions:");
System.out.println("(A): Travle to what looks like an oasis in the didstance:");
System.out.println("(B): keep exploring to find something else");
String choice = sc.nextLine();
// evaluating the useres first choice
// if the user passes the first choice
if (choice == "A")
{
System.out.println("You find water and are able to survive the night");
System.out.println("");
// making the second choice
System.out.println("Its now the next day. you find your self felling hungry you need food.");
System.out.println("(C) stay at the oasis and wait for a food sorce to come");
System.out.println("(D) Go out and serch for some food");
String choiceTwo = sc.nextLine();
// evaluating the second input
// if the user fails the second choice
if (choiceTwo == "C")
{
System.out.println("You wait at the oasis for days no food source arives you evetualuly starve to death");
}
//if the user passes the second choice
if (choiceTwo == "D")
{
System.out.println("You find a fresh kill and was able to salvage some meat. you now have food. ");
// setting up the third choice
System.out.println("Now that you are back at the oasis you need to find a way to get saved");
System.out.println("(E) you can stay at the oasis and create a SOS signal at it: ");
System.out.println("(F) Trava; twords what looks like a small town in the distance");
String choiceThree = sc.nextLine();
//evaluates the third choice
// if the user passes the third choice
if (choiceThree == "E" )
{
System.out.println("You built the SOS signal and help has finaly arived and you were saved");
}
// if the user fails the third choice
if (choiceThree == "F")
{
System.out.println("You walk twords what you thought was a town but it just keeps getting farther away. The town was a halusination you end up wandering forever and evetualy die");
}
}
}
// the user fails the first choice
if (choice == "B")
{
System.out.println("You wander for hours and find nothing you die of sarvation");
}
}
}
Aucun commentaire:
Enregistrer un commentaire