Skip to content

KAllan357/Achievement-System-Challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Kyle Allan
KAllan357@gmail.com
https://github.com/KAllan357/Achievement-System-Challenge

Started 2/1/2011 and finished 3/7/2011

This is a coding exercise that came from the Riot Games careers website which I navigated to while looking at the game League of Legends. The URL can be found at http://www.riotgames.com/careers/software-engineer-java-pvpnet-platform-los-angeles.

Explanation of Methods

I decided to create an easily extensible DSL (Domain Specific Language) for modeling an Achievement. After writing the initial domain objects, I created an XML interpretation of each Achievement listed in the document. They all accessed a particular property on one of the domain objects, optionally did some math on another property of that object, and compared that against a set constant.

XStream provides an excellent and simple way of creating POJO's from an XML document. Once I could easily create Achievement objects, I created the RuleHandler object for taking those pieces and doing the rule processing. This involves a bit of Java Reflection, to access particular properties on the domain objects. Rule processing also involves a few switch statements and enums to simplify the "Math" and "Comparison" sections of the code.

I added two new fields to the GamePlayer object - totalDamageReceived, totalPhysicalDamageReceived, and totalMagicalDamageReceived. These are used in conjunction with the new achievement - Team Carry. This achievement is awarded when: (totalDamageInflicted / totalDamageReceived) >= 2.

Installation Instructions

1. To install, click the Downloads button on the page - https://github.com/KAllan357/Achievement-System-Challenge. Select your preferred format. Extract the archive.
2. Create a new workspace in Eclipse and open it in Eclipse.
3. Create a new Java Project in the project Explorer. Call it "AchievementChallenge"
4. Right click on the new project and select Import. Under the general tab, select File System and hit Next. Navigate to the AchievementChallenge directory that was extracted from the archive and click OK. The words "AchievementChallenge" should appear in the left pane - check the root box and hit Finish. It will ask you if you  want to overwrite your .project file. Go ahead and say yes.
5. If this was done correctly, the project should be in its proper form with a src/main/java, src/test/java, and src/main/resources under the root (as well as some 
   other entries).
6. Maven should auto-resolve your dependencies (if Maven is installed). Note: The only dependencies are JUnit 4 and XStream 1.3.1, and xpp3-1.1.4c (part of XStream).
6a. If you do not have Maven, the dependency jars are included in the /lib folders. Simply associate them into the AchievementChallenge build path in Eclipse to resolve them.

Execution Instructions

Once downloaded and imported into Eclipse, there are two ways to run the unit tests to see the Achievement results.

From a terminal application, navigate to the downloaded directory where the Maven pom.xml file is located. At the prompt execute $ mvn clean install to build the project and execute the unit tests. The output from CodingChallengeTest should indicate what achievements were earned for which player at the end of a game.

View the CodingChallengeTest inside Eclipse and execute it is a JUnit test. This should print the achievement information to the console of Eclipse.

Viewing the Code

All the code can be viewed at Github or viewed in Eclipse once it has all been imported. The following is a brief explanation of the layout:
** Under src/main/java
	* kda.achievement.domain contains my interpretation of all the domain classes that need implementations.
	* kda.achievement.enumeration contains some Java enum types to help simplify the logic in other areas.
	* kda.achievement.logic contains the Achievement and Rule handler code which does almost all of the work in processing achievements.
** Under src/test/java
	* kda.achievement.helpers contains a helper class for assisting in the creation of some common domain objects.
	* kda.achievement.logic.tests contains the JUnit tests for my domain objects and handlers. This also contains the CodingChallenge test case that implements some extra functions.
** Under src/main/resources
	* xml contains the XML resources that are the DSL interpretation of the Achievements.

Improvements

There are still some refinements that could be made to this solution:

* Define an XSD to give a proper outline to what can be appropriate in the DSL for Achievements.
* The RuleHandler could be more robust and may fail in certain XML configurations.
* So far, all achievements are evaluating BigDecimals and the RuleHandler can only handle numbers. If achievements are introduced to compare Strings or other objects, it will fail.
* Implement some more robust error handling and logging (Log4J).
* Some JUnit tests may start to fail as more Achievements are added. It is usually fine for a test to fail, but I may be a bit aggressive in some of my testing.

Example of Output

The Player in this game Shaq earned the following achievements:
Achievement Unlocked! Bruiser: You can really dish out the pain!
Achievement Unlocked! Team Carry: You teach others what its like to deal damage!

The Player in this game Ryan earned the following achievements:
Achievement Unlocked! Bruiser: You can really dish out the pain!
Achievement Unlocked! Sharpshooter: Your aim is tried and true!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages