2022-11-16 15:18:00 +00:00
|
|
|
/*Drew Schuster
|
|
|
|
dtschust
|
|
|
|
ECE462
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.github.dtschust.zork;
|
|
|
|
|
2022-11-22 12:43:15 +00:00
|
|
|
import com.github.dtschust.zork.parser.ParserIOC;
|
2022-11-21 15:36:38 +00:00
|
|
|
import com.github.dtschust.zork.repl.ActionDispatcher;
|
2022-11-16 15:18:00 +00:00
|
|
|
|
2022-11-22 16:25:40 +00:00
|
|
|
import java.io.PrintStream;
|
2022-11-16 15:18:00 +00:00
|
|
|
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-16 15:18:00 +00:00
|
|
|
|
2022-11-22 16:25:40 +00:00
|
|
|
ActionDispatcher d = new ActionDispatcher(game, output);
|
2022-11-16 15:18:00 +00:00
|
|
|
|
2022-11-22 16:25:40 +00:00
|
|
|
/* starting the game!*/
|
|
|
|
d.dispatch("Start at Entrance");
|
2022-11-21 15:36:38 +00:00
|
|
|
|
2022-11-16 15:18:00 +00:00
|
|
|
/* There is no stopping in Zork, until we're done!!*/
|
2022-11-21 15:36:38 +00:00
|
|
|
while (game.isRunning()) {
|
2022-11-22 16:25:40 +00:00
|
|
|
String userInput = input.nextLine();
|
2022-11-16 15:18:00 +00:00
|
|
|
|
|
|
|
/*Now that we have the user command, check the input*/
|
2022-11-22 14:12:55 +00:00
|
|
|
if (!game.evaluateTriggers(userInput)) {
|
2022-11-18 15:56:32 +00:00
|
|
|
/* If we haven't skipped, perform the user action*/
|
2022-11-21 15:36:38 +00:00
|
|
|
d.dispatch(userInput);
|
2022-11-16 15:18:00 +00:00
|
|
|
|
2022-11-22 14:20:35 +00:00
|
|
|
// check the triggers again (various states have changed, gnomes need to be found!)
|
2022-11-22 14:12:55 +00:00
|
|
|
game.evaluateTriggers("");
|
2022-11-16 15:18:00 +00:00
|
|
|
}
|
2022-11-20 13:11:58 +00:00
|
|
|
}
|
2022-11-16 15:18:00 +00:00
|
|
|
|
2022-11-18 15:56:32 +00:00
|
|
|
// single point of termination
|
|
|
|
System.exit(0);
|
2022-11-16 15:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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]);
|
|
|
|
}
|
|
|
|
}
|