/*Drew Schuster dtschust ECE462 */ package com.github.dtschust.zork; import com.github.dtschust.zork.parser.ParserIOC; import com.github.dtschust.zork.repl.ActionDispatcher; import java.io.PrintStream; import java.util.Scanner; /* And away we go*/ public class Zork { final ZorkGame game; final Scanner input = new Scanner(System.in); final PrintStream output = System.out; public Zork(final String filename) { game = ParserIOC.xmlParser().parse(filename); ActionDispatcher d = new ActionDispatcher(game, output); /* starting the game!*/ d.dispatch("Start at Entrance"); /* There is no stopping in Zork, until we're done!!*/ while (game.isRunning()) { String userInput = input.nextLine(); /*Now that we have the user command, check the input*/ if (!game.evaluateTriggers(userInput)) { /* If we haven't skipped, perform the user action*/ d.dispatch(userInput); // check the triggers again (various states have changed, gnomes need to be found!) game.evaluateTriggers(""); } } // single point of termination System.exit(0); } /* I love how basic java main functions are sometimes.*/ public static void main(String[] args) { if (args.length != 1) { System.out.println("Usage: java Zork [filename]"); return; } new Zork(args[0]); } }