/* * ZorkJ - By Alan G. Labouseur */ import java.util.Scanner; public class ZorkJcentralControl { // Globals private static Scanner input = new Scanner(System.in); private static String command = new String(""); private static final String PROMPT = "-]"; private static int currentLocale = 1; private static boolean stillPlaying = true; public static void main(String [] args) { intro(); blankLine(); gameLoop(); } private static void gameLoop() { while (stillPlaying) { if (currentLocale == 1) { localeBackyard(); } else if (currentLocale == 2) { localeHouse(); } else if (currentLocale == 3) { localeShrubs(); } else { System.out.println("Error. Invalid locale:" + currentLocale + " This should never happen."); } } } private static void intro() { System.out.println("Welcome to ZorkJ."); System.out.println(" Written by Alan G. Labouseur"); System.out.println(" (c) 2009 - No Rights Reserved. Some rights obscured."); System.out.println(" Play at your own risk."); } private static void blankLine() { System.out.println(); } private static void localeBackyard() { // Display description. System.out.println("--Back yard--"); System.out.println("It's a lazy summer morning as you sit under a tree"); System.out.println("next to your \"owners\", Phineas and Ferb, wondering"); System.out.println("what they're going to do that day."); // Interact getCommand(); if (command.equalsIgnoreCase("e")) { currentLocale = 2; } else { if (command.equalsIgnoreCase("s")) { currentLocale = 3; } else { System.out.println("You can't go that way."); // Leave currentLocale unchanged. } } } private static void localeHouse() { // Display description. System.out.println("--House--"); System.out.println("(house)"); // Interact getCommand(); if (command.equalsIgnoreCase("s")) { currentLocale = 3; } else { System.out.println("You can't go that way."); // Leave currentLocale unchanged. } } private static void localeShrubs() { // Display description. System.out.println("--Shrubs--"); System.out.println("(shrubs)"); // Interact getCommand(); if (command.equalsIgnoreCase("e")) { currentLocale = 2; } else { System.out.println("You can't go that way."); // Leave currentLocale unchanged. } } private static void getCommand() { // Prompt the user for a command. System.out.print(PROMPT); command = input.nextLine(); // Check to see if they want to quit ... if (command.equalsIgnoreCase("q")) { // ... which they do, so let's quit. System.exit(0); // TODO: implement (stillPlaying = false;) } } }