This repository has been archived on 2022-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
sdm03/src/main/java/com/github/dtschust/zork/Zork.java

51 lines
1.4 KiB
Java

/*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.util.Scanner;
/* And away we go*/
public class Zork {
public static void runZork(final String filename) {
ZorkGame game = ParserIOC.xmlParser().parse(filename, System.out);
ActionDispatcher d = new ActionDispatcher(game);
/* starting the game!*/
d.dispatch("Start at Entrance");
/* There is no stopping in Zork, until we're done!!*/
while (game.isRunning()) {
Scanner input = new Scanner(System.in);
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(final String[] args) {
if (args.length != 1) {
System.out.println("Usage: java Zork [filename]");
return;
}
runZork(args[0]);
}
}