Initial check-in
This commit is contained in:
commit
55e0908c78
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
11
.idea/artifacts/TextBasedGame.xml
Normal file
11
.idea/artifacts/TextBasedGame.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="TextBasedGame">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/TextBasedGame</output-path>
|
||||
<root id="archive" name="TextBasedGame.jar">
|
||||
<element id="module-output" name="Java-TextBasedGame" />
|
||||
<element id="directory" name="META-INF">
|
||||
<element id="file-copy" path="$PROJECT_DIR$/out/production/Java-TextBasedGame/META-INF/MANIFEST.MF" />
|
||||
</element>
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
7
.idea/codeStyles/Project.xml
Normal file
7
.idea/codeStyles/Project.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Java-TextBasedGame.iml" filepath="$PROJECT_DIR$/Java-TextBasedGame.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
150
.idea/workspace.xml
Normal file
150
.idea/workspace.xml
Normal file
@ -0,0 +1,150 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ArtifactsWorkspaceSettings">
|
||||
<artifacts-to-build>
|
||||
<artifact name="TextBasedGame" />
|
||||
</artifacts-to-build>
|
||||
</component>
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="510d163a-8155-4aa6-b7f2-36b413e8f633" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/artifacts/TextBasedGame.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/codeStyles/Project.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Java-TextBasedGame.iml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Armor.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Enemy.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Game.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Item.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Location.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Person.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Player.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Weapon.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/WeaponFactory.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="CodeStyleSettingsInfer">
|
||||
<option name="done" value="true" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="HighlightingSettingsPerFile">
|
||||
<setting file="file://$PROJECT_DIR$/src/Armor.java" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/src/Game.java" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/src/Item.java" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/src/Location.java" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/src/Person.java" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/src/Player.java" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/src/Weapon.java" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/src/WeaponFactory.java" root0="FORCE_HIGHLIGHTING" />
|
||||
</component>
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectCodeStyleSettingsMigration">
|
||||
<option name="version" value="2" />
|
||||
</component>
|
||||
<component name="ProjectId" id="2AUCe8CTyr1vGNX0VTmmJ0Emn3z" />
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||
"Downloaded.Files.Path.Enabled": "false",
|
||||
"Repository.Attach.Annotations": "false",
|
||||
"Repository.Attach.JavaDocs": "false",
|
||||
"Repository.Attach.Sources": "false",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"WebServerToolWindowFactoryState": "false",
|
||||
"last_opened_file_path": "C:/GitHub/Java-TextBasedGame/out/production/Java-TextBasedGame",
|
||||
"project.structure.last.edited": "Artifacts",
|
||||
"project.structure.proportion": "0.15",
|
||||
"project.structure.side.proportion": "0.29177958",
|
||||
"settings.editor.selected.configurable": "web.server"
|
||||
}
|
||||
}</component>
|
||||
<component name="RunManager" selected="Application.Load Save">
|
||||
<configuration name="Default" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="Game" />
|
||||
<module name="Java-TextBasedGame" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="Isaac" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="Game" />
|
||||
<module name="Java-TextBasedGame" />
|
||||
<option name="PROGRAM_PARAMETERS" value="Isaac 19 m" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="Load Save" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="Game" />
|
||||
<module name="Java-TextBasedGame" />
|
||||
<option name="PROGRAM_PARAMETERS" value="load Isaac" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="Jar Build" type="JarApplication">
|
||||
<option name="JAR_PATH" value="$PROJECT_DIR$/out/artifacts/TextBasedGame/TextBasedGame.jar" />
|
||||
<option name="ALTERNATIVE_JRE_PATH" />
|
||||
<method v="2">
|
||||
<option name="BuildArtifacts" enabled="true">
|
||||
<artifact name="TextBasedGame" />
|
||||
</option>
|
||||
</method>
|
||||
</configuration>
|
||||
<list>
|
||||
<item itemvalue="Application.Isaac" />
|
||||
<item itemvalue="Application.Default" />
|
||||
<item itemvalue="Application.Load Save" />
|
||||
<item itemvalue="JAR Application.Jar Build" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="510d163a-8155-4aa6-b7f2-36b413e8f633" name="Changes" comment="" />
|
||||
<created>1655054868910</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1655054868910</updated>
|
||||
<workItem from="1655054870567" duration="25215000" />
|
||||
<workItem from="1655152578449" duration="2254000" />
|
||||
<workItem from="1655170471117" duration="2590000" />
|
||||
<workItem from="1655218678744" duration="506000" />
|
||||
<workItem from="1655251289034" duration="4254000" />
|
||||
<workItem from="1655337729211" duration="2834000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
</project>
|
11
Java-TextBasedGame.iml
Normal file
11
Java-TextBasedGame.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
BIN
character/Isaac.dat
Normal file
BIN
character/Isaac.dat
Normal file
Binary file not shown.
11
src/Armor.java
Normal file
11
src/Armor.java
Normal file
@ -0,0 +1,11 @@
|
||||
import java.io.Serializable;
|
||||
public class Armor extends Item implements Serializable {
|
||||
double armor;
|
||||
String armorClass;
|
||||
|
||||
Armor(String name, String description, long value, double armor, String armorClass){
|
||||
super(name, description, value);
|
||||
this.armor = armor;
|
||||
this.armorClass = armorClass;
|
||||
}
|
||||
}
|
2
src/Enemy.java
Normal file
2
src/Enemy.java
Normal file
@ -0,0 +1,2 @@
|
||||
public class Enemy extends Person {
|
||||
}
|
341
src/Game.java
Normal file
341
src/Game.java
Normal file
@ -0,0 +1,341 @@
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
TODO: Implement move
|
||||
TODO: Implement armor
|
||||
TODO: Implement NPCs
|
||||
TODO: Implement Fights (Implement armor and attack formula)
|
||||
TODO: Implement enemy looting
|
||||
TODO: Implement game over
|
||||
TODO: Implement armor factory
|
||||
TODO: Implement map
|
||||
TODO: Implement player equipment
|
||||
TODO: Add key to left map
|
||||
TODO: Add gate to right of map
|
||||
TODO: Make inventory more robust with damage/armor/value display
|
||||
TODO: Save and load object //Test if can be broken
|
||||
TODO: Save visited locations in player
|
||||
TODO: Rewrite switch case to use either .startWith/.endsWith to .split input string and then able to use positional arguments
|
||||
Maybe:
|
||||
TODO: Make factory that can take locations as arguments
|
||||
TODO: Town after gate
|
||||
TODO: Interiors
|
||||
TODO: Dungeons
|
||||
TODO: Implement vendors
|
||||
*/
|
||||
|
||||
public class Game {
|
||||
public static void main(String[] args) throws IOException {
|
||||
boolean exit = false;
|
||||
String input;
|
||||
Player player;
|
||||
if (args.length > 0 && Objects.equals(args[0], "load")) {
|
||||
try {
|
||||
FileInputStream saveFile = new FileInputStream("./character/" + args[1] + ".dat");
|
||||
ObjectInputStream save = new ObjectInputStream(saveFile);
|
||||
player = (Player) save.readObject();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
player = createPlayer(args);
|
||||
System.out.println("You wake up feeling groggy, you feel like praying for help might provide you with direction.");
|
||||
}
|
||||
while (!exit) {
|
||||
input = reader.readLine();
|
||||
input = input.toLowerCase(Locale.ROOT);
|
||||
switch (input) {
|
||||
case "help":
|
||||
System.out.println("help: describes all given commands");
|
||||
System.out.println("inspect area/{direction}: gives you the name of the area you are in");
|
||||
System.out.println("describe area/{direction}: gives a description of the area along with the presence of items");
|
||||
System.out.println("move {direction}: moves in the specified cardinal direction");
|
||||
System.out.println("take: shows a list of all items on the ground");
|
||||
System.out.println("inspect items: shows a list of all items on the ground");
|
||||
System.out.println("save: saves player to file in directory \"character\" with the given character name. " + "load from the command line with load {character name}");
|
||||
System.out.println("inventory: shows which items are in player inventory");
|
||||
System.out.println("exit: close game");
|
||||
break;
|
||||
|
||||
case "inventory":
|
||||
System.out.println(player.inventory);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case "save":
|
||||
try {
|
||||
FileOutputStream saveFile = new FileOutputStream("./character/" + player.name + ".dat");
|
||||
ObjectOutputStream save = new ObjectOutputStream(saveFile);
|
||||
save.writeObject(player);
|
||||
save.close();
|
||||
saveFile.close();
|
||||
System.out.println("Data saved");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
break;
|
||||
|
||||
case "inspect items":
|
||||
if (player.current.items.length == 0) {
|
||||
System.out.println("There are no items here");
|
||||
}
|
||||
for(Item item: player.current.items) {
|
||||
System.out.print(item.name + ": " + item.description + " Worth: " + item.value);
|
||||
// if type is weapon show damage
|
||||
if (item instanceof Weapon) {
|
||||
System.out.println(". Damage: " + ((Weapon) item).damage);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "take":
|
||||
// section which lists the name of the items
|
||||
if (player.current.items.length == 0) {
|
||||
System.out.println("There are no items to take.");
|
||||
break;
|
||||
}
|
||||
if (player.current.items.length == 1) {
|
||||
System.out.println("There appears to be an item around. It is a " +
|
||||
Arrays.deepToString(player.current.items)
|
||||
.replace(",", "") //remove the commas
|
||||
.replace("[", "") //remove the right bracket
|
||||
.replace("]", "") //remove the left bracket
|
||||
.trim());
|
||||
}
|
||||
if (player.current.items.length > 1) {
|
||||
System.out.println(" There appears to be some items around. They are " +
|
||||
Arrays.deepToString(player.current.items)
|
||||
.replace(",", ", or") //remove the commas
|
||||
.replace("[", "") //remove the right bracket
|
||||
.replace("]", "") //remove the left bracket
|
||||
.trim());
|
||||
}
|
||||
//section asking which item
|
||||
System.out.println("Which item do you take?: ");
|
||||
input = reader.readLine();
|
||||
input = input.toLowerCase(Locale.ROOT);
|
||||
int duplicateNameCount = 0;
|
||||
Item itemToRemove;
|
||||
ArrayList<Item> duplicateItems = new ArrayList<>();
|
||||
for(Item item: player.current.items) {
|
||||
if (item.name.toLowerCase(Locale.ROOT).contains(input)) {
|
||||
duplicateItems.add(item);
|
||||
duplicateNameCount++;
|
||||
}
|
||||
}
|
||||
// if there are no duplicates
|
||||
if (duplicateNameCount == 1) {
|
||||
itemToRemove = duplicateItems.get(0);
|
||||
player.inventory.add(itemToRemove);
|
||||
}
|
||||
// if there are items with the same name, check for duplicates
|
||||
// else because duplicateItemCount is always greater than 1, does not need to be else if
|
||||
else {
|
||||
// convert arraylist to array for the purpose of the for loop
|
||||
Item[] duplicateItemsArray = new Item[duplicateItems.size()];
|
||||
duplicateItems.toArray(duplicateItemsArray);
|
||||
// print duplicate items
|
||||
int count = 1;
|
||||
for(Item item: duplicateItemsArray) {
|
||||
System.out.print("Item " + count + ": " + item.name + ": " + item.description + " Worth:" + item.value);
|
||||
// if type is weapon show damage
|
||||
if (item instanceof Weapon) {
|
||||
System.out.println(". Damage: " + ((Weapon) item).damage);
|
||||
}
|
||||
}
|
||||
// make sure choice is numeric
|
||||
String choiceStr;
|
||||
do {
|
||||
System.out.print("Which " + duplicateItems.get(0).name + " do you take?: ");
|
||||
choiceStr = reader.readLine();
|
||||
} while (isNotNumericString(choiceStr));
|
||||
//add item to player inventory
|
||||
int choice = Integer.parseInt(choiceStr);
|
||||
itemToRemove = duplicateItems.get(choice);
|
||||
player.inventory.add(duplicateItems.get(choice));
|
||||
}
|
||||
//search for index by object and remove item from location
|
||||
int index = 0;
|
||||
for (int i = 0; i < player.current.items.length; i++) {
|
||||
if (itemToRemove == player.current.items[i]) {
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
System.out.println("You took the " + itemToRemove.name + ".");
|
||||
player.current.items = Item.removeElement(player.current.items, index);
|
||||
break;
|
||||
//inspect area
|
||||
case "inspect area":
|
||||
System.out.println("You appear to be in a " + player.current.name);
|
||||
break;
|
||||
case "inspect north":
|
||||
System.out.println("This area appears to be a " + player.current.north.name);
|
||||
break;
|
||||
case "inspect east":
|
||||
System.out.println("This area appears to be a " + player.current.east.name);
|
||||
break;
|
||||
case "inspect south":
|
||||
System.out.println("This area appears to be a " + player.current.south.name);
|
||||
break;
|
||||
case "inspect west":
|
||||
System.out.println("This area appears to be a " + player.current.west.name);
|
||||
break;
|
||||
|
||||
case "move":
|
||||
System.out.println("Please provide a direction");
|
||||
case "move north":
|
||||
if (player.current.north.canWalk) {
|
||||
player.current = player.current.north;
|
||||
System.out.println("You move north");
|
||||
//begin enemy encounter
|
||||
enemyEncounter(player);
|
||||
}
|
||||
else {
|
||||
System.out.println("This area seems too difficult to navigate");
|
||||
}
|
||||
|
||||
case "move east":
|
||||
|
||||
case "move south":
|
||||
|
||||
case "move west":
|
||||
|
||||
|
||||
//describe
|
||||
|
||||
case "describe area":
|
||||
System.out.print("The area appears to be a " + player.current.description);
|
||||
if (player.current.items.length == 1) {
|
||||
System.out.println(" There appears to be an item around. It is a " +
|
||||
Arrays.deepToString(player.current.items)
|
||||
.replace(",", "") //remove the commas
|
||||
.replace("[", "") //remove the right bracket
|
||||
.replace("]", "") //remove the left bracket
|
||||
.trim());
|
||||
}
|
||||
else if (player.current.items.length > 1) {
|
||||
System.out.println(" There appears to be some items around. They are " +
|
||||
Arrays.deepToString(player.current.items)
|
||||
.replace(",", ", and") //remove the commas
|
||||
.replace("[", "") //remove the right bracket
|
||||
.replace("]", "") //remove the left bracket
|
||||
.trim());
|
||||
}
|
||||
else {
|
||||
System.out.println();
|
||||
}
|
||||
break;
|
||||
case "describe north":
|
||||
System.out.println("The area appears to be a " + player.current.north.description);
|
||||
break;
|
||||
case "describe east":
|
||||
System.out.println("The area appears to be a " + player.current.east.description);
|
||||
break;
|
||||
case "describe south":
|
||||
System.out.println("The area appears to be a " + player.current.south.description);
|
||||
break;
|
||||
case "describe west":
|
||||
System.out.println("The area appears to be a " + player.current.west.description);
|
||||
break;
|
||||
case "exit":
|
||||
exit = true;
|
||||
break;
|
||||
default:
|
||||
System.out.println("Command not recognized");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void enemyEncounter(Player player) {
|
||||
Random random = new Random();
|
||||
double doesEncounter = random.nextDouble() * 100;
|
||||
if (doesEncounter <= player.current.enemyChance) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
static Player createPlayer(String[] args) throws IOException {
|
||||
String name;
|
||||
int age;
|
||||
String gender;
|
||||
if (args.length > 0) {
|
||||
name = args[0];
|
||||
System.out.println("What is your name?: " + name);
|
||||
age = Integer.parseInt(args[1]);
|
||||
System.out.println("What is your age?: " + age);
|
||||
gender = args[2];
|
||||
System.out.println("Are you male (m), female (f), gender-fluid (g), or androgynous (a)?: " + gender);
|
||||
}
|
||||
else {
|
||||
System.out.print("What is your name?: ");
|
||||
name = reader.readLine();
|
||||
String ageString;
|
||||
do {
|
||||
System.out.print("What is your age?: ");
|
||||
ageString = reader.readLine();
|
||||
} while (isNotNumericString(ageString));
|
||||
age = Integer.parseInt(ageString);
|
||||
System.out.print("Are you male (m), female (f), gender-fluid (g), or androgynous (a)?: ");
|
||||
gender = reader.readLine();
|
||||
}
|
||||
boolean isMale = false;
|
||||
boolean isFemale = false;
|
||||
switch (gender){
|
||||
case "m":
|
||||
case "M":
|
||||
//male case
|
||||
isMale = true;
|
||||
break;
|
||||
case "f":
|
||||
case "F":
|
||||
//female case
|
||||
isFemale = true;
|
||||
break;
|
||||
case "g":
|
||||
case "G":
|
||||
//gender-fluid case
|
||||
isMale = true;
|
||||
isFemale = true;
|
||||
break;
|
||||
case "a":
|
||||
case "A":
|
||||
default:
|
||||
//androgynous case
|
||||
break;
|
||||
}
|
||||
return new Player(name, age, isMale, isFemale, startArea);
|
||||
}
|
||||
public static boolean isNotNumericString(String str) {
|
||||
try {
|
||||
Double.parseDouble(str);
|
||||
return false;
|
||||
} catch (NumberFormatException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
---------------------------------
|
||||
| $ % % % % % x x x x x x x x # |
|
||||
---------------- % -------------
|
||||
| x |
|
||||
| ! |
|
||||
-----
|
||||
*/
|
||||
//factories
|
||||
static WeaponFactory weaponFactory = new WeaponFactory();
|
||||
|
||||
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
//item lists
|
||||
static Item[] startAreaItems = {weaponFactory.getWeapon("stick")};
|
||||
//locations
|
||||
static Location impassibleShrubs = new Location("thick shrubs", "this location looks impossible to move through.",
|
||||
false);
|
||||
static Location startArea = new Location("forest clearing", "small clearing the the forest, light shines through from above.",
|
||||
true, 0,
|
||||
startAreaItems,
|
||||
null, impassibleShrubs, impassibleShrubs, impassibleShrubs);
|
||||
|
||||
}
|
23
src/Item.java
Normal file
23
src/Item.java
Normal file
@ -0,0 +1,23 @@
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Item implements Serializable {
|
||||
String name;
|
||||
String description;
|
||||
long value;
|
||||
|
||||
Item(String name, String description, long value) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
public static Item[] removeElement(Item[] original, int element){
|
||||
Item[] n = new Item[original.length - 1];
|
||||
System.arraycopy(original, 0, n, 0, element );
|
||||
System.arraycopy(original, element+1, n, element, original.length - element-1);
|
||||
return n;
|
||||
}
|
||||
}
|
41
src/Location.java
Normal file
41
src/Location.java
Normal file
@ -0,0 +1,41 @@
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Location implements Serializable {
|
||||
|
||||
//locations
|
||||
|
||||
|
||||
//end locations
|
||||
|
||||
String name;
|
||||
String description;
|
||||
Item[] items;
|
||||
boolean canWalk;
|
||||
Location north;
|
||||
Location east;
|
||||
Location south;
|
||||
Location west;
|
||||
double enemyChance;
|
||||
|
||||
Location(String name, String description, boolean canWalk) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.canWalk = false;
|
||||
this.north = null;
|
||||
this.east = null;
|
||||
this.south = null;
|
||||
this.west = null;
|
||||
}
|
||||
|
||||
Location(String name, String description, boolean canWalk, double enemyChance, Item[] items, Location north, Location east, Location south, Location west) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.canWalk = canWalk;
|
||||
this.enemyChance = enemyChance;
|
||||
this.items = items;
|
||||
this.north = north;
|
||||
this.east = east;
|
||||
this.south = south;
|
||||
this.west = west;
|
||||
}
|
||||
}
|
58
src/Person.java
Normal file
58
src/Person.java
Normal file
@ -0,0 +1,58 @@
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Person implements Serializable {
|
||||
String name;
|
||||
int age;
|
||||
double heath;
|
||||
boolean isMale;
|
||||
boolean isFemale;
|
||||
Weapon hands;
|
||||
Armor head;
|
||||
Armor chest;
|
||||
Armor leftArm;
|
||||
Armor rightArm;
|
||||
Armor leftLeg;
|
||||
Armor rightLeg;
|
||||
ArrayList<Item> inventory;
|
||||
|
||||
public Person() {
|
||||
this.inventory = new ArrayList<>();
|
||||
}
|
||||
|
||||
Person(String name, int age, double heath, boolean isMale, boolean isFemale,
|
||||
Weapon hands,
|
||||
Armor head, Armor chest, Armor leftArm, Armor rightArm, Armor leftLeg, Armor rightLeg,
|
||||
ArrayList<Item> inventory) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.heath = heath;
|
||||
this.isMale = isMale;
|
||||
this.isFemale = isFemale;
|
||||
this.hands = hands;
|
||||
this.head = head;
|
||||
this.chest = chest;
|
||||
this.leftArm = leftArm;
|
||||
this.rightArm = rightArm;
|
||||
this.leftLeg = leftLeg;
|
||||
this.rightLeg = rightLeg;
|
||||
this.inventory = inventory;
|
||||
|
||||
addEquipmentToInventory();
|
||||
}
|
||||
|
||||
public double getDamage(){
|
||||
return hands.damage;
|
||||
}
|
||||
public double getArmor(){
|
||||
return head.armor + chest.armor + leftArm.armor + rightArm.armor + leftLeg.armor + rightLeg.armor;
|
||||
}
|
||||
private void addEquipmentToInventory() {
|
||||
inventory.add(head);
|
||||
inventory.add(chest);
|
||||
inventory.add(leftArm);
|
||||
inventory.add(rightArm);
|
||||
inventory.add(leftLeg);
|
||||
inventory.add(rightLeg);
|
||||
}
|
||||
}
|
16
src/Player.java
Normal file
16
src/Player.java
Normal file
@ -0,0 +1,16 @@
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Player extends Person implements Serializable {
|
||||
boolean isPlayer = true;
|
||||
Location current;
|
||||
|
||||
Player(String name, int age, boolean isMale, boolean isFemale, Location current) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.isMale = isMale;
|
||||
this.isFemale = isFemale;
|
||||
this.heath = 100;
|
||||
this.current = current;
|
||||
}
|
||||
}
|
10
src/Weapon.java
Normal file
10
src/Weapon.java
Normal file
@ -0,0 +1,10 @@
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Weapon extends Item implements Serializable {
|
||||
double damage;
|
||||
Weapon(String name, String description, long value, double damage){
|
||||
super(name, description, value);
|
||||
this.damage = damage;
|
||||
}
|
||||
}
|
||||
|
24
src/WeaponFactory.java
Normal file
24
src/WeaponFactory.java
Normal file
@ -0,0 +1,24 @@
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Random;
|
||||
|
||||
public class WeaponFactory {
|
||||
private double getRandomDouble(double min, double max) {
|
||||
Random random = new Random();
|
||||
double randomValue = min + (max - min) * random.nextDouble();
|
||||
DecimalFormat df = new DecimalFormat("#.#");
|
||||
randomValue = Double.parseDouble(df.format(randomValue));
|
||||
return randomValue;
|
||||
}
|
||||
|
||||
public Weapon getWeapon(String weaponType) {
|
||||
if (weaponType.equalsIgnoreCase("stick")) {
|
||||
return new Weapon("Stick", "a pointed stick.", 1, getRandomDouble(1, 2));
|
||||
}
|
||||
if (weaponType.equalsIgnoreCase("sword")) {
|
||||
return new Weapon("Sword", "a shiny sword", 35, getRandomDouble(14, 16));
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user