Skip to content

Commit

Permalink
Added implementation of critical hit based on bullets.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmamickas committed Oct 22, 2021
1 parent 205d76c commit 37d76cd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public static void setUpBeforeClass() throws Exception {
Xp.setLevel(1);

Weapon.BULLET_DAMAGE = 10;

Weapon.BULLET_CRITICAL_MULTIPLIER = 10;
Weapon.BULLET_CRITICAL_CHANCE = 1;
}

@AfterClass
Expand Down Expand Up @@ -120,7 +123,7 @@ public void testDie() {

String nextEnemy = Enemy.get().getName();

assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 0) || (nextEnemy != previousEnemy));
assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 0) || (nextEnemy != previousEnemy) || (Enemy.get().getHealth() == 20));

startHealth = Enemy.get().getHealth();

Expand All @@ -136,6 +139,6 @@ public void testDie() {

String lastEnemy = Enemy.get().getName();

assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 0) || (lastEnemy != nextEnemy));
assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 0) || (lastEnemy != nextEnemy) || (Enemy.get().getHealth() == 20));
}
}
23 changes: 23 additions & 0 deletions src/com/hotmail/kalebmarc/textfighter/main/Weapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Weapon implements Comparable<Weapon> {
public static final ArrayList<Weapon> arrayWeapon = new ArrayList<>();
//Properties
public static int BULLET_DAMAGE;
public static int BULLET_CRITICAL_MULTIPLIER;
public static int BULLET_CRITICAL_CHANCE;
//Variables
public static Weapon starting;
private static Weapon current = null;
Expand Down Expand Up @@ -222,6 +224,7 @@ public void dealDam() {
}
//Run the logic for critical hit
criticalHit();
bulletCriticalHit();

} else {
noAmmo();
Expand Down Expand Up @@ -266,10 +269,30 @@ private void criticalHit() {

}
}

private void bulletCriticalHit() {

if (bulletWasCriticalHit()) {

damageDealt *= Weapon.BULLET_CRITICAL_MULTIPLIER;

Ui.cls();
Ui.println("----------------------------------------------------");
Ui.println("Critical Bullet Hit!");
Ui.println("Your bullets dealt " + Weapon.BULLET_CRITICAL_MULTIPLIER + "x normal damage.");
Ui.println("----------------------------------------------------");
Ui.pause();

}
}

private boolean wasCriticalHit() {
return Random.RInt((int) (100 / this.critChanceMultiplier)) == 1;
}

private boolean bulletWasCriticalHit() {
return Random.RInt((int) (100 / Weapon.BULLET_CRITICAL_CHANCE)) == 1;
}

public void viewAbout() {

Expand Down
14 changes: 9 additions & 5 deletions src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public static void setUpBeforeClass() throws Exception {
Xp.setLevel(1);

Weapon.BULLET_DAMAGE = 10;

Weapon.BULLET_CRITICAL_MULTIPLIER = 10;
Weapon.BULLET_CRITICAL_CHANCE = 100;
}

@AfterClass
Expand All @@ -97,6 +100,8 @@ public void tearDown() throws Exception {
@Test
public void testDealDam() {

Weapon.set(0);

ByteArrayInputStream chooseIn = new ByteArrayInputStream("\n".getBytes());

System.setIn(chooseIn);
Expand Down Expand Up @@ -144,10 +149,9 @@ public void testDealDam() {

@Test
public void testGeneralBulletCriticalHit() {
fail("Not yet implemented");

//Weapon.BULLET_CRITICAL_MULTIPLIER = 10
//Weapon.BULLET_CRITICAL_CHANCE = 100
Weapon.BULLET_CRITICAL_MULTIPLIER = 10;
Weapon.BULLET_CRITICAL_CHANCE = 100;

int startHealth;
int endHealth;
Expand Down Expand Up @@ -177,7 +181,7 @@ public void testGeneralBulletCriticalHit() {

String nextEnemy = Enemy.get().getName();

assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 100) || (nextEnemy != previousEnemy));
assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 100) || (nextEnemy != previousEnemy) || (Enemy.get().getHealth() == 20));

startHealth = Enemy.get().getHealth();

Expand All @@ -193,6 +197,6 @@ public void testGeneralBulletCriticalHit() {

String lastEnemy = Enemy.get().getName();

assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 100) || (lastEnemy != nextEnemy));
assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 100) || (lastEnemy != nextEnemy) || (Enemy.get().getHealth() == 20));
}
}
5 changes: 5 additions & 0 deletions src/com/hotmail/kalebmarc/textfighter/player/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi
//Price
Power.price = 25;
Weapon.BULLET_DAMAGE = 10;
Weapon.BULLET_CRITICAL_CHANCE = 1;
Weapon.BULLET_CRITICAL_MULTIPLIER = 10;
FirstAid.price = 5;
Potion.spPrice = 10;
Potion.rpPrice = 20;
Expand Down Expand Up @@ -223,6 +225,8 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi
//PRICE
Power.price = 75;
Weapon.BULLET_DAMAGE = 5;
Weapon.BULLET_CRITICAL_CHANCE = 1;
Weapon.BULLET_CRITICAL_MULTIPLIER = 10;
FirstAid.price = 15;
Potion.spPrice = 25;
Potion.rpPrice = 35;
Expand All @@ -238,6 +242,7 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi
Power.level = 4;

}

if (firstInit) newGameSetup();
}

Expand Down

0 comments on commit 37d76cd

Please sign in to comment.