Question: In java. The goal is to allow warrior.txt to have other txt files to be added on top of it the closest I have got
In java. The goal is to allow warrior.txt to have other txt files to be added on top of it the closest I have got is to have each item appear above the warrior but then I wouldnt be able to move it without alter the x and y axis which is not effienct code. VideoGameDriver package decorator;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner;
public class VideoGameDriver
private static final String ERRORUSERCHOICE "Please enter a valid number between and ;
private String options "Sword", "Shield", "Armor", "Quit" ;
private Scanner scanner;
Original ascii drawing was found here:
https:wwwasciiart.eupeopleoccupationsknights
public VideoGameDriver
scanner new ScannerSystemin;
public void play
Player warrior new WarriorSir Richard";
while true
clear;
System.out.printlnHeres our warrior: ;
System.out.printlnwarrior;
displayMenu;
int userOption getUserChoice;
if userOption
warrior new Swordwarrior;
else if userOption
warrior new Shieldwarrior;
else if userOption
warrior new Armorwarrior;
else if userOption
break;
System.out.printlnGoodbye;
private void displayMenu
System.out.printlnWhat would you like to give our warrior? ;
for int i ; i options.length; i
System.out.printlni optionsi;
private int getUserChoice
while true
System.out.printEnter Number: ;
try
int index Integer.parseIntscannernextLine;
if index index options.length
System.out.printlnERRORUSERCHOICE options.length;
continue;
return index ;
catch Exception e
System.out.printlnERRORUSERCHOICE options.length;
private void clear
System.out.printHJ;
System.out.flush;
public static void mainString args
VideoGameDriver driver new VideoGameDriver;
driver.play;
FileReader package decorator;
import java.ioFile;
import java.ioFileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class FileReader
public static ArrayList getLinesString fileName
ArrayList lines new ArrayList;
try
File file new FilefileName;
Scanner reader new Scannerfile;
while readerhasNextLine
String line reader.nextLine;
lines.addline;
reader.close;
catch FileNotFoundException e
System.out.printlnError reading file.";
eprintStackTrace;
return lines;
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
