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

55 lines
1.5 KiB
Java
Raw Normal View History

/*Drew Schuster
dtschust
ECE462
*/
package com.github.dtschust.zork;
2022-11-22 12:43:15 +00:00
import com.github.dtschust.zork.parser.ParserIOC;
import com.github.dtschust.zork.repl.ActionDispatcher;
2022-11-22 16:25:40 +00:00
import java.io.PrintStream;
import java.util.Scanner;
/* And away we go*/
public class Zork {
2022-11-22 14:20:35 +00:00
final ZorkGame game;
2022-11-22 16:25:40 +00:00
final Scanner input = new Scanner(System.in);
final PrintStream output = System.out;
2022-11-22 10:32:57 +00:00
2022-11-22 12:43:15 +00:00
public Zork(final String filename) {
game = ParserIOC.xmlParser().parse(filename);
2022-11-22 16:25:40 +00:00
ActionDispatcher d = new ActionDispatcher(game, output);
2022-11-22 16:25:40 +00:00
/* starting the game!*/
d.dispatch("Start at Entrance");
/* There is no stopping in Zork, until we're done!!*/
while (game.isRunning()) {
2022-11-22 16:25:40 +00:00
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);
2022-11-22 14:20:35 +00:00
// 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]);
}
}