[mud4j-commit] SF.net SVN: mud4j: [107] trunk/mud4j-core/src
Status: Pre-Alpha
Brought to you by:
mpurland
From: <mpu...@us...> - 2007-01-14 00:43:33
|
Revision: 107 http://mud4j.svn.sourceforge.net/mud4j/?rev=107&view=rev Author: mpurland Date: 2007-01-13 16:42:58 -0800 (Sat, 13 Jan 2007) Log Message: ----------- Change design of abilities to use constructor injection. Modified Paths: -------------- trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java trunk/mud4j-core/src/java/net/sf/mud4j/ability/LocationAbility.java trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/CharacterAbilityTest.java trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java Modified: trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java 2007-01-14 00:31:26 UTC (rev 106) +++ trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java 2007-01-14 00:42:58 UTC (rev 107) @@ -23,13 +23,32 @@ * * @author Matthew Purland */ -public interface CharacterAbility extends Ability { +public abstract class CharacterAbility implements Ability { + + // Character interface to use for ability. + protected Character character; /** - * Run the ability for the specified player. + * Constructor to provide association between character and + * the ability. * - * @param character Character instance. - * @throws AbilityException + * @param character Character to associate to the ability. */ - public void run(Character character) throws AbilityException; + public CharacterAbility(Character character) { + this.character = character; + } + + /** + * Get the character. + * + * @return the character. + */ + public Character getCharacter() { + return this.character; + } + + /** + * {@inheritDoc} + */ + abstract public void run() throws AbilityException; } Modified: trunk/mud4j-core/src/java/net/sf/mud4j/ability/LocationAbility.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/ability/LocationAbility.java 2007-01-14 00:31:26 UTC (rev 106) +++ trunk/mud4j-core/src/java/net/sf/mud4j/ability/LocationAbility.java 2007-01-14 00:42:58 UTC (rev 107) @@ -23,14 +23,31 @@ * * @author Matthew Purland */ -public interface LocationAbility extends Ability { +public abstract class LocationAbility implements Ability { + // Location for the ability. + private Location location; + /** - * Run an ability on a location. + * Constructor to create a LocationAbility to associate + * the ability with a location. * - * @param location Location to run ability on. - * @throws AbilityException + * @param location Location to associate with the specific ability. */ - public void run(Location location) throws AbilityException; + public LocationAbility(Location location) { + this.location = location; + } + + /** + * Get the location for the ability. + * @return Returns the location that is associated with the ability. + */ + public Location getLocation() { + return location; + } + /** + * {@inheritDoc} + */ + abstract public void run() throws AbilityException; } Modified: trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/CharacterAbilityTest.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/CharacterAbilityTest.java 2007-01-14 00:31:26 UTC (rev 106) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/CharacterAbilityTest.java 2007-01-14 00:42:58 UTC (rev 107) @@ -39,7 +39,7 @@ * Assert that we can create an ability. */ public void testCreateCharacterAbility() { - ability = new MockCharacterAbility(); + ability = new MockCharacterAbility(character); } @@ -50,10 +50,10 @@ * @throws AbilityException */ public void testRunCharacterAbility() throws AbilityException { - ability = new MockCharacterAbility(); + ability = new MockCharacterAbility(character); try { - ability.run(character); + ability.run(); fail("MockCharacterAbility did not an expected AbilityException."); } catch (AbilityException ex) { Modified: trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java 2007-01-14 00:31:26 UTC (rev 106) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java 2007-01-14 00:42:58 UTC (rev 107) @@ -27,12 +27,17 @@ * * @author Matthew Purland */ -public class MockCharacterAbility implements CharacterAbility { +public class MockCharacterAbility extends CharacterAbility { + + public MockCharacterAbility(Character character) { + super(character); + } + /* (non-Javadoc) * @see net.sf.mud4j.ability.CharacterAbility#run(net.sf.mud4j.character.Character) */ - public void run(Character character) throws AbilityException { + public void run() throws AbilityException { try { character.message(MockCharacter.TEST_MESSAGE); } @@ -41,12 +46,5 @@ } } - /* (non-Javadoc) - * @see net.sf.mud4j.ability.Ability#run() - */ - public void run() throws AbilityException { - throw new UnsupportedOperationException(); - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |