-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add classes to represent weapons and weapon types. Also add a basic sword weapon, as well as testing for the new functionality.
- Loading branch information
1 parent
564f335
commit 7f038d9
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.excaliburzero.weapons; | ||
|
||
/** | ||
* The <code>BasicSword</code> class is used to represent a basic sword. | ||
* | ||
* @author Christopher Wells {@literal <cwellsny@nycap.rr.com>} | ||
*/ | ||
public class BasicSword extends Weapon { | ||
|
||
public BasicSword() { | ||
super("Basic Sword", 5, 8, WeaponType.Sword); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.excaliburzero.weapons; | ||
|
||
/** | ||
* The <code>Weapon</code> class is used to represent a weapon. | ||
* | ||
* @author Christopher Wells {@literal <cwellsny@nycap.rr.com>} | ||
*/ | ||
public abstract class Weapon { | ||
private final String name; | ||
private final int power; | ||
private final int weight; | ||
private final WeaponType type; | ||
|
||
public Weapon(String name, int power, int weight, WeaponType type) { | ||
this.name = name; | ||
this.power = power; | ||
this.weight = weight; | ||
this.type = type; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getPower() { | ||
return power; | ||
} | ||
|
||
public int getWeight() { | ||
return weight; | ||
} | ||
|
||
public WeaponType getType() { | ||
return type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.excaliburzero.weapons; | ||
|
||
/** | ||
* The <code>WeaponType</code> enum is used to represent the different possible | ||
* types of weapons. | ||
* | ||
* @author Christopher Wells {@literal <cwellsny@nycap.rr.com>} | ||
*/ | ||
public enum WeaponType { | ||
Sword, Axe, Bow | ||
} |
24 changes: 24 additions & 0 deletions
24
core/test/com/github/excaliburzero/weapons/WeaponTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.github.excaliburzero.weapons; | ||
|
||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* The <code>WeaponTest</code> class is used to test the various methods of the | ||
* Weapon class. | ||
* | ||
* @author Christopher Wells {@literal <cwellsny@nycap.rr.com>} | ||
*/ | ||
public class WeaponTest { | ||
|
||
@Test | ||
public void testGetters() { | ||
Weapon weapon = new BasicSword(); | ||
|
||
// Test each of the getter methods | ||
assertEquals("Basic Sword", weapon.getName()); | ||
assertEquals(5, weapon.getPower()); | ||
assertEquals(8, weapon.getWeight()); | ||
assertEquals(WeaponType.Sword, weapon.getType()); | ||
} | ||
} |