import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.*; /** * This class creates an object that will contain the core variables and methods of the game. */ public class Game { private String playerName; public Game() { this.playerName = "Jeff"; // name defaults to jeff. } /** * This function is the entry point of the whole game. */ public void start() throws IOException { prntDlg("WELCOME TO DECISIONS"); // Welcome message playerName = usrInpt("Please enter your name:"); prntDlg("Well hello, $N"); readStory("scripts/scripta"); } /** * PRINT DIALOG: Prints a dialog box to talk to the player. * Additionally, replaces all instances of $N with the playerName * * @param text the text you want to display. */ // TODO: Make this more readable. public void prntDlg(String text) { text = text.replace("$N", playerName); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println(text); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); } /** * USER INPUT: it gets user input and returns it for use. * * @param text The text you want to prompt them with. * @return The text the user entered. */ public String usrInpt(String text) { Scanner myObj = new Scanner(System.in); // Create a Scanner object prntDlg(text); return myObj.nextLine(); } /** * This function will interpret a story file you created. *
* The story file must follow a fairly strict syntax.
* This is documented separately.
* This function determines how our story files will be read.
* It's VERY IMPORTANT to understand this function
*
* @param storyName the name of the story file you have stored.
* @throws IOException if something goes wrong.
*/
public void readStory(String storyName) throws IOException {
// This is the name of the next branch to read.
// It is updated in the FIN command.
String nextBranch;
// This is an array of options to be compiled for the player to choose from.
// They are updated using the OPT command.
// They are compiled in the FIN then cleared afterwards for the next branch.
ArrayList