For my class I have to create a interactive story/game.
I a having some trouble with the variables.
This is my first coding class I have ever taken so I am sorry if it looks messy.
I put alot of it into ifs and else ifs because that is all we have learned so far. My error is mostly coming from else if (Go.equalsIgnoreCase("Speak")) { I am getting the error "This variable my have not been initialized.
Please dumb your responses down if possible because I am still trying to learn it all. Thank you.
import java.util.Scanner;
public class Homework02 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String Go, Listen, Speak, Fight, A, B, C, D;
System.out.println(" WELCOME TO THE DUNGEON!");
System.out.println(" ");
System.out.println(" You are woken up by a large man kicking you in the stomach.\n"
+ "You let a large gasp of air out before proptly getting up in a blurry state.\n"
+ "What will you do?\n"
+ "(------------------------------------------)\n"
+ "1)Listen to the man (Listen)\n"
+ "2)Speak to the man (Speak)\n"
+ "3)Throw a punch at the man(Attack) ");
System.out.print("> ");
Go = keyboard.next();
if (Go.equalsIgnoreCase("Listen")) {
System.out.println("The large man tells you to get ready for your hearing in 2 minutes.\n"
+ "What will you do?\n"
+ "(---------------------------------------------------------------------)\n"
+ "1)Attack(1)\n"
+ "2)Sit Down(2) ");}
else if (Go.equalsIgnoreCase("Speak")) {
System.out.println("You open your mouth to start speaking to the large man.\n"
+ "As you make a sound he balls his fist up and sucker punches you in the stomach dropping you to the floor.\n"
+ "He states 'You speak when spoken to you filthy mutt.' Then tells you to get ready for your hearing\n"
+ "You spit out blood onto the floor and get on all fours. The large man kicks your head into the toilet and your vision gets fuzzy\n"
+ "You slowly start to fade into an unconcious state. As you start to see black the man says 'That's one less piece of trash we have to feed now.'");
System.out.println("////YOU HAVE DIED. RESTART THE GAME.////");
A = keyboard.next();
if (A.equalsIgnoreCase("1"));
System.out.println("The man turns his back to walk out of your cell.\n"
+ "As the man begeins to walk out you grab your blanket and rush him.\n"
+ "You wrap the blanket around his neck and start to strangle him.\n"
+ "The large man begins to turn purple and blue and you keep pulling tighter and tighter.\n"
+ "The man finally falls to his knees then onto his belly.\n"
+ "As the large man lies lifeless on the floor you grab his baton and keys and run out of the cell.\n"
+ "Do you run to the Left or to the Right?\n"
+ "(--------------------------------------------------------------------------)\n"
+ "1)Left\n"
+ "2)Right");}
else if (A.equalsIgnoreCase("2"));
System.out.println("You sit down to think about how you ended up there but you are drawing blanks.\n"
+ "You don't even know your name.\n"
+ "You sit on the floor of the cell waiting for the Large man to come back and retreive you.\n"
+ "*2 minutes pass by*\n"
+ "The large man appears again and tells you to follow him.\n"
+ "As you follow the large man down the hallway of the dungeon you see all the other starving prisoners rotting away in their cells.\n"
+ "You finally arrive to a large room filled with torches and skulls with a man sitting on a throne made of bones\n"
+ "'AHHHHH! My newest warrior!' The man exclaims! 'I cannot wait to see what you can do in the arena!'\n"
+ "'We have your first round tomorrow! Please eat and rest up for your fight! I cant wait to see you in action!'"
+ "What do you do?\n"
+ "(---------------------------------------------------------------------------------------------------------------------)"
+ "1)Go back to your cell to eat and rest(1)\n"
+ "2)Speak\n");
}
{
}
}