Hello, I hope to be a member here a while, and as my first official post, I would like to issue my novice bug. I know, you will find it extremely easy. I am trying to make a text-adventure as my first step to game programming, and I ended with a bug with user input that doesn't continue the user-input.
Here is the code:
Game.java
package main; import java.util.Scanner; public class Game extends Variables { public Game() { } public static void main(String[] args) { Main.start(); } }
Variables.java
package main; import java.util.Scanner; public class Variables { static Scanner i = new Scanner(System.in); public static String direction = ""; public static void sleep() { try { Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); } } public static void space() { System.out.println(""); } }
Main.java
package main; public class Main extends Variables { public static void start() { System.out.println("You wake up lost, washed ashore on a beach. All you see in sight is a twig, a rock, and lots of sand."); System.out.println("COMMANDS: go \n" + "OPTIONS: North, South, East, West"); direction = i.nextLine(); if(direction.equals("North")) { north(); } else if(direction.equals("north")) { north(); } else if(direction.equals("South")) { south(); } else if(direction.equals("south")) { south(); } else if(direction.equals("East")) { east(); } else if(direction.equals("east")) { east(); } else if(direction.equals("West")) { west(); } else if(direction.equals("west")) { west(); } } public static void north() { System.out.println("You have traveled north into a forest, where you see a turtle resting on a rock, nothing special in this direction."); sleep(); System.out.println("Please choose an action:"); direction = i.nextLine(); } public static void south() { System.out.println("I wouldn't go that way, there is an aweful lot of water there."); sleep(); System.out.println("Please choose an action:"); direction = i.nextLine(); } public static void east() { System.out.println("Oh, a snake, it's staring and hissing at you. I would get some defense before I go there."); sleep(); System.out.println("Please choose an action:"); direction = i.nextLine(); } public static void west() { System.out.println("I see rope and some fish stuck in shore, flopping"); sleep(); System.out.println("Please choose an action:"); direction = i.nextLine(); } }