From 37d76cde3040bc1572c54dbc13057909fb4bf6c7 Mon Sep 17 00:00:00 2001 From: Emma Date: Fri, 22 Oct 2021 16:52:18 -0700 Subject: [PATCH] Added implementation of critical hit based on bullets. --- .../kalebmarc/textfighter/main/EnemyTest.java | 7 ++++-- .../kalebmarc/textfighter/main/Weapon.java | 23 +++++++++++++++++++ .../textfighter/main/WeaponTest.java | 14 +++++++---- .../textfighter/player/Settings.java | 5 ++++ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java b/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java index 1aa6c4ad..daa3a1a3 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java @@ -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 @@ -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(); @@ -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)); } } diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java index 48a2e615..2add22c3 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java @@ -15,6 +15,8 @@ public class Weapon implements Comparable { public static final ArrayList 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; @@ -222,6 +224,7 @@ public void dealDam() { } //Run the logic for critical hit criticalHit(); + bulletCriticalHit(); } else { noAmmo(); @@ -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() { diff --git a/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java b/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java index e4eff15a..45c6a4b4 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java @@ -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 @@ -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); @@ -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; @@ -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(); @@ -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)); } } diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Settings.java b/src/com/hotmail/kalebmarc/textfighter/player/Settings.java index 0df8850a..3b176c1a 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Settings.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Settings.java @@ -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; @@ -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; @@ -238,6 +242,7 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi Power.level = 4; } + if (firstInit) newGameSetup(); }