idk ive done too much
This commit is contained in:
7
PROJECT-2/src/module-info.java
Normal file
7
PROJECT-2/src/module-info.java
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @author brett
|
||||
*
|
||||
*/
|
||||
module courses.uwstout.cs144 {
|
||||
requires junit;
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package uwstout.courses.cs144.projects.project2.companion;
|
||||
|
||||
/**
|
||||
* Represents a Player's companion.
|
||||
*
|
||||
* @author Brett Bender
|
||||
* @version 2022.11.15
|
||||
*/
|
||||
public class Companion {
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
private static final int DEF_COOLDOWN = 0;
|
||||
private static final int MIN_COOLDOWN = 0;
|
||||
private static final int BASE_DAMAGE = 15;
|
||||
// Sayings
|
||||
private static final String VERY_NEGATIVE_SAYING = "Maybe I should take my money and go.";
|
||||
private static final String NEGATIVE_SAYING = "I'm bored.";
|
||||
private static final String NEUTRAL_SAYING = "Now what?";
|
||||
private static final String POSITIVE_SAYING = "Is that free gold I see?";
|
||||
private static final String VERY_POSITIVE_SAYING = "Woohoo! More stuff!";
|
||||
|
||||
/*
|
||||
* Class Members
|
||||
*/
|
||||
private Player player;
|
||||
private Relationship relationship;
|
||||
private int cooldown;
|
||||
|
||||
/**
|
||||
* Create a new Companion for a Player
|
||||
*
|
||||
* @param nPlayer The Player this Companion is for
|
||||
*/
|
||||
public Companion(Player nPlayer) {
|
||||
player = nPlayer;
|
||||
cooldown = DEF_COOLDOWN;
|
||||
relationship = new Relationship();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Player for this Companion
|
||||
*
|
||||
* @return The Player
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Relationship for this Companion
|
||||
*
|
||||
* @return The Relationship
|
||||
*/
|
||||
public Relationship getRelationship() {
|
||||
return relationship;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cooldown of actions
|
||||
*
|
||||
* @return The current cooldown
|
||||
*/
|
||||
public int getCooldown() {
|
||||
return cooldown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a saying based on the status of the relationship
|
||||
*
|
||||
* @return The saying
|
||||
*/
|
||||
public String getSaying() {
|
||||
String retString = "";
|
||||
switch (relationship.getRelationshipStatus()) {
|
||||
case "Very Negative":
|
||||
retString = VERY_NEGATIVE_SAYING;
|
||||
break;
|
||||
case "Negative":
|
||||
retString = NEGATIVE_SAYING;
|
||||
break;
|
||||
case "Neutral":
|
||||
retString = NEUTRAL_SAYING;
|
||||
break;
|
||||
case "Positive":
|
||||
retString = POSITIVE_SAYING;
|
||||
break;
|
||||
case "Very Positive":
|
||||
retString = VERY_POSITIVE_SAYING;
|
||||
break;
|
||||
}
|
||||
return retString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Heals the player depending on the strength of the relationship
|
||||
*
|
||||
* @return The amount healed
|
||||
*/
|
||||
public int heal() {
|
||||
int healAmount = 0;
|
||||
if (cooldown == 0) {
|
||||
// Set the cooldown
|
||||
cooldown = 4;
|
||||
int rStrength = relationship.getRelationshipStrength();
|
||||
if (rStrength != 0) {
|
||||
healAmount = (Math.abs(rStrength) + 2) / 3 * 10;
|
||||
} else {
|
||||
healAmount = 5;
|
||||
}
|
||||
}
|
||||
|
||||
return healAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attacks
|
||||
*
|
||||
* @return The damage of the attack
|
||||
*/
|
||||
public int attack() {
|
||||
int attackAmount = 0;
|
||||
if (cooldown == 0) {
|
||||
// Set the cooldown
|
||||
cooldown = 4;
|
||||
attackAmount = 5 * player.getLevel()
|
||||
+ relationship.getRelationshipStrength() + BASE_DAMAGE;
|
||||
}
|
||||
|
||||
return attackAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when time is passed
|
||||
*/
|
||||
public void tick() {
|
||||
// Decrease the cooldown
|
||||
if (cooldown > MIN_COOLDOWN) {
|
||||
cooldown--;
|
||||
}
|
||||
|
||||
// Heal the player if need be
|
||||
if (cooldown == 0
|
||||
&& (player.getCurrentHealth() < player.getMaxHealth() / 2)) {
|
||||
player.adjustHealth(heal());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
package uwstout.courses.cs144.projects.project2.companion;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests the Companion class
|
||||
*
|
||||
* @author Brett Bender
|
||||
* @version 2022.11.15
|
||||
*/
|
||||
public class CompanionTest {
|
||||
|
||||
private Player p1;
|
||||
private Player p2;
|
||||
|
||||
private Companion c1;
|
||||
private Companion c2;
|
||||
|
||||
/**
|
||||
* Sets the Test class up, creates default Players and Companions
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
p1 = new Player("Player1", 0, 10);
|
||||
p2 = new Player("Player2", 5, 15);
|
||||
|
||||
c1 = new Companion(p1);
|
||||
c2 = new Companion(p2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Companion(Player) constructor)
|
||||
*/
|
||||
@Test
|
||||
public void testCompanion() {
|
||||
assertEquals(p1, c1.getPlayer());
|
||||
assertEquals(0, c1.getCooldown());
|
||||
assertEquals(1, c1.getRelationship().getRelationshipStrength());
|
||||
assertEquals(false, c1.getRelationship().wasQuestCompleted());
|
||||
|
||||
assertEquals(p2, c2.getPlayer());
|
||||
assertEquals(0, c2.getCooldown());
|
||||
assertEquals(1, c2.getRelationship().getRelationshipStrength());
|
||||
assertEquals(false, c2.getRelationship().wasQuestCompleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link Companion#getSaying()} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetSaying() {
|
||||
setRelationshipStrength(c1.getRelationship(), -10);
|
||||
assertEquals("Maybe I should take my money and go.", c1.getSaying());
|
||||
|
||||
setRelationshipStrength(c1.getRelationship(), -5);
|
||||
assertEquals("I'm bored.", c1.getSaying());
|
||||
|
||||
setRelationshipStrength(c1.getRelationship(), 0);
|
||||
assertEquals("Now what?", c1.getSaying());
|
||||
|
||||
setRelationshipStrength(c1.getRelationship(), 5);
|
||||
assertEquals("Is that free gold I see?", c1.getSaying());
|
||||
|
||||
setRelationshipStrength(c1.getRelationship(), 19);
|
||||
assertEquals("Woohoo! More stuff!", c1.getSaying());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link Companion#heal()} method.
|
||||
*/
|
||||
@Test
|
||||
public void testHeal() {
|
||||
assertEquals(10, c1.heal());
|
||||
assertEquals(4, c1.getCooldown());
|
||||
|
||||
assertEquals(0, c1.heal());
|
||||
|
||||
doTicks(c1, 4);
|
||||
setRelationshipStrength(c1.getRelationship(), 5);
|
||||
assertEquals(20, c1.heal());
|
||||
assertEquals(4, c1.getCooldown());
|
||||
|
||||
doTicks(c1, 4);
|
||||
setRelationshipStrength(c1.getRelationship(), -5);
|
||||
assertEquals(20, c1.heal());
|
||||
assertEquals(4, c1.getCooldown());
|
||||
|
||||
doTicks(c1, 4);
|
||||
setRelationshipStrength(c1.getRelationship(), -2);
|
||||
assertEquals(10, c1.heal());
|
||||
assertEquals(4, c1.getCooldown());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link Companion#attack()} method.
|
||||
*/
|
||||
@Test
|
||||
public void testAttack() {
|
||||
// Level 1 Values
|
||||
setRelationshipStrength(c1.getRelationship(), 0);
|
||||
|
||||
assertEquals(20, c1.attack());
|
||||
assertEquals(4, c1.getCooldown());
|
||||
|
||||
assertEquals(0, c1.attack());
|
||||
|
||||
doTicks(c1, 4);
|
||||
setRelationshipStrength(c1.getRelationship(), 5);
|
||||
assertEquals(25, c1.attack());
|
||||
assertEquals(4, c1.getCooldown());
|
||||
|
||||
doTicks(c1, 4);
|
||||
setRelationshipStrength(c1.getRelationship(), -5);
|
||||
assertEquals(15, c1.attack());
|
||||
assertEquals(4, c1.getCooldown());
|
||||
|
||||
// Level 5 Values
|
||||
setRelationshipStrength(c2.getRelationship(), 0);
|
||||
assertEquals(0, c1.attack());
|
||||
|
||||
doTicks(c2, 1);
|
||||
assertEquals(40, c2.attack());
|
||||
assertEquals(4, c2.getCooldown());
|
||||
|
||||
doTicks(c2, 4);
|
||||
setRelationshipStrength(c2.getRelationship(), 5);
|
||||
assertEquals(45, c2.attack());
|
||||
assertEquals(4, c2.getCooldown());
|
||||
|
||||
doTicks(c2, 4);
|
||||
setRelationshipStrength(c2.getRelationship(), -5);
|
||||
assertEquals(35, c2.attack());
|
||||
assertEquals(4, c2.getCooldown());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link Companion#tick()} method.
|
||||
*/
|
||||
@Test
|
||||
public void testTick() {
|
||||
// Set the cooldown to 4
|
||||
c1.attack();
|
||||
|
||||
// Ensure it decreases cooldown by one each time
|
||||
c1.tick();
|
||||
assertEquals(3, c1.getCooldown());
|
||||
c1.tick();
|
||||
assertEquals(2, c1.getCooldown());
|
||||
c1.tick();
|
||||
assertEquals(1, c1.getCooldown());
|
||||
c1.tick();
|
||||
assertEquals(0, c1.getCooldown());
|
||||
|
||||
// Make sure it heals
|
||||
c1.getPlayer().adjustHealth(-6);
|
||||
c1.tick();
|
||||
assertEquals(10, c1.getPlayer().getCurrentHealth());
|
||||
|
||||
// Making sure heal amount is correct overall
|
||||
doTicks(c1, 4);
|
||||
c1.getPlayer().adjustHealth(-10);
|
||||
setRelationshipStrength(c1.getRelationship(), 0);
|
||||
c1.tick();
|
||||
assertEquals(5, c1.getPlayer().getCurrentHealth());
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases/decreases a relationship's strength to match a certain level.
|
||||
*
|
||||
* @param rel Relationship to modify
|
||||
* @param str New strength level
|
||||
*/
|
||||
private void setRelationshipStrength(Relationship rel, int str) {
|
||||
int currentStr = rel.getRelationshipStrength();
|
||||
int adjustment = str - currentStr;
|
||||
|
||||
if (adjustment < 0) {
|
||||
for (int i = 0; i < Math.abs(adjustment); i++) {
|
||||
rel.decreaseRelationship();
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < adjustment; i++) {
|
||||
rel.increaseRelationship();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the Companion's tick method count times.
|
||||
*
|
||||
* @param comp Companion to call tick on
|
||||
* @param count Number of times to call tick
|
||||
*/
|
||||
private void doTicks(Companion comp, int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
comp.tick();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package uwstout.courses.cs144.projects.project2.companion;
|
||||
|
||||
/**
|
||||
* Represents a player in a game.
|
||||
*
|
||||
* @author Brett Bender
|
||||
* @version 2022.11.15
|
||||
*/
|
||||
public class Player {
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
private static final int DEF_MAX_HEALTH = 10;
|
||||
private static final int DEF_LEVEL = 1;
|
||||
private static final int MIN_POSSIBLE_HEALTH = 0;
|
||||
|
||||
/*
|
||||
* Class Members
|
||||
*/
|
||||
private int level;
|
||||
private int maxHealth;
|
||||
private int curHealth;
|
||||
private boolean alive;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Create a new player with a name, level, and a given max health. Will
|
||||
* ensure level is at least 1, and if max health is less than or equal to 0,
|
||||
* it will be 10.
|
||||
*
|
||||
* @param nName The name of the player
|
||||
* @param nLevel The level of the player
|
||||
* @param nMaxHealth The maximum health of the player
|
||||
*/
|
||||
public Player(String nName, int nLevel, int nMaxHealth) {
|
||||
maxHealth = (nMaxHealth > 0) ? nMaxHealth : DEF_MAX_HEALTH;
|
||||
level = (nLevel >= 1) ? nLevel : DEF_LEVEL;
|
||||
curHealth = maxHealth;
|
||||
name = nName;
|
||||
alive = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level of the Player
|
||||
*
|
||||
* @return The level
|
||||
*/
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the Player
|
||||
*
|
||||
* @return The name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the max health of the Player
|
||||
*
|
||||
* @return The maximum health
|
||||
*/
|
||||
public int getMaxHealth() {
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current health of the Player
|
||||
*
|
||||
* @return The current health
|
||||
*/
|
||||
public int getCurrentHealth() {
|
||||
return curHealth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Player is alive
|
||||
*
|
||||
* @return Player's alive status
|
||||
*/
|
||||
public boolean isAlive() {
|
||||
return alive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust the health of the player. Will mark as not-alive if the change
|
||||
* causes the current health to drop below 0. Will also cap to max health.
|
||||
*
|
||||
* @param change The amount that the health should be changed.
|
||||
*/
|
||||
public void adjustHealth(int change) {
|
||||
if (alive) {
|
||||
curHealth += change;
|
||||
|
||||
if (curHealth > maxHealth) {
|
||||
curHealth = maxHealth;
|
||||
}
|
||||
|
||||
if (curHealth < MIN_POSSIBLE_HEALTH) {
|
||||
curHealth = MIN_POSSIBLE_HEALTH;
|
||||
alive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package uwstout.courses.cs144.projects.project2.companion;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests the Player class
|
||||
*
|
||||
* @author Brett Bender
|
||||
* @version 2022.11.15
|
||||
*/
|
||||
public class PlayerTest {
|
||||
|
||||
private Player p1;
|
||||
private Player p2;
|
||||
|
||||
/**
|
||||
* Sets the Test class up, creates default players
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
p1 = new Player("Player1", 0, 10);
|
||||
p2 = new Player("Player2", 5, 15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Player(String, int, int) constructor. (Including all get
|
||||
* methods)
|
||||
*/
|
||||
@Test
|
||||
public void testPlayer() {
|
||||
Player t1 = new Player("player", 0, 0);
|
||||
assertEquals("player", t1.getName());
|
||||
assertEquals(1, t1.getLevel());
|
||||
assertEquals(10, t1.getMaxHealth());
|
||||
assertEquals(true, t1.isAlive());
|
||||
assertEquals(10, t1.getCurrentHealth());
|
||||
|
||||
Player t2 = new Player("player2", -10, -10);
|
||||
assertEquals("player2", t2.getName());
|
||||
assertEquals(1, t2.getLevel());
|
||||
assertEquals(10, t2.getMaxHealth());
|
||||
assertEquals(true, t2.isAlive());
|
||||
assertEquals(10, t2.getCurrentHealth());
|
||||
|
||||
Player t3 = new Player("player3", 2, 15);
|
||||
assertEquals("player3", t3.getName());
|
||||
assertEquals(2, t3.getLevel());
|
||||
assertEquals(15, t3.getMaxHealth());
|
||||
assertEquals(true, t3.isAlive());
|
||||
assertEquals(15, t3.getCurrentHealth());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link Player#adjustHealth(int)} method.
|
||||
*/
|
||||
@Test
|
||||
public void testAdjustHealth() {
|
||||
p1.adjustHealth(-10);
|
||||
assertEquals(true, p1.isAlive());
|
||||
assertEquals(0, p1.getCurrentHealth());
|
||||
|
||||
p1.adjustHealth(-1);
|
||||
assertEquals(false, p1.isAlive());
|
||||
assertEquals(0, p1.getCurrentHealth());
|
||||
|
||||
p1.adjustHealth(1);
|
||||
assertEquals(false, p1.isAlive());
|
||||
assertEquals(0, p1.getCurrentHealth());
|
||||
|
||||
p2.adjustHealth(10);
|
||||
assertEquals(true, p2.isAlive());
|
||||
assertEquals(15, p2.getCurrentHealth());
|
||||
|
||||
p2.adjustHealth(-1);
|
||||
assertEquals(true, p2.isAlive());
|
||||
assertEquals(14, p2.getCurrentHealth());
|
||||
|
||||
p2.adjustHealth(-16);
|
||||
assertEquals(false, p2.isAlive());
|
||||
assertEquals(0, p2.getCurrentHealth());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package uwstout.courses.cs144.projects.project2.companion;
|
||||
|
||||
/**
|
||||
* Represents a relationship between a player and a companion.
|
||||
*
|
||||
* @author Brett Bender
|
||||
* @version 2022.11.15
|
||||
*/
|
||||
public class Relationship {
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
// Relationship Strength
|
||||
private static final int MAX_RELATIONSHIP_STRENGTH = 10;
|
||||
private static final int MIN_RELATIONSHIP_STRENGTH = -10;
|
||||
|
||||
// Relationship Statuses
|
||||
/// Very Negative
|
||||
private static final String STATUS_VERY_NEGATIVE = "Very Negative";
|
||||
/// Negative
|
||||
private static final int STATUS_NEGATIVE_BOUNDARY = -6;
|
||||
private static final String STATUS_NEGATIVE = "Negative";
|
||||
/// Neutral
|
||||
private static final int STATUS_NEUTRAL_BOUNDARY = -2;
|
||||
private static final String STATUS_NEUTRAL = "Neutral";
|
||||
/// Positive
|
||||
private static final int STATUS_POSITIVE_BOUNDARY = 3;
|
||||
private static final String STATUS_POSITIVE = "Positive";
|
||||
/// Very Positive
|
||||
private static final int STATUS_VERY_POSITIVE_BOUNDARY = 7;
|
||||
private static final String STATUS_VERY_POSITIVE = "Very Positive";
|
||||
|
||||
/*
|
||||
* Class Members
|
||||
*/
|
||||
private boolean questCompleted;
|
||||
private int strength;
|
||||
|
||||
/**
|
||||
* Create a new Relationship. Defaults to an uncompleted quest and a
|
||||
* strength of 1.
|
||||
*/
|
||||
public Relationship() {
|
||||
questCompleted = false;
|
||||
strength = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the strength of the Relationship.
|
||||
*
|
||||
* @return The relationship strength
|
||||
*/
|
||||
public int getRelationshipStrength() {
|
||||
return strength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the quest was completed.
|
||||
*
|
||||
* @return The quest completion status
|
||||
*/
|
||||
public boolean wasQuestCompleted() {
|
||||
return questCompleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the strength of the relationship, if the quest is not
|
||||
* completed. Will be maxed to 10.
|
||||
*/
|
||||
public void increaseRelationship() {
|
||||
if (strength < MAX_RELATIONSHIP_STRENGTH && !questCompleted) {
|
||||
strength++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decreases the strength of the relationship, if the quest is not
|
||||
* completed. Will keep at or above -10.
|
||||
*/
|
||||
public void decreaseRelationship() {
|
||||
if (strength > MIN_RELATIONSHIP_STRENGTH && !questCompleted) {
|
||||
strength--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a quest as completed, setting the strength based on if it was
|
||||
* successful or not.
|
||||
*
|
||||
* @param successful If the quest was successful or not
|
||||
*/
|
||||
public void questCompleted(boolean successful) {
|
||||
if (!questCompleted) {
|
||||
|
||||
questCompleted = true;
|
||||
|
||||
if (successful) {
|
||||
strength = MAX_RELATIONSHIP_STRENGTH;
|
||||
} else {
|
||||
strength = MIN_RELATIONSHIP_STRENGTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of the relationship status.
|
||||
*
|
||||
* @return The status of the relationship
|
||||
*/
|
||||
public String getRelationshipStatus() {
|
||||
String retString;
|
||||
if (strength < STATUS_NEGATIVE_BOUNDARY) {
|
||||
retString = STATUS_VERY_NEGATIVE;
|
||||
} else if (strength < STATUS_NEUTRAL_BOUNDARY) {
|
||||
retString = STATUS_NEGATIVE;
|
||||
} else if (strength < STATUS_POSITIVE_BOUNDARY) {
|
||||
retString = STATUS_NEUTRAL;
|
||||
} else if (strength < STATUS_VERY_POSITIVE_BOUNDARY) {
|
||||
retString = STATUS_POSITIVE;
|
||||
} else { // It is above the very positive boundary
|
||||
retString = STATUS_VERY_POSITIVE;
|
||||
}
|
||||
|
||||
return retString;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package uwstout.courses.cs144.projects.project2.companion;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests the Relationship class
|
||||
*
|
||||
* @author Brett Bender
|
||||
* @version 2022.11.15
|
||||
*/
|
||||
public class RelationshipTest {
|
||||
|
||||
private Relationship r1;
|
||||
private Relationship r2;
|
||||
|
||||
/**
|
||||
* Sets the Test class up, creating default relationships
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
r1 = new Relationship();
|
||||
r2 = new Relationship();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the default constructor
|
||||
*/
|
||||
@Test
|
||||
public void testRelationship() {
|
||||
assertEquals(1, r1.getRelationshipStrength());
|
||||
assertEquals(false, r1.wasQuestCompleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link Relationship#increaseRelationship()} method.
|
||||
*/
|
||||
@Test
|
||||
public void testIncreaseRelationship() {
|
||||
r1.increaseRelationship();
|
||||
assertEquals(2, r1.getRelationshipStrength());
|
||||
|
||||
setRelationshipStrength(r1, 10);
|
||||
assertEquals(10, r1.getRelationshipStrength());
|
||||
|
||||
setRelationshipStrength(r1, 15);
|
||||
assertEquals(10, r1.getRelationshipStrength());
|
||||
|
||||
r1.questCompleted(false);
|
||||
setRelationshipStrength(r1, 15);
|
||||
assertEquals(-10, r1.getRelationshipStrength());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link Relationship#decreaseRelationship()} method.
|
||||
*/
|
||||
@Test
|
||||
public void testDecreaseRealtionship() {
|
||||
r1.decreaseRelationship();
|
||||
assertEquals(0, r1.getRelationshipStrength());
|
||||
|
||||
setRelationshipStrength(r1, -10);
|
||||
assertEquals(-10, r1.getRelationshipStrength());
|
||||
|
||||
setRelationshipStrength(r1, -15);
|
||||
assertEquals(-10, r1.getRelationshipStrength());
|
||||
|
||||
r1.questCompleted(true);
|
||||
setRelationshipStrength(r1, -15);
|
||||
assertEquals(10, r1.getRelationshipStrength());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link Relationship#questCompleted()} method.
|
||||
*/
|
||||
@Test
|
||||
public void testQuestCompleted() {
|
||||
assertEquals(false, r1.wasQuestCompleted());
|
||||
r1.questCompleted(true);
|
||||
assertEquals(true, r1.wasQuestCompleted());
|
||||
assertEquals(10, r1.getRelationshipStrength());
|
||||
r1.questCompleted(false);
|
||||
assertEquals(true, r1.wasQuestCompleted());
|
||||
assertEquals(10, r1.getRelationshipStrength());
|
||||
|
||||
assertEquals(false, r2.wasQuestCompleted());
|
||||
r2.questCompleted(false);
|
||||
assertEquals(true, r2.wasQuestCompleted());
|
||||
assertEquals(-10, r2.getRelationshipStrength());
|
||||
r2.questCompleted(true);
|
||||
assertEquals(true, r2.wasQuestCompleted());
|
||||
assertEquals(-10, r2.getRelationshipStrength());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link Relationship#getRelationshipStatus()} method.
|
||||
*/
|
||||
@Test
|
||||
public void testGetRelationshipStatus() {
|
||||
// Very Negative
|
||||
setRelationshipStrength(r1, -10);
|
||||
assertEquals("Very Negative", r1.getRelationshipStatus());
|
||||
|
||||
setRelationshipStrength(r1, -7);
|
||||
assertEquals("Very Negative", r1.getRelationshipStatus());
|
||||
|
||||
// Negative
|
||||
setRelationshipStrength(r1, -6);
|
||||
assertEquals("Negative", r1.getRelationshipStatus());
|
||||
|
||||
setRelationshipStrength(r1, -3);
|
||||
assertEquals("Negative", r1.getRelationshipStatus());
|
||||
|
||||
// Neutral
|
||||
setRelationshipStrength(r1, -2);
|
||||
assertEquals("Neutral", r1.getRelationshipStatus());
|
||||
|
||||
setRelationshipStrength(r1, 2);
|
||||
assertEquals("Neutral", r1.getRelationshipStatus());
|
||||
|
||||
// Positive
|
||||
setRelationshipStrength(r1, 3);
|
||||
assertEquals("Positive", r1.getRelationshipStatus());
|
||||
|
||||
setRelationshipStrength(r1, 6);
|
||||
assertEquals("Positive", r1.getRelationshipStatus());
|
||||
|
||||
// Very Positive
|
||||
setRelationshipStrength(r1, 7);
|
||||
assertEquals("Very Positive", r1.getRelationshipStatus());
|
||||
|
||||
setRelationshipStrength(r1, 10);
|
||||
assertEquals("Very Positive", r1.getRelationshipStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases/decreases a relationship's strength to match a certain level.
|
||||
*
|
||||
* @param rel Relationship to modify
|
||||
* @param str New strength level
|
||||
*/
|
||||
private void setRelationshipStrength(Relationship rel, int str) {
|
||||
int currentStr = rel.getRelationshipStrength();
|
||||
int adjustment = str - currentStr;
|
||||
|
||||
if (adjustment < 0) {
|
||||
for (int i = 0; i < Math.abs(adjustment); i++) {
|
||||
rel.decreaseRelationship();
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < adjustment; i++) {
|
||||
rel.increaseRelationship();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user