Another pull request for Hacktoberfest

Continuing from the last blog post Fourth pull request for Hacktoberfest . Since I was unable to contact the maintainer on my fourth pull request I will be working on a different project to complete the Hacktoberfest. This project is also written in Java and revolves around game development.


Project:

The project I will be working on is called Dungeon. Dungeon is a text-based open-world RPG written in Java. This project uses Maven, Maven specifics how to build the project and also handles running tests. This is the first project that I have worked on that has some testing involved.


I had some problems setting up Maven. The Maven plugins that are used in this project were outdated and didn’t work with the latest version of Maven. Googling my problem specifically I found an article on how to solve my problem: How to solve Unable to parse configuration of mojo org.codehaus.mojo:findbugs-maven-plugin?. Once I downgrade my Maven I was able to run the mvn package command which builds the project.

Issue:

The issue I will be working on is an enchantment. The game is an open world, and the maintainer wanted a new location, a riverside. The maintainer also mentions about how this location could be used for an achievement later on.

Implementing the solution

Implementing this location had many parts to it. Looking at the issue seemed fairly simple, all location were saved as a JSON file which is later parse. I added the “Riverside” location into the JSON file and built the project. Adding only the location into the JSON file seem to work, “Riverside” locations would appear randomly on the map. Thinking that this issue was easy I decide to also create an achievement for the new “Riverside” location.


Just like locations, the achievements were also saved into a JSON file which is later parse by the code. I added the achievement to the JSON file and tested the game, which worked! While looking through the files I had edited I came to realization that I missed something.


The game already had a location called “River” and I realized that “Riverside” locations spawning randomly did not make sense. For example, “Riverside” locations would spawn next to “Desert” locations which does not make sense. “Riverside” locations are only suppose to spawn next to rivers. Knowing that I had to do some Java coding I went to work. I created a function that would only spawn “Riverside” locations to the left of a river or to the right of a river:

boolean isRiverside(Point point) {      

  River leftOfRiver = rivers.get(point.getX() - 1);      
  River rightOfRiver = rivers.get(point.getX() + 1);      
          
  return leftOfRiver != null || rightOfRiver != null;      
} 

The function is fairly simple, called in the WorldGeneration class the function checks to see if the point given has a river to the left or to the right of it. The function returns a boolean which if it yields true spawn a “Riverside” location otherwise it does not. I also created getters/setters functions to follow the code style/format of the project, see the pull request for more details.

Testing:

Now that I have finished my implementation, I am now able to test my build locally. Running the mvn test command showed these errors:

[WARNING] src\main\java\org\mafagafogigante\dungeon\game\RiverGenerator.java:64,35 WhitespaceAround: WhitespaceAround: '{' is not preceded with whitespace.

[WARNING] src\main\java\org\mafagafogigante\dungeon\game\WorldGenerator.java:74,63 WhitespaceAround: WhitespaceAround: '{' is not preceded with whitespace.

The Maven plugin that checks code format detected this error. I forgot to enter a white space before { symbol after defining the function. It is pretty surprising to me that the Maven plugin was able to pick this up, I guess the maintainer created the conditions for this. This was very insightful, in the future I should also try using Maven for managing, testing, and building. Fixing my problem I try again.


Running the testing again using mvn test I receive a different error:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.008 sec <<< FAILURE!
 testIsFileHasValidStructure(org.mafagafogigante.dungeon.io.AchievementsJsonFileTest)  Time elapsed: 0.004 sec  <<< ERROR!
 java.lang.IllegalArgumentException: RIVERSIDE does not have a rule.

This time one of the test scripts failed. The error says it occurs in file AchievementsJsonFileTest. Looking into it, I found that this problem was caused because of the achievement I added into the game. In the test script, I had to specify the achievement “rule” (How the achievement will be achieved) so that the test script can work. After adding the achievement to the test script, I am ready to create the pull request.

Pull Request:

I created the pull request and upload it to be reviewed. Once the pull request was created the automation testing kicked in. Since I already tested locally the automated test should all pass:

I see that the testing passed on different java environments and receive all 3 check approval.


I am waiting on the creator of the project to reply to me. The maintainer said the change was good, but commit message was not so he changed it. He refereed to me this article about commit message conventions which seems very helpful. Finally my pull request is merged. I found to really like the concept of this game, and actually had some fun playing it. If I ever have some free time I may try to contribute to this project again.


Conclusion to Hacktoberfest

I do feel like I achieve my goals in this Hacktoberfest, I met new people, learned new things and have a better understanding on how open source projects work.

Links:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s