Skip to content

Commit

Permalink
Add weapon and weapon type classes
Browse files Browse the repository at this point in the history
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
ExcaliburZero committed May 11, 2016
1 parent 564f335 commit 7f038d9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/src/com/github/excaliburzero/weapons/BasicSword.java
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);
}

}
36 changes: 36 additions & 0 deletions core/src/com/github/excaliburzero/weapons/Weapon.java
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;
}
}
11 changes: 11 additions & 0 deletions core/src/com/github/excaliburzero/weapons/WeaponType.java
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 core/test/com/github/excaliburzero/weapons/WeaponTest.java
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());
}
}

0 comments on commit 7f038d9

Please sign in to comment.