From 5312915343458c62319e0f4b54ea09bd10df975f Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 18 Oct 2021 21:43:10 -0700 Subject: [PATCH 01/10] Added pre-refactoring tests for potion class before modification. --- .../textfighter/player/PotionTest.java | 239 ++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java diff --git a/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java b/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java new file mode 100644 index 00000000..04f73ed8 --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java @@ -0,0 +1,239 @@ +package com.hotmail.kalebmarc.textfighter.player; + +import static org.junit.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.manipulation.Ordering.Context; + +public class PotionTest { + + static InputStream sysInBackup; + + static ByteArrayInputStream in; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + sysInBackup = System.in; // backup System.in to restore it later + in = new ByteArrayInputStream("\n".getBytes()); + System.setIn(in); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + System.setIn(sysInBackup); + } + + @Before + public void setUp() throws Exception { + sysInBackup = System.in; // backup System.in to restore it later + in = new ByteArrayInputStream("\n\n\n\n\n\n\n\n\n\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n".getBytes()); + System.setIn(in); + + Potion.spUsed = 0; + + Potion.rpUsed = 0; + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void testGet() { + //fail("Not yet implemented"); + + assertEquals(Potion.get("survival"), 0); + + assertEquals(Potion.get("recovery"), 0); + + Potion.set("survival", 5, false); + + Potion.set("recovery", 5, false); + + assertEquals(Potion.get("survival"), 5); + + assertEquals(Potion.get("recovery"), 5); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 2); + + assertEquals(Potion.get("recovery"), 3); + } + + @Test + public void testSet() { + + Potion.set("survival", 0, false); + + Potion.set("recovery", 0, false); + + assertEquals(Potion.get("survival"), 0); + + assertEquals(Potion.get("recovery"), 0); + + Potion.set("survival", 5, false); + + Potion.set("recovery", 5, false); + + assertEquals(Potion.get("survival"), 5); + + assertEquals(Potion.get("recovery"), 5); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + Potion.set("survival", 5, false); + + Potion.set("recovery", 5, false); + + assertEquals(Potion.get("survival"), 5); + + assertEquals(Potion.get("recovery"), 5); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + Potion.set("survival", 5, true); + + Potion.set("recovery", 5, true); + + assertEquals(Potion.get("survival"), 7); + + assertEquals(Potion.get("recovery"), 8); + } + + @Test + public void testUse() { + + Potion.set("survival", 0, false); + + Potion.set("recovery", 0, false); + + Potion.set("survival", 5, false); + + Potion.set("recovery", 5, false); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 2); + + assertEquals(Potion.get("recovery"), 3); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 0); + + assertEquals(Potion.get("recovery"), 0); + + Potion.use("survival"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 0); + + assertEquals(Potion.get("recovery"), 0); + } + + @Test + public void testUsed() { + + Potion.set("survival", 0, false); + + Potion.set("recovery", 0, false); + + Potion.set("survival", 5, false); + + Potion.set("recovery", 5, false); + + assertEquals(14, Potion.spUsed); + + assertEquals(11, Potion.rpUsed); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(17, Potion.spUsed); + + assertEquals(13, Potion.rpUsed); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(19, Potion.spUsed); + + assertEquals(16, Potion.rpUsed); + + Potion.use("survival"); + + Potion.use("recovery"); + + assertEquals(19, Potion.spUsed); + + assertEquals(16, Potion.rpUsed); + } + +} From e88a6ffe8ff810e6c8b756407401a761a4da66c6 Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 18 Oct 2021 21:44:36 -0700 Subject: [PATCH 02/10] Added break statement to separate potion incrementation --- src/com/hotmail/kalebmarc/textfighter/player/Potion.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Potion.java b/src/com/hotmail/kalebmarc/textfighter/player/Potion.java index fefe8a80..0678e336 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Potion.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Potion.java @@ -111,8 +111,10 @@ public static void used(String kind) { switch (kind.toLowerCase()) { case "survival": spUsed++; + break; case "recovery": rpUsed++; + break; } } From 23e6e6672c4d53ffdea361ed0242dd3107a9734c Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 18 Oct 2021 21:47:39 -0700 Subject: [PATCH 03/10] Separated print statements to view different potions and performed regression testing. --- src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java | 4 ---- src/com/hotmail/kalebmarc/textfighter/player/Stats.java | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java b/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java index 04f73ed8..1dba4853 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java @@ -38,10 +38,6 @@ public void setUp() throws Exception { sysInBackup = System.in; // backup System.in to restore it later in = new ByteArrayInputStream("\n\n\n\n\n\n\n\n\n\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n".getBytes()); System.setIn(in); - - Potion.spUsed = 0; - - Potion.rpUsed = 0; } @After diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Stats.java b/src/com/hotmail/kalebmarc/textfighter/player/Stats.java index c1385ab2..e9296957 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Stats.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Stats.java @@ -68,7 +68,9 @@ public static void view() { Ui.println(" Health - " + Health.getStr()); Ui.println(" Insta-Healths used - " + InstaHealth.used); Ui.println(" First-Aid kits used - " + FirstAid.used); - Ui.println(" Potions used - " + (Potion.spUsed + Potion.rpUsed)); + Ui.println(" Survival potions used - " + (Potion.spUsed)); + Ui.println(" Recovery potions used - " + (Potion.rpUsed)); + Ui.println(" Total potions used - " + (Potion.spUsed + Potion.rpUsed)); Ui.println(" Times Died - " + Health.timesDied); Ui.println(" Food items eaten - " + Food.totalEaten); Ui.println(); From 65d2bdf9e6ca64bba8a622e99ebd64c4e73116a9 Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 18 Oct 2021 22:02:04 -0700 Subject: [PATCH 04/10] Temporarily remove test for cleanliness and merge. --- .../textfighter/player/PotionTest.java | 235 ------------------ 1 file changed, 235 deletions(-) delete mode 100644 src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java diff --git a/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java b/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java deleted file mode 100644 index 1dba4853..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java +++ /dev/null @@ -1,235 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.player; - -import static org.junit.Assert.*; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.manipulation.Ordering.Context; - -public class PotionTest { - - static InputStream sysInBackup; - - static ByteArrayInputStream in; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - sysInBackup = System.in; // backup System.in to restore it later - in = new ByteArrayInputStream("\n".getBytes()); - System.setIn(in); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - System.setIn(sysInBackup); - } - - @Before - public void setUp() throws Exception { - sysInBackup = System.in; // backup System.in to restore it later - in = new ByteArrayInputStream("\n\n\n\n\n\n\n\n\n\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n".getBytes()); - System.setIn(in); - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void testGet() { - //fail("Not yet implemented"); - - assertEquals(Potion.get("survival"), 0); - - assertEquals(Potion.get("recovery"), 0); - - Potion.set("survival", 5, false); - - Potion.set("recovery", 5, false); - - assertEquals(Potion.get("survival"), 5); - - assertEquals(Potion.get("recovery"), 5); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 2); - - assertEquals(Potion.get("recovery"), 3); - } - - @Test - public void testSet() { - - Potion.set("survival", 0, false); - - Potion.set("recovery", 0, false); - - assertEquals(Potion.get("survival"), 0); - - assertEquals(Potion.get("recovery"), 0); - - Potion.set("survival", 5, false); - - Potion.set("recovery", 5, false); - - assertEquals(Potion.get("survival"), 5); - - assertEquals(Potion.get("recovery"), 5); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - Potion.set("survival", 5, false); - - Potion.set("recovery", 5, false); - - assertEquals(Potion.get("survival"), 5); - - assertEquals(Potion.get("recovery"), 5); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - Potion.set("survival", 5, true); - - Potion.set("recovery", 5, true); - - assertEquals(Potion.get("survival"), 7); - - assertEquals(Potion.get("recovery"), 8); - } - - @Test - public void testUse() { - - Potion.set("survival", 0, false); - - Potion.set("recovery", 0, false); - - Potion.set("survival", 5, false); - - Potion.set("recovery", 5, false); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 2); - - assertEquals(Potion.get("recovery"), 3); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 0); - - assertEquals(Potion.get("recovery"), 0); - - Potion.use("survival"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 0); - - assertEquals(Potion.get("recovery"), 0); - } - - @Test - public void testUsed() { - - Potion.set("survival", 0, false); - - Potion.set("recovery", 0, false); - - Potion.set("survival", 5, false); - - Potion.set("recovery", 5, false); - - assertEquals(14, Potion.spUsed); - - assertEquals(11, Potion.rpUsed); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(17, Potion.spUsed); - - assertEquals(13, Potion.rpUsed); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(19, Potion.spUsed); - - assertEquals(16, Potion.rpUsed); - - Potion.use("survival"); - - Potion.use("recovery"); - - assertEquals(19, Potion.spUsed); - - assertEquals(16, Potion.rpUsed); - } - -} From 4b6434d428528b7f2d217d2ac8a7c8c5a98381e9 Mon Sep 17 00:00:00 2001 From: Miranda Date: Tue, 19 Oct 2021 21:13:44 -0700 Subject: [PATCH 05/10] Updated health section of the Help menu --- .../kalebmarc/textfighter/main/Help.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Help.java b/src/com/hotmail/kalebmarc/textfighter/main/Help.java index 419689bf..401bebe9 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Help.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Help.java @@ -141,7 +141,30 @@ private static void info_health() { Ui.println("health up to 200. Each upgrade will cost 100 coins on easy, "); Ui.println("and 150 coins on hard; and it will upgrade your health by 10."); Ui.println("You will be able to upgrade once per level."); - //TODO Add more health info + Ui.println("Health deteriorates by fighting enemies."); + Ui.println("If your health reaches 0, you'll die and you will lose coins."); + Ui.println("The goal is to eliminate an enemy by reducing his health to 0."); + Ui.println("If an enemies health is 0 they will die."); + Ui.println("You'll receive XP points and gain coins if you kill an enemy."); + Ui.println("Potions are used to increase your health."); + Ui.println("You start the game with 2 Recovery and 2 Survival Potions."); + Ui.println("A Recovery Potion increases your health by 25%."); + Ui.println("A Survival Potion increases your health by 75%."); + Ui.println("You can purchase more potions at the shop once you've "); + Ui.println("completed level 2."); + Ui.println("First Aid Kits are used to increase your health."); + Ui.println("You start the game with 3 First Aid Kits."); + Ui.println("A First Aid Kit increases your health by 20 health points."); + Ui.println("You can purchase more First Aid Kits at the shop."); + Ui.println("Food is given to you at the beginning of the game."); + Ui.println("You can eat food to increase your health."); + Ui.println("If you eat all the food you cannot purchase more at the shop."); + Ui.println("InstaHealth can also restore your health."); + Ui.println("If you use an InstaHealth your health will fully recover."); + Ui.println("InstaHealth can be purchased at the shops after you have "); + Ui.println("reached level 3."); + Ui.println("The prices of the items you can purchase at the shop are "); + Ui.println("determined by which difficulty you are playing on. If you "); Ui.println("------------------------------------------------------------"); Ui.pause(); } From 5f09642406d7d83885600b1b2e77d164ce99e8ed Mon Sep 17 00:00:00 2001 From: Miranda Date: Wed, 20 Oct 2021 12:14:23 -0700 Subject: [PATCH 06/10] Removed trailing 'If you ' --- src/com/hotmail/kalebmarc/textfighter/main/Help.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Help.java b/src/com/hotmail/kalebmarc/textfighter/main/Help.java index 401bebe9..10d4e448 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Help.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Help.java @@ -164,7 +164,7 @@ private static void info_health() { Ui.println("InstaHealth can be purchased at the shops after you have "); Ui.println("reached level 3."); Ui.println("The prices of the items you can purchase at the shop are "); - Ui.println("determined by which difficulty you are playing on. If you "); + Ui.println("determined by which difficulty you are playing on."); Ui.println("------------------------------------------------------------"); Ui.pause(); } From dbb4ada6c50e79e20e4fba68a7ac4d80a0c7a1f3 Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 20 Oct 2021 20:33:56 -0700 Subject: [PATCH 07/10] Added tests for array and access modifier. --- .../textfighter/item/ArmourTest.java | 101 ++++++++++++ .../kalebmarc/textfighter/main/EnemyTest.java | 148 ++++++++++++++++++ .../kalebmarc/textfighter/main/FoodTest.java | 84 ++++++++++ .../textfighter/main/WeaponTest.java | 80 ++++++++++ 4 files changed, 413 insertions(+) create mode 100644 src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java create mode 100644 src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java create mode 100644 src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java create mode 100644 src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java diff --git a/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java b/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java new file mode 100644 index 00000000..c53ee0b3 --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java @@ -0,0 +1,101 @@ +package com.hotmail.kalebmarc.textfighter.item; + +import static org.junit.Assert.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import java.io.InputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Scanner; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; + +public class ArmourTest { + + static Armour none; + + static Armour basic; + + static Armour advanced; + + static InputStream sysInBackup; + + static ByteArrayInputStream in; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + none = new Armour("None", 0, 0, 1); + basic = new Armour("Basic", 400, 15, 5); + advanced = new Armour("Advanced", 750, 30, 7); + + none.setOwns(true); + + basic.setOwns(false); + + advanced.setOwns(true); + + Armour.set(0); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + + sysInBackup = System.in; // backup System.in to restore it later + } + + @After + public void tearDown() throws Exception { + + System.setIn(sysInBackup); + } + + @Test + public void testGetArmours() { + + assertEquals(3, Armour.getArmours().size()); + + assertEquals("None", Armour.getArmours().get(0).getName()); + assertEquals(0, Armour.getArmours().get(0).getPrice()); + assertEquals(0, Armour.getArmours().get(0).getDamResist()); + assertEquals(1, Armour.getArmours().get(0).getLevel()); + + assertEquals( "Basic", Armour.getArmours().get(1).getName()); + assertEquals(400, Armour.getArmours().get(1).getPrice()); + assertEquals(15, Armour.getArmours().get(1).getDamResist()); + assertEquals(5, Armour.getArmours().get(1).getLevel()); + + assertEquals("Advanced", Armour.getArmours().get(2).getName()); + assertEquals(750, Armour.getArmours().get(2).getPrice()); + assertEquals(30, Armour.getArmours().get(2).getDamResist()); + assertEquals(7, Armour.getArmours().get(2).getLevel()); + } + + @Test + public void testChoose() { + + assertEquals(0, Armour.get()); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("2".getBytes()); + + System.setIn(chooseIn); + + Armour.choose(); + + System.setIn(sysInBackup); + + assertEquals(2, Armour.get()); + } +} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java b/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java new file mode 100644 index 00000000..c65668c9 --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java @@ -0,0 +1,148 @@ +package com.hotmail.kalebmarc.textfighter.main; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Set; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.hotmail.kalebmarc.textfighter.player.Xp; + +public class EnemyTest { + + public static Enemy darkElf; + public static Enemy ninja; + public static Enemy giantSpider; + public static Enemy zombie; + public static Enemy goblin; + public static Enemy ghost; + public static Enemy barbarian; + public static Enemy giantAnt; + public static Enemy evilUnicorn; + public static Enemy ogre; + + static ArrayList allEnemies; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + darkElf = new Enemy("Dark Elf", 45, 10, 15, 10, 15, 15, 5, 100, true, false); + ninja = new Enemy("Ninja", 75, 5, 15, 5, 15, 15, 1, 10, true, false); + giantSpider = new Enemy("Giant Spider", 35, 5, 10, 5, 10, 10, 5, 100, true, false); + zombie = new Enemy("Zombie", 20, 5, 15, 5, 15, 15, 1, 10, true, false); + goblin = new Enemy("Goblin", 60, 10, 20, 10, 20, 20, 1, 10, true, false); + ghost = new Enemy("Ghost", 85, 15, 25, 15, 25, 25, 1, 100, true, false); + barbarian = new Enemy("Barbarian", 50, 5, 15, 5, 15, 15, 5, 100, true, false); + giantAnt = new Enemy("Giant Ant", 30, 5, 10, 5, 10, 10, 1, 10, true, false); + evilUnicorn = new Enemy("Evil Unicorn", 35, 30, 40, 5, 15, 20, 5, 100, true, false); + ogre = new Enemy("Ogre", 90, 20, 50, 10, 30, 50, 5, 100, true, false); + + allEnemies = new ArrayList<>(); + + allEnemies.add(darkElf); + allEnemies.add(ninja); + allEnemies.add(giantSpider); + allEnemies.add(ghost); + allEnemies.add(barbarian); + allEnemies.add(giantAnt); + allEnemies.add(evilUnicorn); + allEnemies.add(ogre); + + Xp.setLevel(1); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testGet() { + + Xp.setLevel(1); + + Enemy.encounterNew(); + + assertTrue(Enemy.get() instanceof Enemy); + + ArrayList suitableEnemies = new ArrayList(); + + suitableEnemies.add(ninja); + suitableEnemies.add(zombie); + suitableEnemies.add(goblin); + suitableEnemies.add(ghost); + suitableEnemies.add(giantAnt); + + assertTrue(suitableEnemies.contains(Enemy.get())); + + Xp.setLevel(15); + + suitableEnemies = new ArrayList(); + + suitableEnemies.add(darkElf); + suitableEnemies.add(giantSpider); + suitableEnemies.add(ghost); + suitableEnemies.add(barbarian); + suitableEnemies.add(evilUnicorn); + suitableEnemies.add(ogre); + + Enemy.encounterNew(); + + assertTrue(Enemy.get() instanceof Enemy); + + assertTrue(suitableEnemies.contains(Enemy.get())); + } + + @Test + public void testFindEnemy() { + + Xp.setLevel(1); + + Enemy.findEnemy(); + + assertTrue(Enemy.get() instanceof Enemy); + + ArrayList suitableEnemies = new ArrayList(); + + suitableEnemies.add(ninja); + suitableEnemies.add(zombie); + suitableEnemies.add(goblin); + suitableEnemies.add(ghost); + suitableEnemies.add(giantAnt); + + assertTrue(suitableEnemies.contains(Enemy.get())); + + Xp.setLevel(15); + + suitableEnemies = new ArrayList(); + + suitableEnemies.add(darkElf); + suitableEnemies.add(giantSpider); + suitableEnemies.add(ghost); + suitableEnemies.add(barbarian); + suitableEnemies.add(evilUnicorn); + suitableEnemies.add(ogre); + + Enemy.findEnemy(); + + assertTrue(Enemy.get() instanceof Enemy); + + assertTrue(suitableEnemies.contains(Enemy.get())); + } + + @Test + public void testGetEnemies() { + fail("Not yet implemented"); + } +} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java b/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java new file mode 100644 index 00000000..a3f41d3e --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java @@ -0,0 +1,84 @@ +package com.hotmail.kalebmarc.textfighter.main; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.when; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.hotmail.kalebmarc.textfighter.player.Health; + + +/*import org.easymock.EasyMock; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(Food.class)*/ +public class FoodTest { + + static InputStream sysInBackup; + + public static Food apple; + public static Food orange; + public static Food dragonfruit; + public static Food meat; + public static Food mushroom; + public static Food fish; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + apple = new Food("Apple", "A boring 'ol apple.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); + orange = new Food("Orange", "Sort of like an apple, but orange.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); + dragonfruit = new Food("Dragon Fruit", "Unfortunately, not a real dragon.", StatusEffect.type.HEALTH, Food.type.FRUIT, 10); + meat = new Food("Chunk of meat", "Probably not rotten.", StatusEffect.type.HEALTH, Food.type.MEAT_OTHER, 15); + mushroom = new Food("Mushroom", "The good kind!", StatusEffect.type.HEALTH, Food.type.OTHER, 5); + fish = new Food("Fish", "Found in rivers and lakes.", StatusEffect.type.HEALTH, Food.type.MEAT_FISH, 15); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + + sysInBackup = System.in; // backup System.in to restore it later + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testList() { + Health.set(50, 100); + + //PowerMockito.mockStatic(Ui.class); + //when(Ui.getValidInt()).thenReturn(1); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("1".getBytes()); + + System.setIn(chooseIn); + + Food.list(); + + System.setIn(sysInBackup); + + assertEquals(Health.get(), 55); + } + + @Test + public void testGetFoods() { + fail("Not yet implemented"); + } +} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java b/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java new file mode 100644 index 00000000..c3509ddf --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java @@ -0,0 +1,80 @@ +package com.hotmail.kalebmarc.textfighter.main; + +import static org.junit.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class WeaponTest { + + static InputStream sysInBackup; + + static Weapon fists; + static Weapon baseballBat; + static Weapon knife; + static Weapon pipe; + //Guns: + static Weapon pistol; + static Weapon smg; + static Weapon shotgun; + static Weapon rifle; + static Weapon sniper; + + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + fists = new Weapon("Fists", true, false, 0, 0, 5, 10, true, false); + baseballBat = new Weapon("Baseball Bat", false, true, 120, 1, 10, 15, true, false); + knife = new Weapon("Knife", false, true, 125, 2, 10, 20, true, false); + pipe = new Weapon("Pipe", false, false, 0, 0, 5, 20, true, false); + //Guns: + pistol = new Weapon("Pistol", 1, 18, true, 250, 1, 4, 15, 1.5, 3, 4, true, false); + smg = new Weapon("Smg", 10, 75, true, 700, 1, 10, 75, 2.5, 4, 6, true, false); + shotgun = new Weapon("Shotgun", 1, 12, true, 375, 2, 9, 60, 2, 5, 7, true, false); + rifle = new Weapon("Rifle", 1, 18, true, 275, 1, 5, 10, 1.25, 6, 7, true, false); + sniper = new Weapon("Sniper", 1, 10, true, 700, 2, 7, 0, 1, 7, 10, true, false); + + Weapon.arrayWeapon.get(1).owns = true; + Weapon.arrayWeapon.get(4).owns = true; + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + sysInBackup = System.in; // backup System.in to restore it later + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testChoose() { + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("3".getBytes()); + + System.setIn(chooseIn); + + Weapon.choose(); + + System.setIn(sysInBackup); + + assertEquals("Pistol", Weapon.get().getName()); + } + + @Test + public void testGetWeapons() { + fail("Not yet implemented"); + } +} From 689be51b6928c5aba8e30cdd29e9b525e3708298 Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 20 Oct 2021 21:07:26 -0700 Subject: [PATCH 08/10] Added implementation to change array access modifiers. --- .../kalebmarc/textfighter/item/Chest.java | 16 ++++---- .../kalebmarc/textfighter/main/Cheats.java | 28 +++++++------- .../kalebmarc/textfighter/main/Debug.java | 14 +++---- .../kalebmarc/textfighter/main/Enemy.java | 11 ++++-- .../kalebmarc/textfighter/main/Food.java | 19 ++++++---- .../kalebmarc/textfighter/main/Help.java | 38 +++++++++---------- .../kalebmarc/textfighter/main/Saves.java | 34 ++++++++--------- .../kalebmarc/textfighter/main/Shop.java | 26 ++++++------- .../kalebmarc/textfighter/main/Weapon.java | 19 ++++++---- 9 files changed, 110 insertions(+), 95 deletions(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/item/Chest.java b/src/com/hotmail/kalebmarc/textfighter/item/Chest.java index 41e6687f..92a46770 100644 --- a/src/com/hotmail/kalebmarc/textfighter/item/Chest.java +++ b/src/com/hotmail/kalebmarc/textfighter/item/Chest.java @@ -23,11 +23,11 @@ public static void view() { Ui.println(" Recovery: " + Potion.get("recovery")); Ui.println("Coins: " + Coins.get()); Ui.println("POWERS: " + Power.get()); - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { - if (Weapon.arrayWeapon.get(i).owns()) { - Ui.println(Weapon.arrayWeapon.get(i).getName()); - if (!Weapon.arrayWeapon.get(i).melee) - Ui.println(" (Ammo: " + Weapon.arrayWeapon.get(i).getAmmo() + ")"); + for (int i = 0; i < Weapon.getWeapons().size(); i++) { + if (Weapon.getWeapons().get(i).owns()) { + Ui.println(Weapon.getWeapons().get(i).getName()); + if (!Weapon.getWeapons().get(i).melee) + Ui.println(" (Ammo: " + Weapon.getWeapons().get(i).getAmmo() + ")"); } } for (int i = 1; i < Armour.getArmours().size(); i++) { @@ -35,9 +35,9 @@ public static void view() { Ui.println(Armour.getArmours().get(i).toString()); } } - for (int i = 0; i < Food.arrayFood.size(); i++) { - if (Food.arrayFood.get(i).getQuantity() > 0) - Ui.println(Food.arrayFood.get(i).getName() + "(x" + Food.arrayFood.get(i).getQuantity() + ")"); + for (int i = 0; i < Food.getFoods().size(); i++) { + if (Food.getFoods().get(i).getQuantity() > 0) + Ui.println(Food.getFoods().get(i).getName() + "(x" + Food.getFoods().get(i).getQuantity() + ")"); } Ui.println(); Ui.println("------------------------------"); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java b/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java index 4ecdb042..5af1425c 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java @@ -44,27 +44,27 @@ private static void cheatSelect() { Coins.set(5000, false); FirstAid.set(5000, false); InstaHealth.set(5000, false); - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { - Weapon.arrayWeapon.get(i).setAmmo(5000, false); + for (int i = 0; i < Weapon.getWeapons().size(); i++) { + Weapon.getWeapons().get(i).setAmmo(5000, false); } Power.set(5000, false); - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { - Weapon.arrayWeapon.get(i).owns = true; + for (int i = 0; i < Weapon.getWeapons().size(); i++) { + Weapon.getWeapons().get(i).owns = true; } Stats.timesCheated++; - for (int i = 0; i < Food.arrayFood.size(); i++) - Food.arrayFood.get(i).setQuantity(5000); + for (int i = 0; i < Food.getFoods().size(); i++) + Food.getFoods().get(i).setQuantity(5000); Potion.set("Survival", 5000, false); Potion.set("Recovery", 5000, false); break; case "weaponstash": - for (int i = 0; i <= Weapon.arrayWeapon.size(); i++) { - Weapon.arrayWeapon.get(i).setAmmo(5000, false); + for (int i = 0; i <= Weapon.getWeapons().size(); i++) { + Weapon.getWeapons().get(i).setAmmo(5000, false); } Power.set(5000, false); - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { - Weapon.arrayWeapon.get(i).owns = true; + for (int i = 0; i < Weapon.getWeapons().size(); i++) { + Weapon.getWeapons().get(i).owns = true; } Stats.timesCheated++; break; @@ -73,8 +73,8 @@ private static void cheatSelect() { InstaHealth.set(500, false); Potion.set("Survival", 500, false); Potion.set("Recovery", 500, false); - for (int i = 0; i < Food.arrayFood.size(); i++) - Food.arrayFood.get(i).setQuantity(100); + for (int i = 0; i < Food.getFoods().size(); i++) + Food.getFoods().get(i).setQuantity(100); Stats.timesCheated++; break; case "healme": @@ -103,8 +103,8 @@ private static void cheatSelect() { Stats.timesCheated++; break; case "thirstforfood": - for (int i = 0; i < Food.arrayFood.size(); i++) - Food.arrayFood.get(i).setQuantity(10); + for (int i = 0; i < Food.getFoods().size(); i++) + Food.getFoods().get(i).setQuantity(10); Stats.timesCheated++; break; diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Debug.java b/src/com/hotmail/kalebmarc/textfighter/main/Debug.java index 48b0e98e..5520c30f 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Debug.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Debug.java @@ -56,12 +56,12 @@ public static void menu() { Xp.set(Ui.getValidInt(), false); break; case 3: - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { - Weapon.arrayWeapon.get(i).owns = true; + for (int i = 0; i < Weapon.getWeapons().size(); i++) { + Weapon.getWeapons().get(i).owns = true; } Power.set(100, true); - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { - Weapon.arrayWeapon.get(i).setAmmo(10000, false); + for (int i = 0; i < Weapon.getWeapons().size(); i++) { + Weapon.getWeapons().get(i).setAmmo(10000, false); } Ui.println("You now have all weapons"); Ui.pause(); @@ -84,10 +84,10 @@ public static void menu() { break; case 8: Ui.cls(); - for (int i = 0; i < Food.arrayFood.size(); i++) { - Ui.println(i + ") " + Food.arrayFood.get(i).getName()); + for (int i = 0; i < Food.getFoods().size(); i++) { + Ui.println(i + ") " + Food.getFoods().get(i).getName()); } - Food.arrayFood.get(Ui.getValidInt()).setQuantity(10); + Food.getFoods().get(Ui.getValidInt()).setQuantity(10); break; case 9: return; diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java b/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java index adb16e21..5b280d9d 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java @@ -1,5 +1,6 @@ package com.hotmail.kalebmarc.textfighter.main; +import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.player.*; import javax.swing.*; @@ -72,6 +73,10 @@ public static void set(int i) { current = arrayEnemy.get(i); } + public static ArrayList getEnemies() { + return arrayEnemy; + } + public static Enemy get() { return current; } @@ -84,9 +89,9 @@ public static void findEnemy() { int playerLevel = Xp.getLevel(); ArrayList suitableEnemies = new ArrayList<>(); - for (int i = 0; i < arrayEnemy.size(); i++) { - if (arrayEnemy.get(i).levelMin <= playerLevel && playerLevel <= arrayEnemy.get(i).levelMax) { - suitableEnemies.add(arrayEnemy.get(i)); + for (int i = 0; i < getEnemies().size(); i++) { + if (getEnemies().get(i).levelMin <= playerLevel && playerLevel <= getEnemies().get(i).levelMax) { + suitableEnemies.add(getEnemies().get(i)); } } current = suitableEnemies.get(Random.RInt(0, suitableEnemies.size() -1)); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Food.java b/src/com/hotmail/kalebmarc/textfighter/main/Food.java index 927b9d9b..aac8f2fa 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Food.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Food.java @@ -1,5 +1,6 @@ package com.hotmail.kalebmarc.textfighter.main; +import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.player.Health; import java.util.ArrayList; @@ -32,10 +33,10 @@ public static void list() { while (true) { Ui.cls(); int j = 0; - int[] offset = new int[arrayFood.size()]; - for (int i = 0; i < arrayFood.size(); i++) { - if (arrayFood.get(i).quantity > 0) { - Ui.println((j + 1) + ") " + arrayFood.get(i).getName() + "(" + arrayFood.get(i).quantity + ")"); + int[] offset = new int[getFoods().size()]; + for (int i = 0; i < getFoods().size(); i++) { + if (getFoods().get(i).quantity > 0) { + Ui.println((j + 1) + ") " + getFoods().get(i).getName() + "(" + getFoods().get(i).quantity + ")"); offset[j] = i - j; j++; } @@ -57,14 +58,14 @@ public static void list() { //TODO once more status effects are implemented, use a switch here if appropriate. //Testing to make sure the option is valid goes here: - if (arrayFood.get(menuItem).getStatusEffect() == StatusEffect.type.HEALTH && Health.get() == Health.getOutOf()) { + if (getFoods().get(menuItem).getStatusEffect() == StatusEffect.type.HEALTH && Health.get() == Health.getOutOf()) { Ui.msg("Your health is already full. No need to eat this!"); return; } //Results go here: - if (arrayFood.get(menuItem).quantity > 0) { - Food.arrayFood.get(menuItem).eat(); + if (getFoods().get(menuItem).quantity > 0) { + Food.getFoods().get(menuItem).eat(); } return; @@ -76,6 +77,10 @@ public static void list() { } } + public static ArrayList getFoods() { + return arrayFood; + } + public String getName() { return this.name; } diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Help.java b/src/com/hotmail/kalebmarc/textfighter/main/Help.java index 419689bf..46d2b7c3 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Help.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Help.java @@ -63,18 +63,18 @@ private static void info_enemy() { Ui.println(" ENEMY INFO "); Ui.println("Which enemy would you like to know about?"); Ui.println(); - for (int i = 0; i < Enemy.arrayEnemy.size(); i++) { - Ui.println((i + 1) + ") " + Enemy.arrayEnemy.get(i).getName()); + for (int i = 0; i < Enemy.getEnemies().size(); i++) { + Ui.println((i + 1) + ") " + Enemy.getEnemies().get(i).getName()); } - Ui.println((Enemy.arrayEnemy.size() + 1) + ") Back"); + Ui.println((Enemy.getEnemies().size() + 1) + ") Back"); Ui.println("------------------------------------------------------------"); int menuItem = Ui.getValidInt(); try { - Enemy.arrayEnemy.get(menuItem - 1).viewAbout(); + Enemy.getEnemies().get(menuItem - 1).viewAbout(); } catch (Exception e) { - if (menuItem == (Enemy.arrayEnemy.size() + 1)) return; + if (menuItem == (Enemy.getEnemies().size() + 1)) return; Ui.println(menuItem + " is not an option."); Ui.pause(); } @@ -115,18 +115,18 @@ private static void info_weapons() { Ui.println(" WEAPON INFO "); Ui.println("Which weapon would you like to know about?"); Ui.println(); - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { - Ui.println((i + 1) + ") " + Weapon.arrayWeapon.get(i).getName()); + for (int i = 0; i < Weapon.getWeapons().size(); i++) { + Ui.println((i + 1) + ") " + Weapon.getWeapons().get(i).getName()); } - Ui.println((Weapon.arrayWeapon.size() + 1) + ") Back"); + Ui.println((Weapon.getWeapons().size() + 1) + ") Back"); Ui.println("------------------------------------------------------------"); int menuItem = Ui.getValidInt(); try { - Weapon.arrayWeapon.get(menuItem - 1).viewAbout(); + Weapon.getWeapons().get(menuItem - 1).viewAbout(); } catch (Exception e) { - if (menuItem == (Weapon.arrayWeapon.size() + 1)) return; + if (menuItem == (Weapon.getWeapons().size() + 1)) return; Ui.println(menuItem + " is not an option."); Ui.pause(); } @@ -153,18 +153,18 @@ private static void info_food() { Ui.println(" FOOD INFO "); Ui.println("Which food would you like to know about?"); Ui.println(); - for (int i = 0; i < Food.arrayFood.size(); i++) { - Ui.println((i + 1) + ") " + Food.arrayFood.get(i).getName()); + for (int i = 0; i < Food.getFoods().size(); i++) { + Ui.println((i + 1) + ") " + Food.getFoods().get(i).getName()); } - Ui.println((Food.arrayFood.size() + 1) + ") Back"); + Ui.println((Food.getFoods().size() + 1) + ") Back"); Ui.println("------------------------------------------------------------"); int menuItem = Ui.getValidInt(); try { - Food.arrayFood.get(menuItem - 1).viewAbout(); + Food.getFoods().get(menuItem - 1).viewAbout(); } catch (Exception e) { - if (menuItem == (Food.arrayFood.size() + 1)) return; + if (menuItem == (Food.getFoods().size() + 1)) return; Ui.println(menuItem + " is not an option."); Ui.pause(); } @@ -243,10 +243,10 @@ private static void info_achs() { Ui.println(" Enemy Slayer | Kill a total of 100 enemies"); Ui.println(" First Kill | Kill one enemy"); Ui.println(" Time For An Upgrade | Buy any weapon from the shop"); - for (int i = 0; i < Enemy.arrayEnemy.size(); i++) { - Ui.print(" Goodbye, " + Enemy.arrayEnemy.get(i).getName()); - for (int x = 0; x < (14 - Enemy.arrayEnemy.get(i).getName().length()); x++) Ui.print(" "); - Ui.println("| Kill a " + Enemy.arrayEnemy.get(i).getName()); + for (int i = 0; i < Enemy.getEnemies().size(); i++) { + Ui.print(" Goodbye, " + Enemy.getEnemies().get(i).getName()); + for (int x = 0; x < (14 - Enemy.getEnemies().get(i).getName().length()); x++) Ui.print(" "); + Ui.println("| Kill a " + Enemy.getEnemies().get(i).getName()); } Ui.println(" Text-Fighter Master | Get all other achievements"); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Saves.java b/src/com/hotmail/kalebmarc/textfighter/main/Saves.java index e9179079..189e2860 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Saves.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Saves.java @@ -91,16 +91,16 @@ public static void save() { set("Stats.Kills", Stats.kills); set("Stats.Total_Kills", Stats.totalKills); set("Stats.High_Score", Stats.highScore); - set("User.Weapons.Current", Weapon.arrayWeapon.indexOf(Weapon.get())); + set("User.Weapons.Current", Weapon.getWeapons().indexOf(Weapon.get())); - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { - if (Weapon.arrayWeapon.get(i).owns()) { + for (int i = 0; i < Weapon.getWeapons().size(); i++) { + if (Weapon.getWeapons().get(i).owns()) { set(("User.Weapons." + i), true); } else { set(("User.Weapons." + i), false); } - set(("User.Weapons.Ammo." + i), Weapon.arrayWeapon.get(i).getAmmo()); + set(("User.Weapons.Ammo." + i), Weapon.getWeapons().get(i).getAmmo()); } @@ -120,7 +120,7 @@ public static void save() { set("User.Armour.Current", Armour.get()); //Enemy - set("Battle.Current.Enemy", Enemy.arrayEnemy.indexOf(Enemy.get())); + set("Battle.Current.Enemy", Enemy.getEnemies().indexOf(Enemy.get())); set("Battle.Current.Enemy_Health", Enemy.get().getHealth()); set("Battle.Current.Enemy_Max_Health", Enemy.get().getHealthMax()); set("Battle.Current.Enemy_First_Aid_Kit", Enemy.get().getFirstAidKit()); @@ -133,9 +133,9 @@ public static void save() { List enemiesKilled = new ArrayList<>(); - for (int i = 0; i < Enemy.arrayEnemy.size(); i++) + for (int i = 0; i < Enemy.getEnemies().size(); i++) if (Achievements.arrayKilled.get(i)) - enemiesKilled.add(Enemy.arrayEnemy.get(i).getName()); + enemiesKilled.add(Enemy.getEnemies().get(i).getName()); set("Achievements.Enemies_Killed", enemiesKilled); set("Achievements.Text_Fighter_Master", Achievements.textFighterMaster); set("Achievements.YAY_POWER", Achievements.YAYPOWER); @@ -249,11 +249,11 @@ public static boolean load() { Stats.totalKills = getInteger("Stats.Total_Kills"); Weapon.set(getInteger("User.Weapons.Current")); - for(int i = 0; i < Weapon.arrayWeapon.size(); i++){ + for(int i = 0; i < Weapon.getWeapons().size(); i++){ if (getBoolean("User.Weapons." + i)){ - Weapon.arrayWeapon.get(i).owns = true; + Weapon.getWeapons().get(i).owns = true; } - Weapon.arrayWeapon.get(i).setAmmo(getInteger("User.Weapons.Ammo." + i), false); + Weapon.getWeapons().get(i).setAmmo(getInteger("User.Weapons.Ammo." + i), false); } Power.set(getInteger("User.Power"), false); @@ -283,8 +283,8 @@ public static boolean load() { List achSet = (List) getList("Achievements.Enemies_Killed"); for (int i = 0; i < achSet.size(); i++){ - for (int x = 0; x < Enemy.arrayEnemy.size(); x++){ - if(Enemy.arrayEnemy.get(x).getName().equals(achSet.get(i))){ + for (int x = 0; x < Enemy.getEnemies().size(); x++){ + if(Enemy.getEnemies().get(x).getName().equals(achSet.get(i))){ Achievements.arrayKilled.set(x, true); } } @@ -457,10 +457,10 @@ public static boolean convert() { Stats.highScore = readInt(); Stats.totalKills = readInt(); Weapon.set(readInt()); - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) - Weapon.arrayWeapon.get(i).owns = readBoolean(); - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) - Weapon.arrayWeapon.get(i).setAmmo(readInt(), false); + for (int i = 0; i < Weapon.getWeapons().size(); i++) + Weapon.getWeapons().get(i).owns = readBoolean(); + for (int i = 0; i < Weapon.getWeapons().size(); i++) + Weapon.getWeapons().get(i).setAmmo(readInt(), false); Power.set(readInt(), false); Power.used = readInt(); Stats.totalDamageDealt = readInt(); @@ -479,7 +479,7 @@ public static boolean convert() { Achievements.enemySlayer = readBoolean(); Achievements.firstKill = readBoolean(); Achievements.timeForAnUpgrade = readBoolean(); - for (int i = 0; i < Enemy.arrayEnemy.size(); i++) + for (int i = 0; i < Enemy.getEnemies().size(); i++) Achievements.arrayKilled.set(i, readBoolean()); Achievements.textFighterMaster = readBoolean(); Achievements.YAYPOWER = readBoolean(); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Shop.java b/src/com/hotmail/kalebmarc/textfighter/main/Shop.java index cc6f295b..7528bcc1 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Shop.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Shop.java @@ -132,12 +132,12 @@ private static void weapons() { Ui.println(); Ui.println("-------------------------------------------------------------------"); int j = 0; - int[] offset = new int[Weapon.arrayWeapon.size()]; - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { - if (Weapon.arrayWeapon.get(i).isBuyable()) { - Ui.println((j + 1) + ") " + Weapon.arrayWeapon.get(i).getName()); - Ui.println(" Price: " + Weapon.arrayWeapon.get(i).price); - Ui.println(" Level: " + Weapon.arrayWeapon.get(i).level); + int[] offset = new int[Weapon.getWeapons().size()]; + for (int i = 0; i < Weapon.getWeapons().size(); i++) { + if (Weapon.getWeapons().get(i).isBuyable()) { + Ui.println((j + 1) + ") " + Weapon.getWeapons().get(i).getName()); + Ui.println(" Price: " + Weapon.getWeapons().get(i).price); + Ui.println(" Level: " + Weapon.getWeapons().get(i).level); offset[j] = i - j; j++; Ui.println(); @@ -170,7 +170,7 @@ private static void weapons() { menuItem = menuItem + offset[menuItem]; //Results go here: - Weapon.arrayWeapon.get(menuItem).buy(); + Weapon.getWeapons().get(menuItem).buy(); return; } catch (Exception e) { @@ -255,12 +255,12 @@ private static void buyAmmo() { Ui.println(); Ui.println("-------------------------------------------------------------------"); ArrayList validWeapons = new ArrayList(); - for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { - if (Weapon.arrayWeapon.get(i).isBuyable() && !Weapon.arrayWeapon.get(i).melee && Weapon.arrayWeapon.get(i).owns()) { - Ui.println((validWeapons.size() + 1) + ") " + Weapon.arrayWeapon.get(i).getName()); - Ui.println(" Price: " + Weapon.arrayWeapon.get(i).getAmmoPrice()); - Ui.println(" Level: " + Weapon.arrayWeapon.get(i).level); - validWeapons.add(Weapon.arrayWeapon.get(i)); + for (int i = 0; i < Weapon.getWeapons().size(); i++) { + if (Weapon.getWeapons().get(i).isBuyable() && !Weapon.getWeapons().get(i).melee && Weapon.getWeapons().get(i).owns()) { + Ui.println((validWeapons.size() + 1) + ") " + Weapon.getWeapons().get(i).getName()); + Ui.println(" Price: " + Weapon.getWeapons().get(i).getAmmoPrice()); + Ui.println(" Level: " + Weapon.getWeapons().get(i).level); + validWeapons.add(Weapon.getWeapons().get(i)); } } Ui.println((validWeapons.size() + 1) + ") Back"); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java index 48a2e615..ba4fc51d 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java @@ -1,5 +1,6 @@ package com.hotmail.kalebmarc.textfighter.main; +import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.player.Achievements; import com.hotmail.kalebmarc.textfighter.player.Coins; import com.hotmail.kalebmarc.textfighter.player.Stats; @@ -91,6 +92,10 @@ public Weapon(String name, boolean startingWeapon, boolean buyable, int price, i } } + public static ArrayList getWeapons() { + return arrayWeapon; + } + public static Weapon get() { return current; } @@ -117,10 +122,10 @@ public static void choose() { Ui.println("Equipped weapon: " + current.getName()); Ui.println("----------------------------"); int j = 0; - int[] offset = new int[arrayWeapon.size()]; - for (int i = 0; i < arrayWeapon.size(); i++) { - if (arrayWeapon.get(i).owns()) { - Ui.println((j + 1) + ") " + arrayWeapon.get(i).getName()); + int[] offset = new int[getWeapons().size()]; + for (int i = 0; i < getWeapons().size(); i++) { + if (getWeapons().get(i).owns()) { + Ui.println((j + 1) + ") " + getWeapons().get(i).getName()); offset[j] = i - j; j++; } @@ -142,13 +147,13 @@ public static void choose() { menuItem = menuItem + offset[menuItem]; //Testing to make sure the option is valid goes here: - if (!arrayWeapon.get(menuItem).owns) { + if (!getWeapons().get(menuItem).owns) { Ui.msg("You do not own this weapon!"); return; } - current = arrayWeapon.get(menuItem); - Ui.msg("You have equipped a " + arrayWeapon.get(menuItem).getName()); + current = getWeapons().get(menuItem); + Ui.msg("You have equipped a " + getWeapons().get(menuItem).getName()); return; } catch (Exception e) { From af111f3eab744568bfe9e6d319dc724f590543a2 Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 20 Oct 2021 21:18:33 -0700 Subject: [PATCH 09/10] Performed regression testing with new functionality. --- .../kalebmarc/textfighter/main/EnemyTest.java | 12 +++++++++++- .../hotmail/kalebmarc/textfighter/main/FoodTest.java | 8 +++++++- .../kalebmarc/textfighter/main/WeaponTest.java | 11 ++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java b/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java index c65668c9..d6b5e737 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java @@ -143,6 +143,16 @@ public void testFindEnemy() { @Test public void testGetEnemies() { - fail("Not yet implemented"); + assertEquals(Enemy.arrayEnemy, Enemy.getEnemies()); + assertEquals(Enemy.arrayEnemy.get(0), Enemy.getEnemies().get(0)); + assertEquals(Enemy.arrayEnemy.get(1), Enemy.getEnemies().get(1)); + assertEquals(Enemy.arrayEnemy.get(2), Enemy.getEnemies().get(2)); + assertEquals(Enemy.arrayEnemy.get(3), Enemy.getEnemies().get(3)); + assertEquals(Enemy.arrayEnemy.get(4), Enemy.getEnemies().get(4)); + assertEquals(Enemy.arrayEnemy.get(5), Enemy.getEnemies().get(5)); + assertEquals(Enemy.arrayEnemy.get(6), Enemy.getEnemies().get(6)); + assertEquals(Enemy.arrayEnemy.get(7), Enemy.getEnemies().get(7)); + assertEquals(Enemy.arrayEnemy.get(8), Enemy.getEnemies().get(8)); + assertEquals(Enemy.arrayEnemy.get(9), Enemy.getEnemies().get(9)); } } diff --git a/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java b/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java index a3f41d3e..d496d96b 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java @@ -79,6 +79,12 @@ public void testList() { @Test public void testGetFoods() { - fail("Not yet implemented"); + assertEquals(Food.arrayFood, Food.getFoods()); + assertEquals(Food.arrayFood.get(0), Food.getFoods().get(0)); + assertEquals(Food.arrayFood.get(1), Food.getFoods().get(1)); + assertEquals(Food.arrayFood.get(2), Food.getFoods().get(2)); + assertEquals(Food.arrayFood.get(3), Food.getFoods().get(3)); + assertEquals(Food.arrayFood.get(4), Food.getFoods().get(4)); + assertEquals(Food.arrayFood.get(5), Food.getFoods().get(5)); } } diff --git a/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java b/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java index c3509ddf..cf8d3f09 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java @@ -75,6 +75,15 @@ public void testChoose() { @Test public void testGetWeapons() { - fail("Not yet implemented"); + assertEquals(Weapon.arrayWeapon, Weapon.getWeapons()); + assertEquals(Weapon.arrayWeapon.get(0), Weapon.getWeapons().get(0)); + assertEquals(Weapon.arrayWeapon.get(1), Weapon.getWeapons().get(1)); + assertEquals(Weapon.arrayWeapon.get(2), Weapon.getWeapons().get(2)); + assertEquals(Weapon.arrayWeapon.get(3), Weapon.getWeapons().get(3)); + assertEquals(Weapon.arrayWeapon.get(4), Weapon.getWeapons().get(4)); + assertEquals(Weapon.arrayWeapon.get(5), Weapon.getWeapons().get(5)); + assertEquals(Weapon.arrayWeapon.get(6), Weapon.getWeapons().get(6)); + assertEquals(Weapon.arrayWeapon.get(7), Weapon.getWeapons().get(7)); + assertEquals(Weapon.arrayWeapon.get(8), Weapon.getWeapons().get(8)); } } From a70ddb8cfd06281c7bdeb7e89a7a04d750f2e099 Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 20 Oct 2021 21:25:40 -0700 Subject: [PATCH 10/10] Temporarily remove tests for cleanliness and merge. --- .../textfighter/item/ArmourTest.java | 101 ----------- .../kalebmarc/textfighter/main/EnemyTest.java | 158 ------------------ .../kalebmarc/textfighter/main/FoodTest.java | 90 ---------- .../textfighter/main/WeaponTest.java | 89 ---------- 4 files changed, 438 deletions(-) delete mode 100644 src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java delete mode 100644 src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java delete mode 100644 src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java delete mode 100644 src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java diff --git a/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java b/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java deleted file mode 100644 index c53ee0b3..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.item; - -import static org.junit.Assert.*; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import java.io.InputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Scanner; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; - -public class ArmourTest { - - static Armour none; - - static Armour basic; - - static Armour advanced; - - static InputStream sysInBackup; - - static ByteArrayInputStream in; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - none = new Armour("None", 0, 0, 1); - basic = new Armour("Basic", 400, 15, 5); - advanced = new Armour("Advanced", 750, 30, 7); - - none.setOwns(true); - - basic.setOwns(false); - - advanced.setOwns(true); - - Armour.set(0); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - - sysInBackup = System.in; // backup System.in to restore it later - } - - @After - public void tearDown() throws Exception { - - System.setIn(sysInBackup); - } - - @Test - public void testGetArmours() { - - assertEquals(3, Armour.getArmours().size()); - - assertEquals("None", Armour.getArmours().get(0).getName()); - assertEquals(0, Armour.getArmours().get(0).getPrice()); - assertEquals(0, Armour.getArmours().get(0).getDamResist()); - assertEquals(1, Armour.getArmours().get(0).getLevel()); - - assertEquals( "Basic", Armour.getArmours().get(1).getName()); - assertEquals(400, Armour.getArmours().get(1).getPrice()); - assertEquals(15, Armour.getArmours().get(1).getDamResist()); - assertEquals(5, Armour.getArmours().get(1).getLevel()); - - assertEquals("Advanced", Armour.getArmours().get(2).getName()); - assertEquals(750, Armour.getArmours().get(2).getPrice()); - assertEquals(30, Armour.getArmours().get(2).getDamResist()); - assertEquals(7, Armour.getArmours().get(2).getLevel()); - } - - @Test - public void testChoose() { - - assertEquals(0, Armour.get()); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("2".getBytes()); - - System.setIn(chooseIn); - - Armour.choose(); - - System.setIn(sysInBackup); - - assertEquals(2, Armour.get()); - } -} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java b/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java deleted file mode 100644 index d6b5e737..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.main; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Set; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.hotmail.kalebmarc.textfighter.player.Xp; - -public class EnemyTest { - - public static Enemy darkElf; - public static Enemy ninja; - public static Enemy giantSpider; - public static Enemy zombie; - public static Enemy goblin; - public static Enemy ghost; - public static Enemy barbarian; - public static Enemy giantAnt; - public static Enemy evilUnicorn; - public static Enemy ogre; - - static ArrayList allEnemies; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - darkElf = new Enemy("Dark Elf", 45, 10, 15, 10, 15, 15, 5, 100, true, false); - ninja = new Enemy("Ninja", 75, 5, 15, 5, 15, 15, 1, 10, true, false); - giantSpider = new Enemy("Giant Spider", 35, 5, 10, 5, 10, 10, 5, 100, true, false); - zombie = new Enemy("Zombie", 20, 5, 15, 5, 15, 15, 1, 10, true, false); - goblin = new Enemy("Goblin", 60, 10, 20, 10, 20, 20, 1, 10, true, false); - ghost = new Enemy("Ghost", 85, 15, 25, 15, 25, 25, 1, 100, true, false); - barbarian = new Enemy("Barbarian", 50, 5, 15, 5, 15, 15, 5, 100, true, false); - giantAnt = new Enemy("Giant Ant", 30, 5, 10, 5, 10, 10, 1, 10, true, false); - evilUnicorn = new Enemy("Evil Unicorn", 35, 30, 40, 5, 15, 20, 5, 100, true, false); - ogre = new Enemy("Ogre", 90, 20, 50, 10, 30, 50, 5, 100, true, false); - - allEnemies = new ArrayList<>(); - - allEnemies.add(darkElf); - allEnemies.add(ninja); - allEnemies.add(giantSpider); - allEnemies.add(ghost); - allEnemies.add(barbarian); - allEnemies.add(giantAnt); - allEnemies.add(evilUnicorn); - allEnemies.add(ogre); - - Xp.setLevel(1); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testGet() { - - Xp.setLevel(1); - - Enemy.encounterNew(); - - assertTrue(Enemy.get() instanceof Enemy); - - ArrayList suitableEnemies = new ArrayList(); - - suitableEnemies.add(ninja); - suitableEnemies.add(zombie); - suitableEnemies.add(goblin); - suitableEnemies.add(ghost); - suitableEnemies.add(giantAnt); - - assertTrue(suitableEnemies.contains(Enemy.get())); - - Xp.setLevel(15); - - suitableEnemies = new ArrayList(); - - suitableEnemies.add(darkElf); - suitableEnemies.add(giantSpider); - suitableEnemies.add(ghost); - suitableEnemies.add(barbarian); - suitableEnemies.add(evilUnicorn); - suitableEnemies.add(ogre); - - Enemy.encounterNew(); - - assertTrue(Enemy.get() instanceof Enemy); - - assertTrue(suitableEnemies.contains(Enemy.get())); - } - - @Test - public void testFindEnemy() { - - Xp.setLevel(1); - - Enemy.findEnemy(); - - assertTrue(Enemy.get() instanceof Enemy); - - ArrayList suitableEnemies = new ArrayList(); - - suitableEnemies.add(ninja); - suitableEnemies.add(zombie); - suitableEnemies.add(goblin); - suitableEnemies.add(ghost); - suitableEnemies.add(giantAnt); - - assertTrue(suitableEnemies.contains(Enemy.get())); - - Xp.setLevel(15); - - suitableEnemies = new ArrayList(); - - suitableEnemies.add(darkElf); - suitableEnemies.add(giantSpider); - suitableEnemies.add(ghost); - suitableEnemies.add(barbarian); - suitableEnemies.add(evilUnicorn); - suitableEnemies.add(ogre); - - Enemy.findEnemy(); - - assertTrue(Enemy.get() instanceof Enemy); - - assertTrue(suitableEnemies.contains(Enemy.get())); - } - - @Test - public void testGetEnemies() { - assertEquals(Enemy.arrayEnemy, Enemy.getEnemies()); - assertEquals(Enemy.arrayEnemy.get(0), Enemy.getEnemies().get(0)); - assertEquals(Enemy.arrayEnemy.get(1), Enemy.getEnemies().get(1)); - assertEquals(Enemy.arrayEnemy.get(2), Enemy.getEnemies().get(2)); - assertEquals(Enemy.arrayEnemy.get(3), Enemy.getEnemies().get(3)); - assertEquals(Enemy.arrayEnemy.get(4), Enemy.getEnemies().get(4)); - assertEquals(Enemy.arrayEnemy.get(5), Enemy.getEnemies().get(5)); - assertEquals(Enemy.arrayEnemy.get(6), Enemy.getEnemies().get(6)); - assertEquals(Enemy.arrayEnemy.get(7), Enemy.getEnemies().get(7)); - assertEquals(Enemy.arrayEnemy.get(8), Enemy.getEnemies().get(8)); - assertEquals(Enemy.arrayEnemy.get(9), Enemy.getEnemies().get(9)); - } -} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java b/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java deleted file mode 100644 index d496d96b..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.main; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.when; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.hotmail.kalebmarc.textfighter.player.Health; - - -/*import org.easymock.EasyMock; -import org.junit.runner.RunWith; -import org.powermock.api.easymock.PowerMock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(Food.class)*/ -public class FoodTest { - - static InputStream sysInBackup; - - public static Food apple; - public static Food orange; - public static Food dragonfruit; - public static Food meat; - public static Food mushroom; - public static Food fish; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - apple = new Food("Apple", "A boring 'ol apple.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); - orange = new Food("Orange", "Sort of like an apple, but orange.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); - dragonfruit = new Food("Dragon Fruit", "Unfortunately, not a real dragon.", StatusEffect.type.HEALTH, Food.type.FRUIT, 10); - meat = new Food("Chunk of meat", "Probably not rotten.", StatusEffect.type.HEALTH, Food.type.MEAT_OTHER, 15); - mushroom = new Food("Mushroom", "The good kind!", StatusEffect.type.HEALTH, Food.type.OTHER, 5); - fish = new Food("Fish", "Found in rivers and lakes.", StatusEffect.type.HEALTH, Food.type.MEAT_FISH, 15); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - - sysInBackup = System.in; // backup System.in to restore it later - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testList() { - Health.set(50, 100); - - //PowerMockito.mockStatic(Ui.class); - //when(Ui.getValidInt()).thenReturn(1); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("1".getBytes()); - - System.setIn(chooseIn); - - Food.list(); - - System.setIn(sysInBackup); - - assertEquals(Health.get(), 55); - } - - @Test - public void testGetFoods() { - assertEquals(Food.arrayFood, Food.getFoods()); - assertEquals(Food.arrayFood.get(0), Food.getFoods().get(0)); - assertEquals(Food.arrayFood.get(1), Food.getFoods().get(1)); - assertEquals(Food.arrayFood.get(2), Food.getFoods().get(2)); - assertEquals(Food.arrayFood.get(3), Food.getFoods().get(3)); - assertEquals(Food.arrayFood.get(4), Food.getFoods().get(4)); - assertEquals(Food.arrayFood.get(5), Food.getFoods().get(5)); - } -} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java b/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java deleted file mode 100644 index cf8d3f09..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.main; - -import static org.junit.Assert.*; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class WeaponTest { - - static InputStream sysInBackup; - - static Weapon fists; - static Weapon baseballBat; - static Weapon knife; - static Weapon pipe; - //Guns: - static Weapon pistol; - static Weapon smg; - static Weapon shotgun; - static Weapon rifle; - static Weapon sniper; - - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - fists = new Weapon("Fists", true, false, 0, 0, 5, 10, true, false); - baseballBat = new Weapon("Baseball Bat", false, true, 120, 1, 10, 15, true, false); - knife = new Weapon("Knife", false, true, 125, 2, 10, 20, true, false); - pipe = new Weapon("Pipe", false, false, 0, 0, 5, 20, true, false); - //Guns: - pistol = new Weapon("Pistol", 1, 18, true, 250, 1, 4, 15, 1.5, 3, 4, true, false); - smg = new Weapon("Smg", 10, 75, true, 700, 1, 10, 75, 2.5, 4, 6, true, false); - shotgun = new Weapon("Shotgun", 1, 12, true, 375, 2, 9, 60, 2, 5, 7, true, false); - rifle = new Weapon("Rifle", 1, 18, true, 275, 1, 5, 10, 1.25, 6, 7, true, false); - sniper = new Weapon("Sniper", 1, 10, true, 700, 2, 7, 0, 1, 7, 10, true, false); - - Weapon.arrayWeapon.get(1).owns = true; - Weapon.arrayWeapon.get(4).owns = true; - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - sysInBackup = System.in; // backup System.in to restore it later - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testChoose() { - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("3".getBytes()); - - System.setIn(chooseIn); - - Weapon.choose(); - - System.setIn(sysInBackup); - - assertEquals("Pistol", Weapon.get().getName()); - } - - @Test - public void testGetWeapons() { - assertEquals(Weapon.arrayWeapon, Weapon.getWeapons()); - assertEquals(Weapon.arrayWeapon.get(0), Weapon.getWeapons().get(0)); - assertEquals(Weapon.arrayWeapon.get(1), Weapon.getWeapons().get(1)); - assertEquals(Weapon.arrayWeapon.get(2), Weapon.getWeapons().get(2)); - assertEquals(Weapon.arrayWeapon.get(3), Weapon.getWeapons().get(3)); - assertEquals(Weapon.arrayWeapon.get(4), Weapon.getWeapons().get(4)); - assertEquals(Weapon.arrayWeapon.get(5), Weapon.getWeapons().get(5)); - assertEquals(Weapon.arrayWeapon.get(6), Weapon.getWeapons().get(6)); - assertEquals(Weapon.arrayWeapon.get(7), Weapon.getWeapons().get(7)); - assertEquals(Weapon.arrayWeapon.get(8), Weapon.getWeapons().get(8)); - } -}