Question: 1 . Download the following class source files: DevisionTree.java TextDecisionGame.java TextDecisionGameBuilder.java TreeNode.java 2 . In Eclipse, create a new Java project called Project 2
Download the following class source files:
DevisionTree.java
TextDecisionGame.java
TextDecisionGameBuilder.java
TreeNode.java
In Eclipse, create a new Java project called "Project and import the above files.
Both TextDecisionGameBuilder.java and TextDecisionGame.java have main methods.
TextDecisionGameBuilder is the one that will help you to build your games. This will
compile and correctly run without further modification.
Using TextDecisionGameBuilder, generate of your own textbased games. Each game
should have at least one path to completion that is at least scenarios deep
Analysis the recursive methods recursiveBuildTree, recursiveSave and recursiveLoad in
the class DecisionTree and gain an understanding of how the trees are is built. Generate
a visual representation in tree form of the order in which each node is created. Put a
number inside the node to denote the order you do not need to put the scenarios in
TextDecisionGame is the second program with main, and this is the actual game
launcher. When you run it it will ask for a save file you created with
TextDecisionGameBuilder. In order for it to work, you need to implement the method
play inside the DecisionTree class. This method is NOT recursive. You will use a loop,
and ask the user what option they wish to choose... moving a traverse pointer to the next
node in the tree based on the users choice. example: travtrav.getOption or
travtrav.getOption
public class TextDecisionGameBuilder
public static void mainString args
TODO Autogenerated method stub
DecisionTree d new DecisionTree;
dbuildStory;
dsaveTreeToFile;import java.util.Scanner;
public class TextDecisionGame
public static void mainString args
Scanner input new ScannerSystemin;
DecisionTree dt new DecisionTree;
char choice;
do
System.out.printlnWhat file your you like to load?";
String filename input.nextLine;
Load up a game from the text file
dtloadTreeFromFilefilename;
Beginning playing.
dtplay;
do
System.out.printlnWould you like to play again?";
choice input.nextLinecharAt;
whilechoice n&&choice N&&choice Y&&choice y;
whilechoice Y choice y; import java.ioFile;
import java.ioFileNotFoundException;
import java.ioPrintWriter;
import java.util.Scanner;
public class DecisionTree
private TreeNode head null;
Scanner input new ScannerSystemin;
public void play
Fill in code here
public void buildStory
head recursivelyBuildTreenew String;
System.out.printlnThe Story Is Complete!";
private TreeNode recursivelyBuildTreeString storySoFar
Reiterate the story so far....
System.out.printlnThe story so far...";
System.out.printlnstorySoFar;
Create a new node
TreeNode newNode new TreeNode;
Find out if this is an end to the story
char choice;
do
System.out.printlnIs this an ending node? yn;
choice input.nextLinecharAt;
whilechoice n&&choice N&&choice Y&&choice y;
Set the newNode to reflect if it's an ending...
newNode.setEndingchoicey choiceY;
Get the text for this segment
String temp;
do
System.out.printlnWhat is the text for this section of the story?";
temp input.nextLine;
System.out.printlnAre you okay with this?yn: temp;
choice input.nextLinecharAt;
whilechoice nchoice N;
Set the newNode to reflect the new text
newNode.setMessagetemp;
Recursively call recursivelyBuildTree if this is not an ending...
ifnewNode.isEnding
newNode.setOptionrecursivelyBuildTreestorySoFartemp
"Option chosen"
;
newNode.setOptionrecursivelyBuildTreestorySoFartemp
"Option chosen"
;
return newNode;
public void saveTreeToFile
System.out.printlnWhat would you like your file name saved as;
String filename input.nextLine;
Create file
try
PrintWriter pw new PrintWriterfilename;
recursiveSavepwhead;
pwclose;
catchFileNotFoundException e
System.out.printlnFile not created! Issue creating file: filename;
private void recursiveSavePrintWriter output, TreeNode currentNode
Save the text from this node
output.printlncurrentNodegetMessage;
Save whether or not this is an ending node
output.printlncurrentNodeisEnding;
if this is not an ending, we need to go deeper
ifcurrentNode.isEnding
recursiveSaveoutputcurrentNode.getOption;
recursiveSaveoutputcurrentNode.getOption;
public void loadTreeFromFileString filename
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
