Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 14 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions adventure.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.29.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2.external:jakarta.inject:2.6.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.grizzly:grizzly-http-server:2.4.4" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.grizzly:grizzly-http:2.4.4" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.grizzly:grizzly-framework:2.4.4" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-common:2.29.1" level="project" />
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:osgi-resource-locator:1.0.3" level="project" />
<orderEntry type="library" name="Maven: com.sun.activation:jakarta.activation:1.2.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-server:2.29.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-client:2.29.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-jaxb:2.29.1" level="project" />
<orderEntry type="library" name="Maven: jakarta.validation:jakarta.validation-api:2.0.2" level="project" />
<orderEntry type="library" name="Maven: jakarta.xml.bind:jakarta.xml.bind-api:2.3.2" level="project" />
<orderEntry type="library" name="Maven: jakarta.activation:jakarta.activation-api:1.2.1" level="project" />
<orderEntry type="library" name="Maven: jakarta.ws.rs:jakarta.ws.rs-api:2.1.6" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.inject:jersey-hk2:2.26" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-locator:2.5.0-b42" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2.external:javax.inject:2.5.0-b42" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2.external:aopalliance-repackaged:2.5.0-b42" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-api:2.5.0-b42" level="project" />
<orderEntry type="library" name="Maven: javax.inject:javax.inject:1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-utils:2.5.0-b42" level="project" />
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.2" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.22.0-CR2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.10.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.10.0" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-json-jackson:2.29.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.ext:jersey-entity-filtering:2.29.1" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.9.9" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.xerial:sqlite-jdbc:3.32.3.2" level="project" />
</component>
</module>
5 changes: 0 additions & 5 deletions src/main/java/Main.java

This file was deleted.

89 changes: 89 additions & 0 deletions src/main/java/student/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package student;

import com.fasterxml.jackson.databind.ObjectMapper;
import student.adventure.AdventureDesign;
import student.adventure.Room;
import student.adventure.UserMoves;

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;

/**
* Main class that uses a scanner input to call methods, and is used as a UI. Commands include "go", "take",
* "drop", "examine", and more. Accounts for spelling and spacing errors.
*/
public class Main {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your main has way too much in it right now. All of your game logic should be in its own class. At the moment its impossible to test your game engine, which is a big issue as we always want to make our code as easy to test as possible.

private static AdventureDesign currentDesign;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of the name currentDesign because that implies the design could change mid-game which it won't.

private static String startingRoom;
private static String endingRoom;

public static void main(String[] args) {
File file = new File("src/main/resources/BreakingBad.json");
ObjectMapper mapper = new ObjectMapper();
try {
//Store JSON data into an AdventureDesign Object
currentDesign = mapper.readValue(file, AdventureDesign.class);
} catch (Exception e) {
System.out.println("Please try again!");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little odd that you tell the user to try again, but you don't give them the opportunity to try again.

System.exit(0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd strongly advise you to stay away from System.exit(). This function kills your entire jvm, which makes your program very inflexible and also a little dangerous.

}
//Stores all data of rooms into a Room array
Room[] rooms = currentDesign.getRooms();
//currentRoom will be the room used for method-calling, first starting at the starting room and traversing
Room currentRoom = new Room();
for (Room room : rooms) {
if (room.getName().equalsIgnoreCase(currentDesign.getStartingRoom())) {
currentRoom = room;
//store beginning room name into variable startingRoom

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be consistent with comment casing

startingRoom = room.getName();
}
if (room.getName().equalsIgnoreCase(currentDesign.getEndingRoom())) {
//store beginning room name into variable endingRoom
endingRoom = room.getName();
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A line of whitespace would be helpful here

Scanner scanner = new Scanner(System.in);
//ArrayList that will be used for method-calling, mostly for "take" and "drop" inputs
ArrayList<String> userItems = new ArrayList<>();
//ArrayList that will be used to note down the rooms traversed, can be called through "history"
ArrayList<String> historyOfRooms = new ArrayList<>();
historyOfRooms.add(currentRoom.getName());
UserMoves.beginningOrEnd(currentRoom, startingRoom, endingRoom);
UserMoves.roomDetails(currentRoom);
while (!(currentRoom.getName().equals(endingRoom))) {
String input = scanner.nextLine();
input = input.toLowerCase();
if (input.contains("go")) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with checking like this is that it's not enough for go to be in the input, it needs to be in the front. Also there needs to be two words in a go command: go and the direction. The way you implemented the go check, it would pass even if there's only one word (like golf) which is incorrect behavior.

//Stores whole input into a String array, trims the spaces, and splits it at "go" to obtain keyword
String[] moves = input.trim().split("go");
//updates the currentRoom object through the keyword
currentRoom = UserMoves.updateRoom(currentRoom, moves[1], currentDesign);
UserMoves.roomDetails(currentRoom);
UserMoves.beginningOrEnd(currentRoom, startingRoom, endingRoom);
//historyOfRooms adds the current state of the room into the list
if(!historyOfRooms.contains(currentRoom.getName())) {
historyOfRooms.add(currentRoom.getName());
}
} else if (input.contains("examine")) {
UserMoves.examine(currentRoom);
} else if (input.contains("take")) {
String[] items = input.split("take");
//Splits the keyword after "take", and runs it through the takeItem method
UserMoves.takeItem(currentRoom, items[1].trim(), userItems);
} else if (input.contains("drop")) {
String[] items = input.split("drop");
//Splits the keyword after "drop", and runs it through the dropItem method
UserMoves.dropItem(currentRoom, items[1].trim(), userItems);
} else if (input.contains("history")) {
System.out.println("Here are the rooms you have traveled: " + historyOfRooms);
} else if (input.contains("inventory")) {
System.out.println("Here are your items: " + userItems);
} else if (input.equalsIgnoreCase("quit") || input.equalsIgnoreCase("exit")) {
//Leaves game if "quit" or "exit" is called
System.out.println("Goodbye! We hope to see you soon!");
System.exit(0);
}
}
}
}
50 changes: 50 additions & 0 deletions src/main/java/student/adventure/AdventureDesign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package student.adventure;

public class AdventureDesign {

//the full list of rooms in the JSON file
public Room[] rooms;
//the name of the room that one starts in, stored in a String
public String startingRoom;
//the name of the room that one ends in, stored in a String
public String endingRoom;

public AdventureDesign() {

}
/**
* getter to retrieve the starting room of the adventure
* @return startingRoom
*/
public String getStartingRoom() {
return startingRoom;
}

/**
* getter to retrieve the ending room of the adventure
* @return endingRoom
*/
public String getEndingRoom() {
return endingRoom;
}

/**
* getter to retrieve the full list of rooms in JSON, all stored in the Room object
* @return rooms
*/
public Room[] getRooms() {
return rooms;
}

/**
* Complete constructor for the AdventureDesign class
* @param startingRoom - the starting room of the adventure
* @param endingRoom - the ending room of the adventure
* @param rooms - the full array of the rooms available
*/
public AdventureDesign(String startingRoom, String endingRoom, Room[] rooms) {
this.startingRoom = startingRoom;
this.endingRoom = endingRoom;
this.rooms = rooms;
}
}
41 changes: 41 additions & 0 deletions src/main/java/student/adventure/DirectionsOnMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package student.adventure;

/**
* This class works much like a linked list, where the Direction acts as a key, and the next room is viewed
* as a value
*/
public class DirectionsOnMap {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just call this class Directions? DirectionsOnMap feels a bit redundant.

//the direction one is going in
private String directionName;
//the next room one will go in following the currentDirection
private String room;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd advise you to call this member variable roomName since you have an object type called Room.


public DirectionsOnMap() {

}
/**
* getter to retrieve the name of the direction
* @return directionName
*/
public String getDirectionName() {
return directionName;
}

/**
* getter to retrieve the name of the room that will be reached following a said direction
* @return room
*/
public String getRoom() {
return room;
}

/**
* Full constructor for the DirectionsOnMap class
* @param directionName - name of the direction(north, east, south, west, etc.)
* @param roomName - name of the room in said direction
*/
public DirectionsOnMap(String directionName, String roomName) {
this.directionName = directionName;
this.room = roomName;
}
}
7 changes: 0 additions & 7 deletions src/main/java/student/adventure/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
This is where code related to your main adventure game should go.

If you are on Week 1 of the assignment, this is the right place to put your code!

Get started by creating some POJOs for the JSON data.

Feel free to delete me :)
70 changes: 70 additions & 0 deletions src/main/java/student/adventure/Room.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package student.adventure;

public class Room {
//name of the room/location
private String name;
//description of the room that one is in
private String description;
//the items that are available to pick up in the room
private String[] items;
//the directions that one can go in at that certain location
private DirectionsOnMap[] directions;

//Empty constructor for Jackson Mapping
public Room() {

}
/**
* getter to retrieve the name of the room
* @return name
*/
public String getName() {
return name;
}

/**
* getter to retrieve the description of the room
* @return description
*/
public String getDescription() {
return description;
}

/**
* getter to retrieve the items in the room, stored in a String array
* @return items
*/
public String[] getItems() {
return items;
}

/**
* getter to retrieve the directions in the room, stored in a different class DirectionsOnMap
* @return directions
*/
public DirectionsOnMap[] getDirections() {
return directions;
}

/**
* setter to modify the list of items in a location after a take/drop method
* @param newItems - the new modified list
*/
public void setNewItems(String[] newItems) {
items = newItems;
}

/**
* Full constructor for the Room class
* @param name - name of the room
* @param description - description of the room
* @param items - items located in the room
* @param directions - possible locations from the room
*/
public Room(String name, String description, String[] items, DirectionsOnMap[] directions) {
this.name = name;
this.description = description;
this.items = items;
this.directions = directions;
}
}
Loading