From e8b001ec7e498a5e5bdcdbb69d9a30cc5d3a5d31 Mon Sep 17 00:00:00 2001 From: R1ndT Date: Tue, 21 Dec 2021 08:19:48 +0100 Subject: [PATCH 1/7] Organised imports, removed test classes, added build.gradle to .gitignore --- .gitignore | 1 + build.gradle | 55 --- gradlew | 0 .../textfighter/casino/BlackjackGame.java | 8 +- .../kalebmarc/textfighter/item/Armour.java | 4 +- .../textfighter/item/ArmourTest.java | 196 ---------- .../kalebmarc/textfighter/main/About.java | 2 +- .../kalebmarc/textfighter/main/Cheats.java | 11 +- .../textfighter/main/CheatsTest.java | 156 -------- .../kalebmarc/textfighter/main/DebugTest.java | 160 -------- .../kalebmarc/textfighter/main/Enemy.java | 13 +- .../kalebmarc/textfighter/main/EnemyTest.java | 343 ------------------ .../kalebmarc/textfighter/main/Food.java | 5 +- .../kalebmarc/textfighter/main/FoodTest.java | 119 ------ .../kalebmarc/textfighter/main/Game.java | 27 +- .../kalebmarc/textfighter/main/Handle.java | 2 +- .../kalebmarc/textfighter/main/Help.java | 1 - .../kalebmarc/textfighter/main/HelpTest.java | 24 -- .../kalebmarc/textfighter/main/Quest.java | 4 +- .../kalebmarc/textfighter/main/Saves.java | 34 +- .../kalebmarc/textfighter/main/Shop.java | 4 +- .../kalebmarc/textfighter/main/Ui.java | 3 +- .../kalebmarc/textfighter/main/Weapon.java | 10 +- .../textfighter/main/WeaponTest.java | 284 --------------- .../textfighter/player/Achievements.java | 7 +- .../kalebmarc/textfighter/player/Health.java | 7 +- .../textfighter/player/HealthTest.java | 19 - .../textfighter/player/PotionTest.java | 325 ----------------- .../textfighter/player/Settings.java | 7 +- .../kalebmarc/textfighter/player/Stats.java | 7 +- .../kalebmarc/textfighter/player/Xp.java | 4 +- src/tests/TestGameClock.java | 71 ---- src/time/GameClock.java | 5 - 33 files changed, 108 insertions(+), 1810 deletions(-) delete mode 100644 build.gradle mode change 100755 => 100644 gradlew delete mode 100644 src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java delete mode 100644 src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java delete mode 100644 src/com/hotmail/kalebmarc/textfighter/main/DebugTest.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/HelpTest.java delete mode 100644 src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java delete mode 100644 src/com/hotmail/kalebmarc/textfighter/player/HealthTest.java delete mode 100644 src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java delete mode 100644 src/tests/TestGameClock.java diff --git a/.gitignore b/.gitignore index b1d42b78..1a3b87f7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ Text-Fighter.iml .gradle build gradle +build.gradle # Mobile Tools for Java (J2ME) .mtj.tmp/ diff --git a/build.gradle b/build.gradle deleted file mode 100644 index f2844a08..00000000 --- a/build.gradle +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This build file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java project to get you started. - * For more details take a look at the Java Quickstart chapter in the Gradle - * user guide available at https://docs.gradle.org/4.1/userguide/tutorial_java_projects.html - */ - -// Apply the java plugin to add support for Java -// Apply the application plugin to add support for building an application -plugins { - id 'java' - id 'application' -} - -// In this section you declare where to find the dependencies of your project -repositories { - // Use jcenter for resolving your dependencies. - // You can declare any Maven/Ivy/file repository here. - jcenter() -} - -dependencies { - // This dependency is found on compile classpath of this component and consumers. - implementation 'com.google.guava:guava:22.0' - implementation 'org.yaml:snakeyaml:1.19' - // Use JUnit test framework - testImplementation 'junit:junit:4.12' -} - -// Define the main class for the application - -sourceSets { - main { - java { - srcDirs 'src' - } - } -} - -mainClassName = 'com.hotmail.kalebmarc.textfighter.main.Start' - -// Makes the compiled jar file executable -jar{ - manifest{ - attributes( - "Main-Class": mainClassName - ) - } -} - -// Resolves the input problem during Gradle run -run{ - standardInput = System.in -} diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 diff --git a/src/com/hotmail/kalebmarc/textfighter/casino/BlackjackGame.java b/src/com/hotmail/kalebmarc/textfighter/casino/BlackjackGame.java index f45cf7da..e201d396 100644 --- a/src/com/hotmail/kalebmarc/textfighter/casino/BlackjackGame.java +++ b/src/com/hotmail/kalebmarc/textfighter/casino/BlackjackGame.java @@ -1,10 +1,14 @@ package com.hotmail.kalebmarc.textfighter.casino; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Stack; + import com.hotmail.kalebmarc.textfighter.main.Ui; import com.hotmail.kalebmarc.textfighter.player.Coins; -import java.util.*; - public class BlackjackGame extends BasicCasinoGame { private Stack cardStack; diff --git a/src/com/hotmail/kalebmarc/textfighter/item/Armour.java b/src/com/hotmail/kalebmarc/textfighter/item/Armour.java index 58e582cc..abac2e27 100644 --- a/src/com/hotmail/kalebmarc/textfighter/item/Armour.java +++ b/src/com/hotmail/kalebmarc/textfighter/item/Armour.java @@ -1,13 +1,13 @@ package com.hotmail.kalebmarc.textfighter.item; +import java.util.ArrayList; + import com.hotmail.kalebmarc.textfighter.main.Handle; import com.hotmail.kalebmarc.textfighter.main.NPC; import com.hotmail.kalebmarc.textfighter.main.Ui; import com.hotmail.kalebmarc.textfighter.player.Coins; import com.hotmail.kalebmarc.textfighter.player.Xp; -import java.util.ArrayList; - public class Armour { private static ArrayList armours = new ArrayList<>(3); 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 5cf1a839..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java +++ /dev/null @@ -1,196 +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 { - - sysInBackup = System.in; - - 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(false); - - Armour.set(0); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - - System.setIn(sysInBackup); - } - - @Before - public void setUp() throws Exception { - - System.setIn(sysInBackup); - - none.setOwns(true); - - basic.setOwns(false); - - advanced.setOwns(false); - - Armour.set(0); - } - - @After - public void tearDown() throws Exception { - - System.setIn(sysInBackup); - } - - @Test - public void testChooseOnly() { - // Select armour when only one type is owned - - // Check that no armour is equipped yet - assertEquals(0, Armour.get()); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("1".getBytes()); // Set input stream to pick armour automatically - - System.setIn(chooseIn); - - Armour.choose(); // Pick armour to equip - - System.setIn(sysInBackup); - - assertEquals(0, Armour.get()); // Check that correct armour was equipped - - assertEquals(none, Armour.getEquipped()); // Check for correct armour object equipped - } - - @Test - public void testChooseFirst() { - // Select armour when only all three types are owned - - none.setOwns(true); - - basic.setOwns(true); - - advanced.setOwns(true); - - // Check that no armour is equipped yet - assertEquals(0, Armour.get()); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("1".getBytes()); // Set input stream to pick armour automatically - - System.setIn(chooseIn); - - Armour.choose(); // Pick armour to equip - - System.setIn(sysInBackup); - - assertEquals(0, Armour.get()); // Check that correct armour was equipped - - assertEquals(none, Armour.getEquipped()); // Check for correct armour object equipped - } - - @Test - public void testChooseMiddle() { - - none.setOwns(true); - - basic.setOwns(true); - - advanced.setOwns(true); - - // Check that no armour is equipped yet - assertEquals(0, Armour.get()); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("2".getBytes()); // Set input stream to pick armour automatically - - System.setIn(chooseIn); - - Armour.choose(); // Pick armour to equip - - System.setIn(sysInBackup); - - assertEquals(1, Armour.get()); // Check that correct armour was equipped - - assertEquals(basic, Armour.getEquipped()); // Check for correct armour object equipped - } - - @Test - public void testChooseLast() { - - none.setOwns(true); - - basic.setOwns(true); - - advanced.setOwns(true); - - // Check that no armour is equipped yet - assertEquals(0, Armour.get()); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("3".getBytes()); // Set input stream to pick armour automatically - - System.setIn(chooseIn); - - Armour.choose(); // Pick armour to equip - - System.setIn(sysInBackup); - - assertEquals(2, Armour.get()); // Check that correct armour was equipped - - assertEquals(advanced, Armour.getEquipped()); // Check for correct armour object equipped - } - - @Test - public void testGetArmours() { - // Test constant armours array access - - assertEquals(3, Armour.getArmours().size()); - - // Check all objects are the same in each list access method - 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()); - } -} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/About.java b/src/com/hotmail/kalebmarc/textfighter/main/About.java index 8ce41103..073ad5a6 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/About.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/About.java @@ -1,6 +1,6 @@ package com.hotmail.kalebmarc.textfighter.main; -import javax.swing.*; +import javax.swing.JOptionPane; class About { private static boolean viewed = false; diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java b/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java index 44bc108d..da50b04a 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java @@ -1,11 +1,16 @@ package com.hotmail.kalebmarc.textfighter.main; +import java.util.Scanner; + import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; import com.hotmail.kalebmarc.textfighter.item.Power; -import com.hotmail.kalebmarc.textfighter.player.*; - -import java.util.Scanner; +import com.hotmail.kalebmarc.textfighter.player.Coins; +import com.hotmail.kalebmarc.textfighter.player.Health; +import com.hotmail.kalebmarc.textfighter.player.Potion; +import com.hotmail.kalebmarc.textfighter.player.Settings; +import com.hotmail.kalebmarc.textfighter.player.Stats; +import com.hotmail.kalebmarc.textfighter.player.Xp; public class Cheats { diff --git a/src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java b/src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java deleted file mode 100644 index 593267f3..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.main; - -import static org.junit.Assert.*; - -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; - -public class CheatsTest { - - 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; - - 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 { - Cheats.enable(); - - sysInBackup = System.in; // backup System.in to restore it later - - 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); - - 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 { - - System.setIn(sysInBackup); - } - - @Before - public void setUp() throws Exception { - - System.setIn(sysInBackup); - } - - @After - public void tearDown() throws Exception { - - System.setIn(sysInBackup); - } - - @Test - public void testCheatGatewaygivemeitall() { - - Ui.print("Type 'givemeitall' to test"); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("givemeitall".getBytes()); // Set input stream to pick cheat automatically - - System.setIn(chooseIn); - - Cheats.cheatGateway(); - - System.setIn(sysInBackup); - - // Ensure that cheat updated food counts - assertEquals(5000, Food.arrayFood.get(0).getQuantity()); - assertEquals(5000, Food.arrayFood.get(1).getQuantity()); - assertEquals(5000, Food.arrayFood.get(2).getQuantity()); - assertEquals(5000, Food.arrayFood.get(3).getQuantity()); - assertEquals(5000, Food.arrayFood.get(4).getQuantity()); - assertEquals(5000, Food.arrayFood.get(5).getQuantity()); - - // Ensure that cheat updated weapon counts - assertTrue(Weapon.arrayWeapon.get(0).owns); - assertTrue(Weapon.arrayWeapon.get(1).owns); - assertTrue(Weapon.arrayWeapon.get(2).owns); - assertTrue(Weapon.arrayWeapon.get(3).owns); - assertTrue(Weapon.arrayWeapon.get(4).owns); - assertTrue(Weapon.arrayWeapon.get(5).owns); - assertTrue(Weapon.arrayWeapon.get(6).owns); - assertTrue(Weapon.arrayWeapon.get(7).owns); - assertTrue(Weapon.arrayWeapon.get(8).owns); - } - - @Test - public void testCheatGatewayweaponstash() { - - Ui.print("Type 'weaponstash' to test"); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("weaponstash".getBytes()); // Set input stream to pick cheat automatically - - System.setIn(chooseIn); - - Cheats.cheatGateway(); - - System.setIn(sysInBackup); - - // Ensure that cheat updated weapon ammo counts - assertEquals(5000, Weapon.arrayWeapon.get(4).getAmmo()); - assertEquals(5000, Weapon.arrayWeapon.get(5).getAmmo()); - assertEquals(5000, Weapon.arrayWeapon.get(6).getAmmo()); - assertEquals(5000, Weapon.arrayWeapon.get(7).getAmmo()); - assertEquals(5000, Weapon.arrayWeapon.get(8).getAmmo()); - } - - @Test - public void testCheatGatewaythirstforfood() { - - Ui.print("Type 'thirstforfood' to test"); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("thirstforfood".getBytes()); // Set input stream to pick cheat automatically - - System.setIn(chooseIn); - - Cheats.cheatGateway(); - - System.setIn(sysInBackup); - - // Ensure that cheat updated food counts - assertEquals(10, Food.arrayFood.get(0).getQuantity()); - assertEquals(10, Food.arrayFood.get(1).getQuantity()); - assertEquals(10, Food.arrayFood.get(2).getQuantity()); - assertEquals(10, Food.arrayFood.get(3).getQuantity()); - assertEquals(10, Food.arrayFood.get(4).getQuantity()); - assertEquals(10, Food.arrayFood.get(5).getQuantity()); - } diff --git a/src/com/hotmail/kalebmarc/textfighter/main/DebugTest.java b/src/com/hotmail/kalebmarc/textfighter/main/DebugTest.java deleted file mode 100644 index ee5307ed..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/main/DebugTest.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.main; - -import static org.junit.Assert.*; - -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; - -public class DebugTest { - - 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; - - 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 { - - Debug.enable(); - - sysInBackup = System.in; // backup System.in to restore it later - - 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); - - 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 { - - System.setIn(sysInBackup); - } - - @Before - public void setUp() throws Exception { - - System.setIn(sysInBackup); - } - - @After - public void tearDown() throws Exception { - - System.setIn(sysInBackup); - } - - @Test - public void testMenuWeapon() { - - Ui.print("Enter '3' followed by '9' to test"); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("3".getBytes()); // Set input stream to pick cheat automatically - - System.setIn(chooseIn); - - Debug.menu(); - - System.setIn(sysInBackup); - - // Ensure that debug updated weapon counts - assertTrue(Weapon.arrayWeapon.get(0).owns); - assertTrue(Weapon.arrayWeapon.get(1).owns); - assertTrue(Weapon.arrayWeapon.get(2).owns); - assertTrue(Weapon.arrayWeapon.get(3).owns); - assertTrue(Weapon.arrayWeapon.get(4).owns); - assertTrue(Weapon.arrayWeapon.get(5).owns); - assertTrue(Weapon.arrayWeapon.get(6).owns); - assertTrue(Weapon.arrayWeapon.get(7).owns); - assertTrue(Weapon.arrayWeapon.get(8).owns); - - assertTrue(Weapon.getWeapons().get(0).owns); - assertTrue(Weapon.getWeapons().get(1).owns); - assertTrue(Weapon.getWeapons().get(2).owns); - assertTrue(Weapon.getWeapons().get(3).owns); - assertTrue(Weapon.getWeapons().get(4).owns); - assertTrue(Weapon.getWeapons().get(5).owns); - assertTrue(Weapon.getWeapons().get(6).owns); - assertTrue(Weapon.getWeapons().get(7).owns); - assertTrue(Weapon.getWeapons().get(8).owns); - - // Ensure that debug updated weapon ammo counts - assertEquals(10000, Weapon.arrayWeapon.get(4).getAmmo()); - assertEquals(10000, Weapon.arrayWeapon.get(5).getAmmo()); - assertEquals(10000, Weapon.arrayWeapon.get(6).getAmmo()); - assertEquals(10000, Weapon.arrayWeapon.get(7).getAmmo()); - assertEquals(10000, Weapon.arrayWeapon.get(8).getAmmo()); - - assertEquals(10000, Weapon.getWeapons().get(4).getAmmo()); - assertEquals(10000, Weapon.getWeapons().get(5).getAmmo()); - assertEquals(10000, Weapon.getWeapons().get(6).getAmmo()); - assertEquals(10000, Weapon.getWeapons().get(7).getAmmo()); - assertEquals(10000, Weapon.getWeapons().get(8).getAmmo()); - } - - @Test - public void testMenuFood() { - - Ui.print("Enter '8' followed by the numbers '0' through '5' five times, then finally '9' to test"); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("8".getBytes()); // Set input stream to pick cheat automatically - - System.setIn(chooseIn); - - Debug.menu(); - - System.setIn(sysInBackup); - - // Ensure that cheat updated food counts - assertEquals(10, Food.arrayFood.get(0).getQuantity()); - assertEquals(10, Food.arrayFood.get(1).getQuantity()); - assertEquals(10, Food.arrayFood.get(2).getQuantity()); - assertEquals(10, Food.arrayFood.get(3).getQuantity()); - assertEquals(10, Food.arrayFood.get(4).getQuantity()); - assertEquals(10, Food.arrayFood.get(5).getQuantity()); - - assertEquals(10, Food.getFoods().get(0).getQuantity()); - assertEquals(10, Food.getFoods().get(1).getQuantity()); - assertEquals(10, Food.getFoods().get(2).getQuantity()); - assertEquals(10, Food.getFoods().get(3).getQuantity()); - assertEquals(10, Food.getFoods().get(4).getQuantity()); - assertEquals(10, Food.getFoods().get(5).getQuantity()); - } - -} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java b/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java index 5b280d9d..9ae53d74 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java @@ -1,11 +1,16 @@ package com.hotmail.kalebmarc.textfighter.main; -import com.hotmail.kalebmarc.textfighter.item.Armour; -import com.hotmail.kalebmarc.textfighter.player.*; - -import javax.swing.*; import java.util.ArrayList; +import javax.swing.JOptionPane; + +import com.hotmail.kalebmarc.textfighter.player.Achievements; +import com.hotmail.kalebmarc.textfighter.player.Coins; +import com.hotmail.kalebmarc.textfighter.player.Health; +import com.hotmail.kalebmarc.textfighter.player.Potion; +import com.hotmail.kalebmarc.textfighter.player.Stats; +import com.hotmail.kalebmarc.textfighter.player.Xp; + public class Enemy { //constants 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 e402d5a3..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java +++ /dev/null @@ -1,343 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.main; - -import static org.junit.Assert.*; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -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 { - - 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; - - 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 { - - System.setIn(sysInBackup); - - 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(Weapon.getIndex(baseballBat)).owns = true; - Weapon.arrayWeapon.get(Weapon.getIndex(pistol)).owns = true; - Weapon.arrayWeapon.get(Weapon.getIndex(pistol)).setAmmo(4, true); - - darkElf = new Enemy("Dark Elf", 45, 10, 15, 10, 15, 15, 5, 99, 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, 99, 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, 99, true, false); - barbarian = new Enemy("Barbarian", 50, 5, 15, 5, 15, 15, 5, 99, 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, 99, true, false); - ogre = new Enemy("Ogre", 90, 20, 50, 10, 30, 50, 5, 99, true, false); - - allEnemies = new ArrayList<>(); - - allEnemies.add(darkElf); - allEnemies.add(ninja); - allEnemies.add(giantSpider); - allEnemies.add(zombie); - allEnemies.add(ghost); - allEnemies.add(barbarian); - allEnemies.add(giantAnt); - allEnemies.add(evilUnicorn); - allEnemies.add(ogre); - - Xp.setLevel(1); - - Weapon.BULLET_DAMAGE = 10; - - Weapon.BULLET_CRITICAL_MULTIPLIER = 10; - Weapon.BULLET_CRITICAL_CHANCE = 0.001; - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - - System.setIn(sysInBackup); - } - - @Before - public void setUp() throws Exception { - - System.setIn(sysInBackup); - } - - @After - public void tearDown() throws Exception { - - System.setIn(sysInBackup); - } - - @Test - public void testDie() { - // The enemies used in this test have health high enough that only a critical hit will kill them - // Tests are formed as such to verify that critical hits affect the enemies health correctly - - int startHealth; - int endHealth; - int lost; - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("\n".getBytes()); // Initialize a stream to move past user input - - System.setIn(chooseIn); - - Enemy.encounterNew(); // Get a new enemy to fight - - String previousEnemy = Enemy.get().getName(); // Record this enemy to check for enemy death later - - startHealth = Enemy.get().getHealth(); - - Weapon.set(4); - - do - { - Weapon.get().dealDam(); // Loop until user doesn't miss - - endHealth = Enemy.get().getHealth(); - - lost = startHealth - endHealth; - - } while (lost == 0); - - String nextEnemy = Enemy.get().getName(); // Record this enemy to check for enemy death later - - assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 0) || (nextEnemy != previousEnemy) || (Enemy.get().getHealth() == 20)); // Enemy should have lost a certain amount of health based on weapon, or died - - startHealth = Enemy.get().getHealth(); - - do - { - Weapon.get().dealDam(); // Loop until user doesn't miss - - endHealth = Enemy.get().getHealth(); - - lost = startHealth - endHealth; - - } while (lost == 0); - - String lastEnemy = Enemy.get().getName(); // Record this enemy to check for enemy death later - - assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 0) || (lastEnemy != nextEnemy) || (Enemy.get().getHealth() == 20)); // Enemy should have lost a certain amount of health based on weapon, or died - } - - @Test - public void testSet() { - - Xp.setLevel(1); // Set player level to set suitable enemies - - Enemy.set(1); // Set a new enemy to fight - - assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was set without error - - assertEquals(ninja.getName(), Enemy.get().getName()); // Ensure that correct enemy was set - - Xp.setLevel(15); // Set player level to set suitable enemies - - Enemy.set(0); // Set a new enemy to fight - - assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was set without error - - assertEquals(darkElf.getName(), Enemy.get().getName()); // Ensure that correct enemy was set - - Enemy getTestEnemy = new Enemy("getTestEnemy", 90, 20, 50, 10, 30, 50, 50, 100, true, false); - - Xp.setLevel(100); // Set player level to set suitable enemies - - Enemy.set(10); // Set a new enemy to fight - - assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was set without error - - assertEquals(getTestEnemy.getName(), Enemy.get().getName()); // Ensure that correct enemy was set - } - - @Test - public void testGet() { - - Xp.setLevel(1); // Set player level to find suitable enemies - - Enemy.encounterNew(); // Encounter a new enemy to fight - - assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error - - ArrayList suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemies - - suitableEnemies.add(ninja); - suitableEnemies.add(zombie); - suitableEnemies.add(goblin); - suitableEnemies.add(ghost); - suitableEnemies.add(giantAnt); - - assertTrue(suitableEnemies.contains(Enemy.get())); // Ensure that get returns a valid enemy that was encountered - - Xp.setLevel(15); // Set player level to find suitable enemies - - suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemies - - suitableEnemies.add(darkElf); - suitableEnemies.add(giantSpider); - suitableEnemies.add(ghost); - suitableEnemies.add(barbarian); - suitableEnemies.add(evilUnicorn); - suitableEnemies.add(ogre); - - Enemy.encounterNew(); // Encounter a new enemy to fight - - assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error - - assertTrue(suitableEnemies.contains(Enemy.get())); // Ensure that get returns a valid enemy that was encountered - - Enemy getTestEnemy = new Enemy("getTestEnemy", 90, 20, 50, 10, 30, 50, 50, 100, true, false); - - Xp.setLevel(100); // Set player level to find suitable enemies - - Enemy.encounterNew(); // Encounter a new enemy to fight - - assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error - - assertEquals(getTestEnemy.getName(), Enemy.get().getName()); // Ensure that get returns specific enemy (only valid enemy) - } - - @Test - public void testGetIndex() { - - Xp.setLevel(1); // Set player level to find suitable enemies - - Enemy.encounterNew(); // Encounter a new enemy to fight - - ArrayList suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemy indeces - - suitableEnemies.add(1); - suitableEnemies.add(3); - suitableEnemies.add(4); - suitableEnemies.add(5); - suitableEnemies.add(7); - - assertTrue(suitableEnemies.contains(Enemy.getIndex(Enemy.get()))); // Ensure that get returns a valid enemy that was encountered - - Xp.setLevel(15); // Set player level to find suitable enemies - - suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemy indeces - - suitableEnemies.add(0); - suitableEnemies.add(2); - suitableEnemies.add(4); - suitableEnemies.add(6); - suitableEnemies.add(8); - suitableEnemies.add(9); - - Enemy.encounterNew(); // Encounter a new enemy to fight - - assertTrue(suitableEnemies.contains(Enemy.getIndex(Enemy.get()))); // Ensure that get returns a valid enemy that was encountered - - Enemy getTestEnemy = new Enemy("getTestEnemy", 90, 20, 50, 10, 30, 50, 50, 100, true, false); - - Xp.setLevel(100); // Set player level to find suitable enemies - - Enemy.encounterNew(); // Encounter a new enemy to fight - - assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error - - assertEquals(10, Enemy.getIndex(Enemy.get())); // Ensure that get returns specific enemy (only valid enemy) - } - - @Test - public void testFindEnemy() { - - Xp.setLevel(1); // Set player level to find suitable enemies - - Enemy.findEnemy(); // Find a new enemy to fight - - assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error - - ArrayList suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemies - - suitableEnemies.add(ninja); - suitableEnemies.add(zombie); - suitableEnemies.add(goblin); - suitableEnemies.add(ghost); - suitableEnemies.add(giantAnt); - - assertTrue(suitableEnemies.contains(Enemy.get())); // Ensure that valid enemy was found - - Xp.setLevel(15); // Set player level to find suitable enemies - - suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemies - - suitableEnemies.add(darkElf); - suitableEnemies.add(giantSpider); - suitableEnemies.add(ghost); - suitableEnemies.add(barbarian); - suitableEnemies.add(evilUnicorn); - suitableEnemies.add(ogre); - - Enemy.findEnemy(); // Find a new enemy to fight - - assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error - - assertTrue(suitableEnemies.contains(Enemy.get())); // Ensure that valid enemy was found - } - - @Test - public void testGetEnemies() { - // Test constant enemies array access - - assertEquals(Enemy.arrayEnemy.size(), Enemy.getEnemies().size()); - - assertEquals(Enemy.arrayEnemy, Enemy.getEnemies()); - - // Check all objects are the same in each list access method - 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/Food.java b/src/com/hotmail/kalebmarc/textfighter/main/Food.java index aac8f2fa..b5f58683 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Food.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Food.java @@ -1,10 +1,9 @@ package com.hotmail.kalebmarc.textfighter.main; -import com.hotmail.kalebmarc.textfighter.item.Armour; -import com.hotmail.kalebmarc.textfighter.player.Health; - import java.util.ArrayList; +import com.hotmail.kalebmarc.textfighter.player.Health; + public class Food { //Food List 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 4033129f..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.main; - -import static org.junit.Assert.assertEquals; - -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; - -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 { - - sysInBackup = System.in; // backup System.in to restore it later - - 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 { - - System.setIn(sysInBackup); - } - - @Before - public void setUp() throws Exception { - - System.setIn(sysInBackup); - } - - @After - public void tearDown() throws Exception { - - System.setIn(sysInBackup); - } - - @Test - public void testListChooseFirst() { - Health.set(50, 100); // Set player health to make food eating visible - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("1".getBytes()); // Set input stream to pick food automatically - - System.setIn(chooseIn); - - Food.list(); // Eat a food - - System.setIn(sysInBackup); - - assertEquals(Health.get(), 55); // Check that player health was updated - } - - @Test - public void testListChooseMiddle() { - Health.set(50, 100); // Set player health to make food eating visible - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("3".getBytes()); // Set input stream to pick food automatically - - System.setIn(chooseIn); - - Food.list(); // Eat a food - - System.setIn(sysInBackup); - - assertEquals(Health.get(), 60); // Check that player health was updated - } - - @Test - public void testListChooseLast() { - Health.set(50, 100); // Set player health to make food eating visible - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("6".getBytes()); // Set input stream to pick food automatically - - System.setIn(chooseIn); - - Food.list(); // Eat a food - - System.setIn(sysInBackup); - - assertEquals(Health.get(), 65); // Check that player health was updated - } - - @Test - public void testGetFoods() { - // Test constant foods array access - - assertEquals(Food.arrayFood.size(), Food.getFoods().size()); - - assertEquals(Food.arrayFood, Food.getFoods()); - - // Check all objects are the same in each list access method - 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/Game.java b/src/com/hotmail/kalebmarc/textfighter/main/Game.java index 6d5e8729..398bb8bd 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Game.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Game.java @@ -1,19 +1,30 @@ package com.hotmail.kalebmarc.textfighter.main; -import com.hotmail.kalebmarc.textfighter.item.*; -import com.hotmail.kalebmarc.textfighter.player.*; - -import time.GameClock; - -import javax.swing.*; -import java.util.Scanner; - import static com.hotmail.kalebmarc.textfighter.player.Health.getStr; import static com.hotmail.kalebmarc.textfighter.player.Health.upgrade; import static com.hotmail.kalebmarc.textfighter.player.Settings.menu; import static com.hotmail.kalebmarc.textfighter.player.Settings.setDif; import static java.util.Arrays.asList; +import java.util.Scanner; + +import javax.swing.JOptionPane; + +import com.hotmail.kalebmarc.textfighter.item.Armour; +import com.hotmail.kalebmarc.textfighter.item.Chest; +import com.hotmail.kalebmarc.textfighter.item.FirstAid; +import com.hotmail.kalebmarc.textfighter.item.InstaHealth; +import com.hotmail.kalebmarc.textfighter.item.Power; +import com.hotmail.kalebmarc.textfighter.player.Achievements; +import com.hotmail.kalebmarc.textfighter.player.Coins; +import com.hotmail.kalebmarc.textfighter.player.Health; +import com.hotmail.kalebmarc.textfighter.player.Potion; +import com.hotmail.kalebmarc.textfighter.player.Settings; +import com.hotmail.kalebmarc.textfighter.player.Stats; +import com.hotmail.kalebmarc.textfighter.player.Xp; + +import time.GameClock; + public class Game { // docschorsch added boolean to indicate if a game had been started private static boolean gameStarted = false; diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Handle.java b/src/com/hotmail/kalebmarc/textfighter/main/Handle.java index 54e76dc7..c23237e0 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Handle.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Handle.java @@ -1,6 +1,6 @@ package com.hotmail.kalebmarc.textfighter.main; -import javax.swing.*; +import javax.swing.JOptionPane; public class Handle { private Handle() { diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Help.java b/src/com/hotmail/kalebmarc/textfighter/main/Help.java index 56e84652..991e3284 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Help.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Help.java @@ -1,7 +1,6 @@ package com.hotmail.kalebmarc.textfighter.main; import com.hotmail.kalebmarc.textfighter.item.Armour; -import com.hotmail.kalebmarc.textfighter.player.Achievements; class Help { private Help() { diff --git a/src/com/hotmail/kalebmarc/textfighter/main/HelpTest.java b/src/com/hotmail/kalebmarc/textfighter/main/HelpTest.java deleted file mode 100644 index c624fe36..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/main/HelpTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.main; -import com.hotmail.kalebmarc.textfighter.main.Help; -import static org.junit.jupiter.api.Assertions.*; - -import java.io.*; -import org.junit.jupiter.api.Test; - -import org.mockito.MockedStatic; -import static org.mockito.Mockito.*; - - -public class HelpTest { - - @Test - //Test to ensure the Help.view() User input 4 outputs Health information - public void testView() { - Help.view(); - Ui user = mock(Ui.class); - when(user.getValidInt()).thenReturn(4); - //Check console output - assertEquals(4,Ui.getValidInt()); - } - -} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Quest.java b/src/com/hotmail/kalebmarc/textfighter/main/Quest.java index 668c5eac..a5ff2af4 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Quest.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Quest.java @@ -1,10 +1,10 @@ package com.hotmail.kalebmarc.textfighter.main; +import java.util.ArrayList; + import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.player.Xp; -import java.util.ArrayList; - public class Quest { private static final ArrayList QuestList = new ArrayList<>(); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Saves.java b/src/com/hotmail/kalebmarc/textfighter/main/Saves.java index 189e2860..4ebe537a 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Saves.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Saves.java @@ -1,17 +1,35 @@ package com.hotmail.kalebmarc.textfighter.main; -import com.hotmail.kalebmarc.textfighter.item.Armour; -import com.hotmail.kalebmarc.textfighter.item.FirstAid; -import com.hotmail.kalebmarc.textfighter.item.InstaHealth; -import com.hotmail.kalebmarc.textfighter.item.Power; -import com.hotmail.kalebmarc.textfighter.player.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; + import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.representer.Representer; -import java.io.*; -import java.nio.charset.Charset; -import java.util.*; +import com.hotmail.kalebmarc.textfighter.item.Armour; +import com.hotmail.kalebmarc.textfighter.item.FirstAid; +import com.hotmail.kalebmarc.textfighter.item.InstaHealth; +import com.hotmail.kalebmarc.textfighter.item.Power; +import com.hotmail.kalebmarc.textfighter.player.Achievements; +import com.hotmail.kalebmarc.textfighter.player.Coins; +import com.hotmail.kalebmarc.textfighter.player.Health; +import com.hotmail.kalebmarc.textfighter.player.Potion; +import com.hotmail.kalebmarc.textfighter.player.Settings; +import com.hotmail.kalebmarc.textfighter.player.Stats; +import com.hotmail.kalebmarc.textfighter.player.Xp; /** * Created by Brendon Butler on 7/27/2016. diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Shop.java b/src/com/hotmail/kalebmarc/textfighter/main/Shop.java index 7528bcc1..ce1452c8 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Shop.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Shop.java @@ -1,5 +1,7 @@ package com.hotmail.kalebmarc.textfighter.main; +import java.util.ArrayList; + import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; @@ -9,8 +11,6 @@ import com.hotmail.kalebmarc.textfighter.player.Stats; import com.hotmail.kalebmarc.textfighter.player.Xp; -import java.util.ArrayList; - class Shop { private Shop() { } diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Ui.java b/src/com/hotmail/kalebmarc/textfighter/main/Ui.java index a40e1408..b1d006ad 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Ui.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Ui.java @@ -1,9 +1,10 @@ package com.hotmail.kalebmarc.textfighter.main; -import javax.swing.*; import java.io.IOException; import java.util.Scanner; +import javax.swing.JOptionPane; + public class Ui { public static boolean guiEnabled = true; private static Scanner in = new Scanner(System.in); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java index 857446fd..c092acb1 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java @@ -1,15 +1,15 @@ package com.hotmail.kalebmarc.textfighter.main; -import com.hotmail.kalebmarc.textfighter.item.Armour; +import java.util.ArrayList; +import java.util.Collections; + +import javax.swing.JOptionPane; + import com.hotmail.kalebmarc.textfighter.player.Achievements; import com.hotmail.kalebmarc.textfighter.player.Coins; import com.hotmail.kalebmarc.textfighter.player.Stats; import com.hotmail.kalebmarc.textfighter.player.Xp; -import javax.swing.*; -import java.util.ArrayList; -import java.util.Collections; - public class Weapon implements Comparable { //Weapon List 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 0c6b8379..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java +++ /dev/null @@ -1,284 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.main; - -import com.hotmail.kalebmarc.textfighter.player.Xp; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.*; - -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; - - -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; - - 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; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - sysInBackup = System.in; // backup System.in to restore it later - - 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; - Weapon.arrayWeapon.get(Weapon.getIndex(baseballBat)).owns = true; - Weapon.arrayWeapon.get(Weapon.getIndex(pistol)).owns = true; - Weapon.arrayWeapon.get(Weapon.getIndex(pistol)).setAmmo(4, true); - - darkElf = new Enemy("Dark Elf", 145, 10, 15, 10, 15, 15, 5, 100, true, false); - ninja = new Enemy("Ninja", 175, 5, 15, 5, 15, 15, 1, 10, true, false); - giantSpider = new Enemy("Giant Spider", 135, 5, 10, 5, 10, 10, 5, 100, true, false); - zombie = new Enemy("Zombie", 120, 5, 15, 5, 15, 15, 1, 10, true, false); - goblin = new Enemy("Goblin", 160, 10, 20, 10, 20, 20, 1, 10, true, false); - ghost = new Enemy("Ghost", 185, 15, 25, 15, 25, 25, 1, 100, true, false); - barbarian = new Enemy("Barbarian", 150, 5, 15, 5, 15, 15, 5, 100, true, false); - giantAnt = new Enemy("Giant Ant", 130, 5, 10, 5, 10, 10, 1, 10, true, false); - evilUnicorn = new Enemy("Evil Unicorn", 135, 30, 40, 5, 15, 20, 5, 100, true, false); - ogre = new Enemy("Ogre", 190, 20, 50, 10, 30, 50, 5, 100, true, false); - - Xp.setLevel(1); - - Weapon.BULLET_DAMAGE = 10; - - Weapon.BULLET_CRITICAL_MULTIPLIER = 10; - Weapon.BULLET_CRITICAL_CHANCE = 100; - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - - System.setIn(sysInBackup); - } - - @Before - public void setUp() throws Exception { - - System.setIn(sysInBackup); - } - - @After - public void tearDown() throws Exception { - - System.setIn(sysInBackup); - } - - @Test - public void testDealDam() { - - Weapon.set(0); - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("\n".getBytes()); // Initialize a stream to move past user input - - System.setIn(chooseIn); - - Enemy.encounterNew(); - - String previousEnemy = Enemy.get().getName(); // Record this enemy to check for enemy death later - - int startHealth = Enemy.get().getHealth(); - - Weapon.get().dealDam(); - - int endHealth = Enemy.get().getHealth(); - - int lost = startHealth - endHealth; - - assertTrue(lost <= 10 && lost >= 5); - - startHealth = Enemy.get().getHealth(); - - Weapon.set(4); - - Weapon.get().dealDam(); - - endHealth = Enemy.get().getHealth(); - - lost = startHealth - endHealth; - - String nextEnemy = Enemy.get().getName(); // Record this enemy to check for enemy death later - - assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 0) || (nextEnemy != previousEnemy)); // Enemy should have lost a certain amount of health based on weapon, or died - - startHealth = Enemy.get().getHealth(); - - Weapon.get().dealDam(); - - endHealth = Enemy.get().getHealth(); - - lost = startHealth - endHealth; - - String lastEnemy = Enemy.get().getName(); // Record this enemy to check for enemy death later - - assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 0) || (lastEnemy != nextEnemy)); // Enemy should have lost a certain amount of health based on weapon, or died - } - - @Test - public void testGeneralBulletCriticalHit() { - - Weapon.BULLET_CRITICAL_MULTIPLIER = 10; - Weapon.BULLET_CRITICAL_CHANCE = 100; // Set critical chance to 100 to force critical hits to test - - int startHealth; - int endHealth; - int lost; - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("\n".getBytes()); // Initialize a stream to move past user input - - System.setIn(chooseIn); - - Enemy.encounterNew(); - - String previousEnemy = Enemy.get().getName(); // Record this enemy to check for enemy death later - - startHealth = Enemy.get().getHealth(); - - Weapon.set(4); - - do - { - Weapon.get().dealDam(); // Loop until user doesn't miss - - endHealth = Enemy.get().getHealth(); - - lost = startHealth - endHealth; - - } while (lost == 0); - - String nextEnemy = Enemy.get().getName(); // Record this enemy to check for enemy death later - - assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 100) || (nextEnemy != previousEnemy) || (Enemy.get().getHealth() == 20)); // Enemy should have lost a certain amount of health based on bullet damage, or died - - startHealth = Enemy.get().getHealth(); - - do - { - Weapon.get().dealDam(); // Loop until user doesn't miss - - endHealth = Enemy.get().getHealth(); - - lost = startHealth - endHealth; - - } while (lost == 0); - - String lastEnemy = Enemy.get().getName(); // Record this enemy to check for enemy death later - - assertTrue((lost <= Random.RInt(3, 4) * 10 * 10 && lost >= 100) || (lastEnemy != nextEnemy) || (Enemy.get().getHealth() == 20)); // Enemy should have lost a certain amount of health based on bullet damage, or died - } - - public void testGetIndex() { - fail("Not yet implemented"); - } - - @Test - public void testSet() { - Weapon.set(0); // Set weapon to first weapon, fist - - assertEquals("Fists", Weapon.get().getName()); // Check for successful set - - Weapon.set(1); // Set weapon to middle weapon, pipe - - assertEquals("Pipe", Weapon.get().getName()); // Check for successful set - - Weapon.set(4); // Set weapon to middle weapon, pipe - - assertEquals("Pistol", Weapon.get().getName()); // Check for successful set - } - - @Test - public void testChooseFirst() { - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("1".getBytes()); - - System.setIn(chooseIn); - - Weapon.choose(); // Choose a weapon - - System.setIn(sysInBackup); - - assertEquals("Fists", Weapon.get().getName()); // Check that player weapon was updated - } - - @Test - public void testChooseMiddle() { - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("2".getBytes()); - - System.setIn(chooseIn); - - Weapon.choose(); // Choose a weapon - - System.setIn(sysInBackup); - - assertEquals("Pipe", Weapon.get().getName()); // Check that player weapon was updated - } - - @Test - public void testChooseLast() { - - ByteArrayInputStream chooseIn = new ByteArrayInputStream("3".getBytes()); - - System.setIn(chooseIn); - - Weapon.choose(); // Choose a weapon - - System.setIn(sysInBackup); - - assertEquals("Pistol", Weapon.get().getName()); // Check that player weapon was updated - } - - @Test - public void testGetWeapons() { - // Test constant weapons array access - - assertEquals(Weapon.arrayWeapon.size(), Weapon.getWeapons().size()); - - assertEquals(Weapon.arrayWeapon, Weapon.getWeapons()); - - // Check all objects are the same in each list access method - 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)); - } -} diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Achievements.java b/src/com/hotmail/kalebmarc/textfighter/player/Achievements.java index 0a48ae55..d8c9fe55 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Achievements.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Achievements.java @@ -1,13 +1,14 @@ package com.hotmail.kalebmarc.textfighter.player; +import java.util.ArrayList; + +import javax.swing.JOptionPane; + import com.hotmail.kalebmarc.textfighter.main.Casino; import com.hotmail.kalebmarc.textfighter.main.Cheats; import com.hotmail.kalebmarc.textfighter.main.Enemy; import com.hotmail.kalebmarc.textfighter.main.Ui; -import javax.swing.*; -import java.util.ArrayList; - public class Achievements { //Arrays for achievements public static final ArrayList arrayKilled = new ArrayList<>(); diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Health.java b/src/com/hotmail/kalebmarc/textfighter/player/Health.java index a42b980e..52f1f4e9 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Health.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Health.java @@ -1,12 +1,13 @@ package com.hotmail.kalebmarc.textfighter.player; +import java.util.concurrent.ThreadLocalRandom; + +import javax.swing.JOptionPane; + import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.main.Enemy; import com.hotmail.kalebmarc.textfighter.main.Handle; import com.hotmail.kalebmarc.textfighter.main.Ui; -import java.util.concurrent.ThreadLocalRandom; - -import javax.swing.*; public class Health { diff --git a/src/com/hotmail/kalebmarc/textfighter/player/HealthTest.java b/src/com/hotmail/kalebmarc/textfighter/player/HealthTest.java deleted file mode 100644 index 5c5dfe29..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/player/HealthTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.player; - -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.Test; - -class HealthTest { - - @Test - void testGet() { - assertEquals(0, Health.get()); - } - - @Test - void testGetOutOf() { - assertEquals(0, Health.getOutOf()); - } - -} 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 0d1d6b93..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java +++ /dev/null @@ -1,325 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.player; - -import static org.junit.Assert.assertEquals; - -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.Ignore; -import org.junit.Test; - -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 { - in = new ByteArrayInputStream("\n".getBytes()); - System.setIn(in); - } - - @After - public void tearDown() throws Exception { - System.setIn(sysInBackup); - } - - @Test - public void testGet() { - - assertEquals(Potion.get("survival"), 0); // Starting with no potions - - assertEquals(Potion.get("recovery"), 0); // Starting with no potions - - Potion.set("survival", 5, false); // Set player's survival potion count to 5 - - Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 - - assertEquals(Potion.get("survival"), 5); // Check survival potion total - - assertEquals(Potion.get("recovery"), 5); // Check recovery potion total - - // Test that using a potion depletes the total - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 2); // Check survival potion total after using some potions - - assertEquals(Potion.get("recovery"), 3); // Check recovery potion total after using some potions - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 0); // Check survival potion total - - assertEquals(Potion.get("recovery"), 0); // Check recovery potion total - - // Attempt to use nonexistant potions - Potion.use("survival"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 0); // Check survival potion total after using all potions - - assertEquals(Potion.get("recovery"), 0); // Check recovery potion total after using all potions - } - - @Test - public void testSet() { - - Potion.set("survival", 0, false); // Starting with no potions - - Potion.set("recovery", 0, false); // Starting with no potions - - assertEquals(Potion.get("survival"), 0); // Check survival potion total - - assertEquals(Potion.get("recovery"), 0); // Check recovery potion total - - Potion.set("survival", 5, false); // Set player's survival potion count to 5 - - Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 - - assertEquals(Potion.get("survival"), 5); // Check survival potion total - - assertEquals(Potion.get("recovery"), 5); // Check recovery potion total - - // Test that using a potion depletes the total - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - Potion.set("survival", 5, false); // Set player's survival potion count to 5 - - Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 - - assertEquals(Potion.get("survival"), 5); // Check survival potion total - - assertEquals(Potion.get("recovery"), 5); // Check recovery potion total - - // Deplete potions again - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 2); // Check survival potion total - - assertEquals(Potion.get("recovery"), 3); // Check recovery potion total - - Potion.set("survival", 5, true); // Set player's survival potion count to 5 more - - Potion.set("recovery", 5, true); // Set player's recovery potion count to 5 more - - assertEquals(Potion.get("survival"), 7); // Check survival potion total - - assertEquals(Potion.get("recovery"), 8); // Check recovery potion total - } - - @Test - public void testUse() { - - Potion.set("survival", 0, false); // Starting with no potions - - Potion.set("recovery", 0, false); // Starting with no potions - - Potion.set("survival", 5, false); // Set player's survival potion count to 5 - - Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 - - // Test that using a potion depletes the total - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 2); // Check survival potion total - - assertEquals(Potion.get("recovery"), 3); // Check recovery potion total - - // Deplete potions again - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 0); // Check survival potion total - - assertEquals(Potion.get("recovery"), 0); // Check recovery potion total - - // Attempt to use nonexistant potions - Potion.use("survival"); - - Potion.use("recovery"); - - assertEquals(Potion.get("survival"), 0); // Check survival potion total after using all potions - - assertEquals(Potion.get("recovery"), 0); // Check recovery potion total after using all potions - } - - @Test - public void testUsed() { - - Potion.set("survival", 0, false); // Starting with no potions - - Potion.set("recovery", 0, false); // Starting with no potions - - Potion.set("survival", 5, false); // Set player's survival potion count to 5 - - Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 - - assertEquals(16, Potion.spUsed); // Check total survival potions that have been used throughout the tests - - assertEquals(14, Potion.rpUsed); // Check total recovery potions that have been used throughout the tests - - // Test that using a potion increments the total used - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(19, Potion.spUsed); // Check total survival potions that have been used - - assertEquals(16, Potion.rpUsed); // Check total recovery potions that have been used - - // Deplete potions again - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(21, Potion.spUsed); // Check total survival potions that have been used - - assertEquals(19, Potion.rpUsed); // Check total recovery potions that have been used - - // Attempt to use nonexistant potions - Potion.use("survival"); - - Potion.use("recovery"); - - assertEquals(21, Potion.spUsed); // Check total survival potions that have been used after using all potions - - assertEquals(19, Potion.rpUsed); // Check total recovery potions that have been used after using all potions - } - - @Ignore - @Test - public void testUsedAlone() { - - Potion.set("survival", 0, false); // Starting with no potions - - Potion.set("recovery", 0, false); // Starting with no potions - - Potion.set("survival", 5, false); // Set player's survival potion count to 5 - - Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 - - Potion.spUsed = 0; // Reset survival potion usage count - - Potion.rpUsed = 0; // Reset recovery potion usage count - - assertEquals(0, Potion.spUsed); // Check total survival potions that have been used in this test - - assertEquals(0, Potion.rpUsed); // Check total recovery potions that have been used in this test - - // Test that using a potion increments the total used - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(3, Potion.spUsed); // Check total survival potions that have been used - - assertEquals(2, Potion.rpUsed); // Check total recovery potions that have been used - - // Deplete potions again - Potion.use("survival"); - - Potion.use("survival"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - Potion.use("recovery"); - - assertEquals(5, Potion.spUsed); // Check total survival potions that have been used - - assertEquals(5, Potion.rpUsed); // Check total recovery potions that have been used - - // Attempt to use nonexistant potions - Potion.use("survival"); - - Potion.use("recovery"); - - assertEquals(5, Potion.spUsed); // Check total survival potions that have been used after using all potions - - assertEquals(5, Potion.rpUsed); // Check total recovery potions that have been used after using all potions - } -} diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Settings.java b/src/com/hotmail/kalebmarc/textfighter/player/Settings.java index 222226f3..99eb9eda 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Settings.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Settings.java @@ -3,7 +3,12 @@ import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; import com.hotmail.kalebmarc.textfighter.item.Power; -import com.hotmail.kalebmarc.textfighter.main.*; +import com.hotmail.kalebmarc.textfighter.main.Bank; +import com.hotmail.kalebmarc.textfighter.main.Cheats; +import com.hotmail.kalebmarc.textfighter.main.Enemy; +import com.hotmail.kalebmarc.textfighter.main.Game; +import com.hotmail.kalebmarc.textfighter.main.Ui; +import com.hotmail.kalebmarc.textfighter.main.Weapon; public class Settings { diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Stats.java b/src/com/hotmail/kalebmarc/textfighter/player/Stats.java index e9296957..e83bb9d5 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Stats.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Stats.java @@ -3,7 +3,12 @@ import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; import com.hotmail.kalebmarc.textfighter.item.Power; -import com.hotmail.kalebmarc.textfighter.main.*; +import com.hotmail.kalebmarc.textfighter.main.Bank; +import com.hotmail.kalebmarc.textfighter.main.Casino; +import com.hotmail.kalebmarc.textfighter.main.Cheats; +import com.hotmail.kalebmarc.textfighter.main.Food; +import com.hotmail.kalebmarc.textfighter.main.Ui; +import com.hotmail.kalebmarc.textfighter.main.Weapon; public class Stats { //Battle Stats diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Xp.java b/src/com/hotmail/kalebmarc/textfighter/player/Xp.java index 950b7c96..b92aabcb 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Xp.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Xp.java @@ -1,11 +1,11 @@ package com.hotmail.kalebmarc.textfighter.player; +import javax.swing.JOptionPane; + import com.hotmail.kalebmarc.textfighter.main.Cheats; import com.hotmail.kalebmarc.textfighter.main.Handle; import com.hotmail.kalebmarc.textfighter.main.Ui; -import javax.swing.*; - public class Xp { //Variables diff --git a/src/tests/TestGameClock.java b/src/tests/TestGameClock.java deleted file mode 100644 index 8200eb76..00000000 --- a/src/tests/TestGameClock.java +++ /dev/null @@ -1,71 +0,0 @@ -package tests; - - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.*; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.Month; - -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.jupiter.api.Test; - -import time.GameClock; - -public class TestGameClock { - - - - @Test - void testTimeConversion() { - GameClock newClock = new GameClock(); - newClock.setStartTime(0); - newClock.setEndTime(60000); - long conversion = newClock.timeConversion(); - assertEquals(conversion, (newClock.getIncreasedTime() + (newClock.getIncreasedTime() * newClock.getIncreasePercent()))); - assertNotEquals(conversion, (newClock.getIncreasedTime() + ((newClock.getIncreasedTime() + 1) * newClock.getIncreasePercent()))); - assertNotEquals(conversion, (newClock.getIncreasedTime() + (345346 * newClock.getIncreasePercent()))); - } - - @Test - void testUpdateGameTime() { - LocalDateTime testTimeBase = LocalDateTime.of(LocalDate.of(2021, Month.DECEMBER, 2), LocalTime.of(5, 0, 0)); - String testTimeFast; - GameClock newClock = new GameClock(); - newClock.setBaseTime(testTimeBase); - newClock.setStartTime(0); - newClock.setEndTime(6000000); - newClock.updateGameTime(); - testTimeFast = newClock.getFastTime().format(newClock.getDateTimeFormat()); - assertFalse(testTimeFast.equals(newClock.getBaseTime().format(newClock.getDateTimeFormat()))); - - } - - - @BeforeClass - void testValues() { - GameClock newClock = new GameClock(); - assertEquals(newClock.getStartTime(), 0); - assertEquals(newClock.getEndTime(), 0); - } - - @Test - void testDayRollOver() { - LocalDateTime testTimeBase = LocalDateTime.of(LocalDate.of(2021, Month.OCTOBER, 23), LocalTime.of(23, 59, 59)); - GameClock newClock = new GameClock(); - newClock.setBaseTime(testTimeBase); - newClock.splitDateTime(newClock.getBaseTime()); - String baseDate = newClock.getGameDate(); - newClock.setStartTime(0); - newClock.setEndTime(6000000); - newClock.updateGameTime(); - String fastDate = newClock.getGameDate(); - assertFalse(fastDate.equalsIgnoreCase(baseDate)); - } - - - -} diff --git a/src/time/GameClock.java b/src/time/GameClock.java index fe6d79a6..01728e12 100644 --- a/src/time/GameClock.java +++ b/src/time/GameClock.java @@ -1,13 +1,8 @@ package time; -import java.time.Clock; import java.time.Duration; -import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.TimeZone; public class GameClock { From 251c7a2c5f1a8ab3dc079299db97ca858c6c672c Mon Sep 17 00:00:00 2001 From: R1ndT Date: Thu, 23 Dec 2021 16:15:50 +0100 Subject: [PATCH 2/7] Added the Property class and integrated it with the shop (Organised imports, added horizontal rule function) --- .gitignore | 1 - build.gradle | 55 ++++++++++++ gradlew | 0 .../textfighter/casino/BlackjackGame.java | 8 +- .../kalebmarc/textfighter/item/Armour.java | 4 +- .../kalebmarc/textfighter/main/About.java | 2 +- .../kalebmarc/textfighter/main/Cheats.java | 11 +-- .../kalebmarc/textfighter/main/Enemy.java | 12 +-- .../kalebmarc/textfighter/main/Food.java | 4 +- .../kalebmarc/textfighter/main/Game.java | 89 ++++++++++++------- .../kalebmarc/textfighter/main/Handle.java | 2 +- .../kalebmarc/textfighter/main/Property.java | 79 +++++++++++++++- .../kalebmarc/textfighter/main/Quest.java | 4 +- .../kalebmarc/textfighter/main/Saves.java | 36 ++------ .../kalebmarc/textfighter/main/Shop.java | 40 +++++++-- .../kalebmarc/textfighter/main/Ui.java | 8 +- .../kalebmarc/textfighter/main/Weapon.java | 9 +- .../textfighter/player/Achievements.java | 7 +- .../kalebmarc/textfighter/player/Coins.java | 1 - .../kalebmarc/textfighter/player/Health.java | 7 +- .../textfighter/player/Settings.java | 17 ++-- .../kalebmarc/textfighter/player/Stats.java | 9 +- .../kalebmarc/textfighter/player/Xp.java | 4 +- 23 files changed, 278 insertions(+), 131 deletions(-) create mode 100644 build.gradle mode change 100644 => 100755 gradlew mode change 100644 => 100755 src/com/hotmail/kalebmarc/textfighter/main/Property.java mode change 100644 => 100755 src/com/hotmail/kalebmarc/textfighter/main/Shop.java diff --git a/.gitignore b/.gitignore index 1a3b87f7..b1d42b78 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ Text-Fighter.iml .gradle build gradle -build.gradle # Mobile Tools for Java (J2ME) .mtj.tmp/ diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..73199da1 --- /dev/null +++ b/build.gradle @@ -0,0 +1,55 @@ +/* + * This build file was generated by the Gradle 'init' task. + * + * This generated file contains a sample Java project to get you started. + * For more details take a look at the Java Quickstart chapter in the Gradle + * user guide available at https://docs.gradle.org/4.1/userguide/tutorial_java_projects.html + */ + +// Apply the java plugin to add support for Java +// Apply the application plugin to add support for building an application +plugins { + id 'java' + id 'application' +} + +// In this section you declare where to find the dependencies of your project +repositories { + // Use jcenter for resolving your dependencies. + // You can declare any Maven/Ivy/file repository here. + jcenter() +} + +dependencies { + // This dependency is found on compile classpath of this component and consumers. + implementation 'com.google.guava:guava:22.0' + implementation 'org.yaml:snakeyaml:1.19' + // Use JUnit test framework + testImplementation 'junit:junit:4.12' +} + +// Define the main class for the application + +sourceSets { + main { + java { + srcDirs 'src' + } + } +} + +mainClassName = 'com.hotmail.kalebmarc.textfighter.main.Start' + +// Makes the compiled jar file executable +jar{ + manifest{ + attributes( + "Main-Class": mainClassName + ) + } +} + +// Resolves the input problem during Gradle run +run{ + standardInput = System.in +} \ No newline at end of file diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/com/hotmail/kalebmarc/textfighter/casino/BlackjackGame.java b/src/com/hotmail/kalebmarc/textfighter/casino/BlackjackGame.java index e201d396..f45cf7da 100644 --- a/src/com/hotmail/kalebmarc/textfighter/casino/BlackjackGame.java +++ b/src/com/hotmail/kalebmarc/textfighter/casino/BlackjackGame.java @@ -1,14 +1,10 @@ package com.hotmail.kalebmarc.textfighter.casino; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Stack; - import com.hotmail.kalebmarc.textfighter.main.Ui; import com.hotmail.kalebmarc.textfighter.player.Coins; +import java.util.*; + public class BlackjackGame extends BasicCasinoGame { private Stack cardStack; diff --git a/src/com/hotmail/kalebmarc/textfighter/item/Armour.java b/src/com/hotmail/kalebmarc/textfighter/item/Armour.java index abac2e27..58e582cc 100644 --- a/src/com/hotmail/kalebmarc/textfighter/item/Armour.java +++ b/src/com/hotmail/kalebmarc/textfighter/item/Armour.java @@ -1,13 +1,13 @@ package com.hotmail.kalebmarc.textfighter.item; -import java.util.ArrayList; - import com.hotmail.kalebmarc.textfighter.main.Handle; import com.hotmail.kalebmarc.textfighter.main.NPC; import com.hotmail.kalebmarc.textfighter.main.Ui; import com.hotmail.kalebmarc.textfighter.player.Coins; import com.hotmail.kalebmarc.textfighter.player.Xp; +import java.util.ArrayList; + public class Armour { private static ArrayList armours = new ArrayList<>(3); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/About.java b/src/com/hotmail/kalebmarc/textfighter/main/About.java index 073ad5a6..8ce41103 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/About.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/About.java @@ -1,6 +1,6 @@ package com.hotmail.kalebmarc.textfighter.main; -import javax.swing.JOptionPane; +import javax.swing.*; class About { private static boolean viewed = false; diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java b/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java index da50b04a..44bc108d 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java @@ -1,16 +1,11 @@ package com.hotmail.kalebmarc.textfighter.main; -import java.util.Scanner; - import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; import com.hotmail.kalebmarc.textfighter.item.Power; -import com.hotmail.kalebmarc.textfighter.player.Coins; -import com.hotmail.kalebmarc.textfighter.player.Health; -import com.hotmail.kalebmarc.textfighter.player.Potion; -import com.hotmail.kalebmarc.textfighter.player.Settings; -import com.hotmail.kalebmarc.textfighter.player.Stats; -import com.hotmail.kalebmarc.textfighter.player.Xp; +import com.hotmail.kalebmarc.textfighter.player.*; + +import java.util.Scanner; public class Cheats { diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java b/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java index 9ae53d74..9c538ada 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java @@ -1,15 +1,9 @@ package com.hotmail.kalebmarc.textfighter.main; -import java.util.ArrayList; - -import javax.swing.JOptionPane; +import com.hotmail.kalebmarc.textfighter.player.*; -import com.hotmail.kalebmarc.textfighter.player.Achievements; -import com.hotmail.kalebmarc.textfighter.player.Coins; -import com.hotmail.kalebmarc.textfighter.player.Health; -import com.hotmail.kalebmarc.textfighter.player.Potion; -import com.hotmail.kalebmarc.textfighter.player.Stats; -import com.hotmail.kalebmarc.textfighter.player.Xp; +import javax.swing.*; +import java.util.ArrayList; public class Enemy { diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Food.java b/src/com/hotmail/kalebmarc/textfighter/main/Food.java index b5f58683..fb4b8e27 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Food.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Food.java @@ -1,9 +1,9 @@ package com.hotmail.kalebmarc.textfighter.main; -import java.util.ArrayList; - import com.hotmail.kalebmarc.textfighter.player.Health; +import java.util.ArrayList; + public class Food { //Food List diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Game.java b/src/com/hotmail/kalebmarc/textfighter/main/Game.java index 398bb8bd..f086b77c 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Game.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Game.java @@ -1,30 +1,19 @@ package com.hotmail.kalebmarc.textfighter.main; +import com.hotmail.kalebmarc.textfighter.item.*; +import com.hotmail.kalebmarc.textfighter.player.*; +import time.GameClock; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.Scanner; + import static com.hotmail.kalebmarc.textfighter.player.Health.getStr; import static com.hotmail.kalebmarc.textfighter.player.Health.upgrade; import static com.hotmail.kalebmarc.textfighter.player.Settings.menu; import static com.hotmail.kalebmarc.textfighter.player.Settings.setDif; import static java.util.Arrays.asList; -import java.util.Scanner; - -import javax.swing.JOptionPane; - -import com.hotmail.kalebmarc.textfighter.item.Armour; -import com.hotmail.kalebmarc.textfighter.item.Chest; -import com.hotmail.kalebmarc.textfighter.item.FirstAid; -import com.hotmail.kalebmarc.textfighter.item.InstaHealth; -import com.hotmail.kalebmarc.textfighter.item.Power; -import com.hotmail.kalebmarc.textfighter.player.Achievements; -import com.hotmail.kalebmarc.textfighter.player.Coins; -import com.hotmail.kalebmarc.textfighter.player.Health; -import com.hotmail.kalebmarc.textfighter.player.Potion; -import com.hotmail.kalebmarc.textfighter.player.Settings; -import com.hotmail.kalebmarc.textfighter.player.Stats; -import com.hotmail.kalebmarc.textfighter.player.Xp; - -import time.GameClock; - public class Game { // docschorsch added boolean to indicate if a game had been started private static boolean gameStarted = false; @@ -62,6 +51,9 @@ public static boolean hadGameStarted() { public static Armour basic = new Armour("Basic", 400, 15, 5); public static Armour advanced = new Armour("Advanced", 750, 30, 7); + //Properties + public static Property farm; + //Food //TODO when the StatusEffect system is implemented, change effect types public static Food apple = new Food("Apple", "A boring 'ol apple.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); @@ -166,14 +158,15 @@ public void start() { Ui.println("------------------------------------------------------------------"); Ui.println("1) Go to battle"); Ui.println("2) Go Home"); - Ui.println("3) Go to the town"); - Ui.println("4) Use First-Aid kit"); - Ui.println("5) Use Potion"); - Ui.println("6) Eat Food"); - Ui.println("7) Use Insta-Health"); - Ui.println("8) Use POWER"); - Ui.println("9) Run From Battle (You will lose any XP earned)"); - Ui.println("10) Quit Game (Game will automatically be saved)"); + Ui.println("3) Go to a property"); + Ui.println("4) Go to the town"); + Ui.println("5) Use First-Aid kit"); + Ui.println("6) Use Potion"); + Ui.println("7) Eat Food"); + Ui.println("8) Use Insta-Health"); + Ui.println("9) Use POWER"); + Ui.println("10) Run From Battle (You will lose any XP earned)"); + Ui.println("11) Quit Game (Game will automatically be saved)"); Ui.println("------------------------------------------------------------------"); switch (Ui.getValidInt()) { @@ -192,12 +185,14 @@ public void start() { home(); break; case 3: + property(); + case 4: town(); break; - case 4: + case 5: FirstAid.use(); break; - case 5: + case 6: Ui.cls(); Ui.println("Which potion would you like to use?"); Ui.println("1) Survival Potion"); @@ -216,21 +211,21 @@ public void start() { break; } break; - case 6: + case 7: Food.list(); break; - case 7: + case 8: InstaHealth.use(); break; - case 8: + case 9: Power.use(); break; - case 9: + case 10: Ui.cls(); Ui.popup("You ran away from the battle.", "Ran Away", JOptionPane.INFORMATION_MESSAGE); Enemy.encounterNew(); break; - case 10: + case 11: Stats.timesQuit++; return; case 0: @@ -369,6 +364,32 @@ private static void home() { }//While loop }//Method + private static void property() { + Ui.println("Which property would you like to visit?"); + Ui.println(); + ArrayList suitableProperties = new ArrayList(); + for (int i = 0; i < Property.getPropertyList().size(); i++) { + Property p = Property.getPropertyList().get(i); + if (p.owns()) { + Ui.print((i + 1) + ") " + p.getName()); + suitableProperties.add(p); + } + } + Ui.println(); + Ui.println((suitableProperties.size() + 1) + ") Back"); + + while(true) { + int menuItem = Ui.getValidInt(); + if (menuItem == suitableProperties.size() + 1) { + return; + } + + if (menuItem <= suitableProperties.size()) { + suitableProperties.get(menuItem -1).visit(); + } + } + } + private static String getDifficulty() { /* diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Handle.java b/src/com/hotmail/kalebmarc/textfighter/main/Handle.java index c23237e0..54e76dc7 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Handle.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Handle.java @@ -1,6 +1,6 @@ package com.hotmail.kalebmarc.textfighter.main; -import javax.swing.JOptionPane; +import javax.swing.*; public class Handle { private Handle() { diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Property.java b/src/com/hotmail/kalebmarc/textfighter/main/Property.java old mode 100644 new mode 100755 index a52a4c8b..3e4b450b --- a/src/com/hotmail/kalebmarc/textfighter/main/Property.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Property.java @@ -1,7 +1,84 @@ package com.hotmail.kalebmarc.textfighter.main; +import com.hotmail.kalebmarc.textfighter.item.FirstAid; +import com.hotmail.kalebmarc.textfighter.player.*; + +import java.util.ArrayList; + public class Property { +public static final ArrayList arrayProperty = new ArrayList(); + + private String name; + private int price; + private int level; + private String description; + private boolean owns; + + public Property(String name, int price, int level, String description, boolean firstInit, boolean changeDif) { + this.name = name; + this.price = price; + this.level = level; + this.description = description; + + if (!changeDif) { + arrayProperty.add(this); + } + + if (firstInit) { + this.owns = false; + } + } + + public static ArrayList getPropertyList() { + return arrayProperty; + } + public String getName() { + return name.toString(); + } + public int getPrice() { + return price; + } + public int getLevel() { + return level; + } + + public void visit() { + Ui.cls(); + Ui.println("------------------------------------------------------------------"); + Ui.println(" ".repeat(27 - name.length()) + "Welcome to the " + name + "!" + " ".repeat(27 - name.length())); + Ui.pause(); + + } + + public boolean owns() { + return owns; + } + public void buy() { + if (this.owns()) { + Ui.msg("You already own this property."); + return; + } + if (level > Xp.getLevel()) { + Ui.msg("You are not a high enough level to buy this item."); + return; + } + if (price > Coins.get()) { + Ui.msg("You do not have enough coins to buy this item."); + return; + } + + Achievements.boughtItem = true; + Coins.set(-price, true); + Stats.coinsSpentOnProperty += price; + this.owns = true; + Ui.println("You have bought a " + this.getName() + " for " + this.price + " coins."); + Ui.println("Coins: " + Coins.get()); + Ui.pause(); + + } + + /* private String name; private String desc; private Type type; @@ -74,6 +151,6 @@ public String toString() { return null; } } - } + } */ } diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Quest.java b/src/com/hotmail/kalebmarc/textfighter/main/Quest.java index a5ff2af4..668c5eac 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Quest.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Quest.java @@ -1,10 +1,10 @@ package com.hotmail.kalebmarc.textfighter.main; -import java.util.ArrayList; - import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.player.Xp; +import java.util.ArrayList; + public class Quest { private static final ArrayList QuestList = new ArrayList<>(); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Saves.java b/src/com/hotmail/kalebmarc/textfighter/main/Saves.java index 4ebe537a..bf24edc4 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Saves.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Saves.java @@ -1,35 +1,17 @@ package com.hotmail.kalebmarc.textfighter.main; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Scanner; -import java.util.Set; - -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.representer.Representer; - import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; import com.hotmail.kalebmarc.textfighter.item.Power; -import com.hotmail.kalebmarc.textfighter.player.Achievements; -import com.hotmail.kalebmarc.textfighter.player.Coins; -import com.hotmail.kalebmarc.textfighter.player.Health; -import com.hotmail.kalebmarc.textfighter.player.Potion; -import com.hotmail.kalebmarc.textfighter.player.Settings; -import com.hotmail.kalebmarc.textfighter.player.Stats; -import com.hotmail.kalebmarc.textfighter.player.Xp; +import com.hotmail.kalebmarc.textfighter.player.*; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.representer.Representer; + +import java.io.*; +import java.nio.charset.Charset; +import java.util.*; /** * Created by Brendon Butler on 7/27/2016. @@ -345,7 +327,7 @@ private static void setup() { } catch (IOException exception) { exception.printStackTrace(); } - + options = new DumperOptions(); setupDumper(); yaml = new Yaml(representer, options); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Shop.java b/src/com/hotmail/kalebmarc/textfighter/main/Shop.java old mode 100644 new mode 100755 index ce1452c8..1cb12460 --- a/src/com/hotmail/kalebmarc/textfighter/main/Shop.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Shop.java @@ -1,7 +1,5 @@ package com.hotmail.kalebmarc.textfighter.main; -import java.util.ArrayList; - import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; @@ -11,6 +9,8 @@ import com.hotmail.kalebmarc.textfighter.player.Stats; import com.hotmail.kalebmarc.textfighter.player.Xp; +import java.util.ArrayList; + class Shop { private Shop() { } @@ -287,6 +287,8 @@ private static void buyAmmo() { } } } + + private static void property(){ while (true){ @@ -298,13 +300,41 @@ private static void property(){ Ui.println("Coins: " + Coins.get()); Ui.println("________________________________________________"); - //TODO do stuff to buy property - Ui.pause();//temp - + for (int i = 0; i < Property.getPropertyList().size(); i++) { + Property p = Property.getPropertyList().get(i); + Ui.println((i + 1) + ") " + p.getName()); + Ui.println(" Price: " + p.getPrice()); + Ui.println(" Level: " + p.getLevel()); + } + Ui.println(); + Ui.println((Property.getPropertyList().size() + 1) + ") Back"); + buyProperty(); + return; + } + } + private static void buyProperty() { + int size = Property.getPropertyList().size(); + int menuItem = Ui.getValidInt(); + if (menuItem == size + 1) { + Ui.cls(); return; } + + if (menuItem <= size) { + Property.getPropertyList().get(menuItem - 1).buy(); + // NPC.gratitude("Property", "purchase"); // TODO Add property shop + property(); + } else { + Ui.println(); + Ui.println(menuItem + " is not an option."); + Ui.cls(); + Ui.pause(); + property(); + } } + + private static void armour() { while (true) { Ui.cls(); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Ui.java b/src/com/hotmail/kalebmarc/textfighter/main/Ui.java index b1d006ad..13b868c2 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Ui.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Ui.java @@ -1,10 +1,9 @@ package com.hotmail.kalebmarc.textfighter.main; +import javax.swing.*; import java.io.IOException; import java.util.Scanner; -import javax.swing.JOptionPane; - public class Ui { public static boolean guiEnabled = true; private static Scanner in = new Scanner(System.in); @@ -113,6 +112,11 @@ public static void println() { print("\n"); } + // 66 characters long + public static void printhr() { + println("------------------------------------------------------------------"); + } + /** * Clears screen, prints msg, then calls pause();. * diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java index c092acb1..9aafe877 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java @@ -1,15 +1,14 @@ package com.hotmail.kalebmarc.textfighter.main; -import java.util.ArrayList; -import java.util.Collections; - -import javax.swing.JOptionPane; - import com.hotmail.kalebmarc.textfighter.player.Achievements; import com.hotmail.kalebmarc.textfighter.player.Coins; import com.hotmail.kalebmarc.textfighter.player.Stats; import com.hotmail.kalebmarc.textfighter.player.Xp; +import javax.swing.*; +import java.util.ArrayList; +import java.util.Collections; + public class Weapon implements Comparable { //Weapon List diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Achievements.java b/src/com/hotmail/kalebmarc/textfighter/player/Achievements.java index d8c9fe55..0a48ae55 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Achievements.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Achievements.java @@ -1,14 +1,13 @@ package com.hotmail.kalebmarc.textfighter.player; -import java.util.ArrayList; - -import javax.swing.JOptionPane; - import com.hotmail.kalebmarc.textfighter.main.Casino; import com.hotmail.kalebmarc.textfighter.main.Cheats; import com.hotmail.kalebmarc.textfighter.main.Enemy; import com.hotmail.kalebmarc.textfighter.main.Ui; +import javax.swing.*; +import java.util.ArrayList; + public class Achievements { //Arrays for achievements public static final ArrayList arrayKilled = new ArrayList<>(); diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Coins.java b/src/com/hotmail/kalebmarc/textfighter/player/Coins.java index a9ebac13..9b3fc8db 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Coins.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Coins.java @@ -22,5 +22,4 @@ public static void set(int amount, boolean add) { if (coins < 0) coins = 0; } } - } \ No newline at end of file diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Health.java b/src/com/hotmail/kalebmarc/textfighter/player/Health.java index 52f1f4e9..02f61c5d 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Health.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Health.java @@ -1,14 +1,13 @@ package com.hotmail.kalebmarc.textfighter.player; -import java.util.concurrent.ThreadLocalRandom; - -import javax.swing.JOptionPane; - import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.main.Enemy; import com.hotmail.kalebmarc.textfighter.main.Handle; import com.hotmail.kalebmarc.textfighter.main.Ui; +import javax.swing.*; +import java.util.concurrent.ThreadLocalRandom; + public class Health { public static int timesDied; diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Settings.java b/src/com/hotmail/kalebmarc/textfighter/player/Settings.java index 99eb9eda..87575d59 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Settings.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Settings.java @@ -3,12 +3,7 @@ import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; import com.hotmail.kalebmarc.textfighter.item.Power; -import com.hotmail.kalebmarc.textfighter.main.Bank; -import com.hotmail.kalebmarc.textfighter.main.Cheats; -import com.hotmail.kalebmarc.textfighter.main.Enemy; -import com.hotmail.kalebmarc.textfighter.main.Game; -import com.hotmail.kalebmarc.textfighter.main.Ui; -import com.hotmail.kalebmarc.textfighter.main.Weapon; +import com.hotmail.kalebmarc.textfighter.main.*; public class Settings { @@ -176,6 +171,9 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi Game.rifle = new Weapon("Rifle", 1, 18, true, 275, 1, 5, 10, 1.25, 6, 7, firstInit, changeDif); Game.sniper = new Weapon("Sniper", 1, 10, true, 700, 2, 7, 0, 1, 7, 10, firstInit, changeDif); + //Properties + Game.farm = new Property("Farm", 200, 10, "A farm", firstInit, changeDif); + //Price Power.price = 25; Weapon.BULLET_DAMAGE = 10; @@ -227,6 +225,9 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi Game.rifle = new Weapon("Rifle", 1, 18, true, 300, 1, 5, 10, 1, 5, 6, firstInit, changeDif); Game.sniper = new Weapon("Sniper", 1, 10, true, 750, 2, 7, 0, .75, 7, 9, firstInit, changeDif); + //Properties + Game.farm = new Property("Farm", 200, 10, "A farm", firstInit, changeDif); + //PRICE Power.price = 75; Weapon.BULLET_DAMAGE = 5; @@ -253,11 +254,11 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi private static void newGameSetup() { - Coins.set(50, false); + Coins.set(50000, false); FirstAid.set(3, false); Potion.set("survival", 2, false); Potion.set("recovery", 2, false); - Xp.setAll(0, 500, 1); + Xp.setAll(0, 500, 100); Game.none.setOwns(true); Game.none.equipSilent(); diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Stats.java b/src/com/hotmail/kalebmarc/textfighter/player/Stats.java index e83bb9d5..fee6772b 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Stats.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Stats.java @@ -3,12 +3,7 @@ import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; import com.hotmail.kalebmarc.textfighter.item.Power; -import com.hotmail.kalebmarc.textfighter.main.Bank; -import com.hotmail.kalebmarc.textfighter.main.Casino; -import com.hotmail.kalebmarc.textfighter.main.Cheats; -import com.hotmail.kalebmarc.textfighter.main.Food; -import com.hotmail.kalebmarc.textfighter.main.Ui; -import com.hotmail.kalebmarc.textfighter.main.Weapon; +import com.hotmail.kalebmarc.textfighter.main.*; public class Stats { //Battle Stats @@ -21,6 +16,7 @@ public class Stats { //Coins public static int totalCoinsSpent; public static int coinsSpentOnWeapons; + public static int coinsSpentOnProperty; public static int coinsSpentOnHealth; public static int coinsSpentOnBankInterest; public static int xpBought; @@ -66,6 +62,7 @@ public static void view() { Ui.println(" Total coins spent - " + totalCoinsSpent); Ui.println(" Coins spent on bank interest - " + coinsSpentOnBankInterest); Ui.println(" Coins spent on weapons - " + coinsSpentOnWeapons); + Ui.println(" Coins spent on buying property - " + coinsSpentOnProperty); Ui.println(" Coins spent on health - " + coinsSpentOnHealth); Ui.println(" XP bought - " + xpBought); Ui.println(); diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Xp.java b/src/com/hotmail/kalebmarc/textfighter/player/Xp.java index b92aabcb..950b7c96 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Xp.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Xp.java @@ -1,11 +1,11 @@ package com.hotmail.kalebmarc.textfighter.player; -import javax.swing.JOptionPane; - import com.hotmail.kalebmarc.textfighter.main.Cheats; import com.hotmail.kalebmarc.textfighter.main.Handle; import com.hotmail.kalebmarc.textfighter.main.Ui; +import javax.swing.*; + public class Xp { //Variables From e8ccf214a880f0a5b3d070f57e859e740a1f57f8 Mon Sep 17 00:00:00 2001 From: R1ndT Date: Thu, 23 Dec 2021 16:32:53 +0100 Subject: [PATCH 3/7] Added a function to centre printed text --- src/com/hotmail/kalebmarc/textfighter/main/Property.java | 5 +++-- src/com/hotmail/kalebmarc/textfighter/main/Ui.java | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Property.java b/src/com/hotmail/kalebmarc/textfighter/main/Property.java index 3e4b450b..012e348c 100755 --- a/src/com/hotmail/kalebmarc/textfighter/main/Property.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Property.java @@ -45,8 +45,9 @@ public int getLevel() { public void visit() { Ui.cls(); - Ui.println("------------------------------------------------------------------"); - Ui.println(" ".repeat(27 - name.length()) + "Welcome to the " + name + "!" + " ".repeat(27 - name.length())); + Ui.printhr(); + Ui.println(Ui.getCentred("Welcome to the " + name + "!")); + Ui.printhr(); Ui.pause(); } diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Ui.java b/src/com/hotmail/kalebmarc/textfighter/main/Ui.java index 13b868c2..f0290bf4 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Ui.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Ui.java @@ -112,9 +112,14 @@ public static void println() { print("\n"); } - // 66 characters long + private static int hrLength = 66; public static void printhr() { - println("------------------------------------------------------------------"); + println("-".repeat(hrLength)); + } + + // This function will reliably centre solely strings of an even length. I don't know of a way to fix this without varying hrLength. Do you? Couldn't varying hrLength solve the issue reliably as well? + public static String getCentred(String input) { + return " ".repeat((hrLength - input.length()) / 2) + input; } /** From fd0e9b3fa21dd20e65a38783f69deba55e665371 Mon Sep 17 00:00:00 2001 From: R1ndT Date: Sun, 26 Dec 2021 17:58:40 +0100 Subject: [PATCH 4/7] Added the logic --- .../kalebmarc/textfighter/farm/Crop.java | 65 ++++++++ .../kalebmarc/textfighter/farm/Farm.java | 131 +++++++++++++++ .../kalebmarc/textfighter/farm/Field.java | 130 +++++++++++++++ .../kalebmarc/textfighter/farm/Seed.java | 124 ++++++++++++++ .../kalebmarc/textfighter/main/Game.java | 46 +++-- .../kalebmarc/textfighter/main/Help.java | 1 + .../kalebmarc/textfighter/main/Property.java | 157 ------------------ .../kalebmarc/textfighter/main/Shop.java | 141 +++++++++++++--- .../textfighter/player/Settings.java | 33 +++- .../kalebmarc/textfighter/player/Stats.java | 4 + 10 files changed, 633 insertions(+), 199 deletions(-) create mode 100644 src/com/hotmail/kalebmarc/textfighter/farm/Crop.java create mode 100755 src/com/hotmail/kalebmarc/textfighter/farm/Farm.java create mode 100644 src/com/hotmail/kalebmarc/textfighter/farm/Field.java create mode 100644 src/com/hotmail/kalebmarc/textfighter/farm/Seed.java delete mode 100755 src/com/hotmail/kalebmarc/textfighter/main/Property.java diff --git a/src/com/hotmail/kalebmarc/textfighter/farm/Crop.java b/src/com/hotmail/kalebmarc/textfighter/farm/Crop.java new file mode 100644 index 00000000..4cf941f6 --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/farm/Crop.java @@ -0,0 +1,65 @@ +package com.hotmail.kalebmarc.textfighter.farm; + +import com.hotmail.kalebmarc.textfighter.main.Ui; +import com.hotmail.kalebmarc.textfighter.player.Achievements; +import com.hotmail.kalebmarc.textfighter.player.Coins; +import com.hotmail.kalebmarc.textfighter.player.Stats; +import com.hotmail.kalebmarc.textfighter.player.Xp; + +import java.util.ArrayList; + +public class Crop { + public static final ArrayList cropArrayList = new ArrayList(); + + private String name; + private int sellPrice; + private Seed seed; + + private int owned = 0; + + public Crop(String name, int sellPrice, Seed seed, boolean firstInit, boolean changeDif) { + this.name = name; + this.sellPrice = sellPrice; + this.seed = seed; + + if (!changeDif) { + cropArrayList.add(this); + } + + if (firstInit) { + this.owned = 0; + } + } + + public void sell(int piecesSold){ + int totalPrice = sellPrice * piecesSold; + + Coins.set(totalPrice, true); + Stats.coinsGainedOnCrops += totalPrice; + this.owned -= piecesSold; + Ui.println("You have sold " + this.getName() + " (" + piecesSold + " bundles)" + " for " + totalPrice + " coins."); + Ui.println("You currently have " + this.owned + " bundles of " + this.getName()); + Ui.println("Coins: " + Coins.get()); + Ui.pause(); + } + + public static ArrayList getCrops() { + return cropArrayList; + } + public String getName() { + return name; + } + public int getSellPrice() { + return sellPrice; + } + public int getOwned() { + return owned; + } + public void setOwned(int owned, boolean add) { + if (add) { + this.owned += owned; + } else { + this.owned = owned; + } + } +} diff --git a/src/com/hotmail/kalebmarc/textfighter/farm/Farm.java b/src/com/hotmail/kalebmarc/textfighter/farm/Farm.java new file mode 100755 index 00000000..077c7c1b --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/farm/Farm.java @@ -0,0 +1,131 @@ +package com.hotmail.kalebmarc.textfighter.farm; + +import com.hotmail.kalebmarc.textfighter.main.Ui; +import com.hotmail.kalebmarc.textfighter.player.Achievements; +import com.hotmail.kalebmarc.textfighter.player.Coins; +import com.hotmail.kalebmarc.textfighter.player.Stats; +import com.hotmail.kalebmarc.textfighter.player.Xp; + +import java.util.ArrayList; + +public class Farm { + + public static final ArrayList arrayFarm = new ArrayList(); + + private String name; + private int price; + private int level; + private String description; + + private int fieldCount; + private ArrayList fields = new ArrayList(); + + private boolean owns; + + public Farm(String name, String description, int price, int level, int fieldCount, boolean firstInit, boolean changeDif) { + this.name = name; + this.price = price; + this.level = level; + this.description = description; + + this.fieldCount = fieldCount; + for (int i = 0; i < fieldCount; i++) { + fields.add(new Field()); + } + + if (!changeDif) { + arrayFarm.add(this); + } + + if (firstInit) { + this.owns = false; + } + } + + public static ArrayList getFarms() { + return arrayFarm; + } + public String getName() { + return name.toString(); + } + public int getPrice() { + return price; + } + public int getLevel() { + return level; + } + public int getFieldCount() { + return fieldCount; + } + public ArrayList getFields() { + return fields; + } + + public void menu() { + while (true) { + Ui.cls(); + Ui.printhr(); + Ui.println(Ui.getCentred("Welcome to " + name + "!")); + Ui.println(); + Ui.println("Fields:"); + for (int i = 0; i < fieldCount; i++) { + Ui.print((i + 1) + "): "); + + Seed seed = fields.get(i).getSeed(); + Ui.print("(" + ((seed == null) ? "No seeds planted)" : seed.getName() + ") - ")); + Ui.println((seed == null) ? "" : ((fields.get(i).getRemainingTime() > 0) ? fields.get(i).getRemainingTime() + " fights remaining until the harvest." : "Ready for harvest")); + } + Ui.println(); + Ui.println((fieldCount + 1) + ") Back"); + + int menuItem = Ui.getValidInt(); + if (menuItem == fieldCount + 1) { + Ui.cls(); + return; + } + + if (menuItem <= fieldCount) { + fields.get(menuItem - 1).menu(this, menuItem); + } else { + Ui.println(); + Ui.println(menuItem + " is not an option."); + Ui.cls(); + Ui.pause(); + } + } + } + + public boolean owns() { + return owns; + } + public void buy() { + if (this.owns()) { + Ui.msg("You already own this property."); + return; + } + if (level > Xp.getLevel()) { + Ui.msg("You do not have a high enough level to buy this item."); + return; + } + if (price > Coins.get()) { + Ui.msg("You do not have enough coins to buy this item."); + return; + } + + Achievements.boughtItem = true; + Coins.set(-price, true); + Stats.coinsSpentOnProperty += price; + this.owns = true; + Ui.println("You have bought a " + this.getName() + " for " + this.price + " coins."); + Ui.println("Coins: " + Coins.get()); + Ui.pause(); + + } + + public void updateFields() { + for (Field f : fields) { + f.updateCycle(); + } + } +} + diff --git a/src/com/hotmail/kalebmarc/textfighter/farm/Field.java b/src/com/hotmail/kalebmarc/textfighter/farm/Field.java new file mode 100644 index 00000000..b06c281d --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/farm/Field.java @@ -0,0 +1,130 @@ +package com.hotmail.kalebmarc.textfighter.farm; + +import com.hotmail.kalebmarc.textfighter.main.Random; +import com.hotmail.kalebmarc.textfighter.main.Ui; + +import java.util.ArrayList; + +public class Field { + private Seed seed; + private int remainingTime; + + public Seed getSeed() { + return seed; + } + + public void menu(Farm farm, int fieldNr) { + while (true) { + // int i = 1; + Ui.cls(); + Ui.printhr(); + Ui.println(Ui.getCentred("Field " + fieldNr + " (" + farm.getName() + ") ")); + Ui.print("(" + ((seed == null) ? "No seeds planted)" : seed.getName() + ") - ")); + Ui.println((seed == null) ? "" : ((this.getRemainingTime() > 0) ? this.getRemainingTime() + " fights remaining until the harvest." : "Ready for harvest")); + Ui.println(); +// Can you think of any way I could possibly make this work? I wanted to make the menu dynamic - display the harvest option only if the crops are ready for harvest - but I just can't come up with a universal and scalable way to solve this other than bunch of if-else statements, which is rather bulky and doesn't meet either specified requirement. +// if (remainingTime == 0) { +// Ui.println(i + ") Harvest"); +// i++; +// } +// Ui.println(i + ") Plant seeds"); +// i++; +// Ui.println(i + ") Back"); +// +// int menuItem = Ui.getValidInt(); +// int cond = i - menuItem; +// switch (cond) { +// case 0: +// return; +// case 1: +// if (remainingTime == 0) { +// // ... +// } +// } + Ui.println("1) Plant seeds"); + Ui.println("2) Harvest"); + Ui.println("3) Back"); + + int menuItem = Ui.getValidInt(); + + switch (menuItem) { + case 1: + plantSeed(); + return; + case 2: + harvest(); + case 3: + return; + default: + Ui.println("\"" + menuItem + "\" isn't a valid option."); + Ui.pause(); + } + } + } + + public void plantSeed() { + ArrayList validSeeds = new ArrayList<>(); + + Ui.cls(); + Ui.println("Which seeds would you like to plant?"); + Ui.println(); + for (int i = 0; i < Seed.getSeeds().size(); i++) { + Seed s = Seed.getSeeds().get(i); + if (s.getOwned() > 0) { + validSeeds.add(s); + Ui.println((i + 1) + ") " + s.getName()); + } + } + Ui.println((validSeeds.size() + 1) + ") Back"); + + int menuItem = Ui.getValidInt(); + if (menuItem == validSeeds.size() + 1) { + return; + } + Seed s = validSeeds.get(menuItem - 1); + + s.setOwned(-1, true); + this.seed = s; + remainingTime = s.getGrowthTime(); + + Ui.cls(); + Ui.println("You have planted " + s.getName() + " on this field."); + Ui.println("There are " + s.getOwned() + " bundles of " + s.getName() + " remaining in your inventory."); + Ui.pause(); + } + + public void harvest() { + if (seed == null) { + Ui.cls(); + Ui.println("No seeds have been planted yet!"); + Ui.pause(); + return; + } + if (remainingTime > 0) { + Ui.cls(); + Ui.println("The crops haven't fully matured yet!"); + Ui.pause(); + return; + } + + Crop c = seed.getCrop(); + int yield = Random.RInt(seed.getMinCrops(), seed.getMaxCrops()); + c.setOwned(yield, true); + this.seed = null; + + Ui.cls(); + Ui.println("The harvest has yielded " + yield + " bundles of " + c.getName() + "."); + Ui.println("You currently have " + c.getOwned() + " bundles of " + c.getName() + "."); + Ui.pause(); + } + + public void updateCycle() { + if (!(remainingTime <= 0)) { + remainingTime--; + } + } + + public int getRemainingTime() { + return remainingTime; + } +} diff --git a/src/com/hotmail/kalebmarc/textfighter/farm/Seed.java b/src/com/hotmail/kalebmarc/textfighter/farm/Seed.java new file mode 100644 index 00000000..df94cd92 --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/farm/Seed.java @@ -0,0 +1,124 @@ +package com.hotmail.kalebmarc.textfighter.farm; + +import com.hotmail.kalebmarc.textfighter.main.Ui; +import com.hotmail.kalebmarc.textfighter.player.Achievements; +import com.hotmail.kalebmarc.textfighter.player.Coins; +import com.hotmail.kalebmarc.textfighter.player.Stats; +import com.hotmail.kalebmarc.textfighter.player.Xp; + +import java.util.ArrayList; + +public class Seed { + public static final ArrayList seedArrayList = new ArrayList(); + + private String name; + private int price; + private int count; + private int level; + private String description; + private int growthTime; // in fights + private int minCrops; + private int maxCrops; + private Crop crop; + + private int owned = 0; + + public Seed(String name, int price, int count, int level, String description, int growthTime, int minCrops, int maxCrops, int cropSellPrice, boolean firstInit, boolean changeDif) { + this.name = name; + this.price = price; + this.count = count; + this.level = level; + this.description = description; + this.growthTime = growthTime; + this.minCrops = minCrops; + this.maxCrops = maxCrops; + this.crop = new Crop(name, cropSellPrice, this, firstInit, changeDif); + + if (!changeDif) { + seedArrayList.add(this); + } + + if (firstInit) { + this.owned = 0; + } + } + + public Seed(String name, int price, int count, int level, String description, int growthTime, int minCrops, int maxCrops, Crop crop, boolean firstInit, boolean changeDif) { + this.name = name; + this.price = price; + this.count = count; + this.level = level; + this.description = description; + this.growthTime = growthTime; + this.minCrops = minCrops; + this.maxCrops = maxCrops; + + if (!changeDif) { + seedArrayList.add(this); + } + + if (firstInit) { + this.owned = 0; + } + } + public void buy(int multiplier) { + int totalPrice = price * multiplier; + int totalBought = count * multiplier; + + if (level > Xp.getLevel()) { + Ui.msg("You do not have a high enough level to buy this item."); + return; + } + if (totalPrice > Coins.get()) { + Ui.msg("You do not have enough coins to buy this item."); + return; + } + + Achievements.boughtItem = true; + Coins.set(-totalPrice, true); + Stats.coinsSpentOnSeeds += price; + this.owned += totalBought; + Ui.println("You have bought " + this.getName() + " (" + totalBought + " bundles)" + " for " + totalPrice + " coins."); + Ui.println("You currently have " + this.owned + " bundles of " + this.getName()); + Ui.println("Coins: " + Coins.get()); + Ui.pause(); + } + + public static ArrayList getSeeds() { + return seedArrayList; + } + public String getName() { + return name; + } + public int getPrice() { + return price; + } + public int getLot() { + return count; + } + public int getLevel() { + return level; + } + public int getMinCrops() { + return minCrops; + } + public int getMaxCrops() { + return maxCrops; + } + public int getGrowthTime() { + return growthTime; + } + public int getOwned() { + return owned; + } + public void setOwned(int owned, boolean add) { + if (add) { + this.owned += owned; + } else { + this.owned = owned; + } + } + public Crop getCrop() { + return crop; + } +} \ No newline at end of file diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Game.java b/src/com/hotmail/kalebmarc/textfighter/main/Game.java index f086b77c..9ec7f996 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Game.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Game.java @@ -1,5 +1,9 @@ package com.hotmail.kalebmarc.textfighter.main; +import com.hotmail.kalebmarc.textfighter.farm.Farm; +import com.hotmail.kalebmarc.textfighter.farm.Field; +import com.hotmail.kalebmarc.textfighter.farm.Seed; +import com.hotmail.kalebmarc.textfighter.farm.Crop; import com.hotmail.kalebmarc.textfighter.item.*; import com.hotmail.kalebmarc.textfighter.player.*; import time.GameClock; @@ -46,13 +50,18 @@ public static boolean hadGameStarted() { public static Weapon rifle; public static Weapon sniper; - //Amours + //Armours public static Armour none = new Armour("None", 0, 0, 1);//DO NOT REMOVE public static Armour basic = new Armour("Basic", 400, 15, 5); public static Armour advanced = new Armour("Advanced", 750, 30, 7); //Properties - public static Property farm; + public static Farm farm; + + //Seeds + public static Seed wheat; + + //Crops //Food //TODO when the StatusEffect system is implemented, change effect types @@ -180,12 +189,19 @@ public void start() { if (fightPath <= 50) Enemy.get().dealDamage(); if (fightPath > 50) Weapon.get().dealDam(); } + + for (Farm f : Farm.getFarms()) { + for (Field fi : f.getFields()) { + fi.updateCycle(); + } + } break; case 2: home(); break; case 3: property(); + break; case 4: town(); break; @@ -367,27 +383,27 @@ private static void home() { private static void property() { Ui.println("Which property would you like to visit?"); Ui.println(); - ArrayList suitableProperties = new ArrayList(); - for (int i = 0; i < Property.getPropertyList().size(); i++) { - Property p = Property.getPropertyList().get(i); + ArrayList suitableFarms = new ArrayList(); + for (int i = 0; i < Farm.getFarms().size(); i++) { + Farm p = Farm.getFarms().get(i); if (p.owns()) { Ui.print((i + 1) + ") " + p.getName()); - suitableProperties.add(p); + Ui.println(); + suitableFarms.add(p); } } Ui.println(); - Ui.println((suitableProperties.size() + 1) + ") Back"); + Ui.println((suitableFarms.size() + 1) + ") Back"); - while(true) { - int menuItem = Ui.getValidInt(); - if (menuItem == suitableProperties.size() + 1) { - return; - } + int menuItem = Ui.getValidInt(); + if (menuItem == suitableFarms.size() + 1) { + return; + } - if (menuItem <= suitableProperties.size()) { - suitableProperties.get(menuItem -1).visit(); - } + if (menuItem <= suitableFarms.size()) { + suitableFarms.get(menuItem - 1).menu(); } + return; } private static String getDifficulty() { diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Help.java b/src/com/hotmail/kalebmarc/textfighter/main/Help.java index 991e3284..b8dccba5 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Help.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Help.java @@ -6,6 +6,7 @@ class Help { private Help() { } + // TODO Add property public static void view() { while (true) { Ui.cls(); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Property.java b/src/com/hotmail/kalebmarc/textfighter/main/Property.java deleted file mode 100755 index 012e348c..00000000 --- a/src/com/hotmail/kalebmarc/textfighter/main/Property.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.hotmail.kalebmarc.textfighter.main; - -import com.hotmail.kalebmarc.textfighter.item.FirstAid; -import com.hotmail.kalebmarc.textfighter.player.*; - -import java.util.ArrayList; - -public class Property { - -public static final ArrayList arrayProperty = new ArrayList(); - - private String name; - private int price; - private int level; - private String description; - private boolean owns; - - public Property(String name, int price, int level, String description, boolean firstInit, boolean changeDif) { - this.name = name; - this.price = price; - this.level = level; - this.description = description; - - if (!changeDif) { - arrayProperty.add(this); - } - - if (firstInit) { - this.owns = false; - } - } - - public static ArrayList getPropertyList() { - return arrayProperty; - } - public String getName() { - return name.toString(); - } - public int getPrice() { - return price; - } - public int getLevel() { - return level; - } - - public void visit() { - Ui.cls(); - Ui.printhr(); - Ui.println(Ui.getCentred("Welcome to the " + name + "!")); - Ui.printhr(); - Ui.pause(); - - } - - public boolean owns() { - return owns; - } - public void buy() { - if (this.owns()) { - Ui.msg("You already own this property."); - return; - } - if (level > Xp.getLevel()) { - Ui.msg("You are not a high enough level to buy this item."); - return; - } - if (price > Coins.get()) { - Ui.msg("You do not have enough coins to buy this item."); - return; - } - - Achievements.boughtItem = true; - Coins.set(-price, true); - Stats.coinsSpentOnProperty += price; - this.owns = true; - Ui.println("You have bought a " + this.getName() + " for " + this.price + " coins."); - Ui.println("Coins: " + Coins.get()); - Ui.pause(); - - } - - /* - private String name; - private String desc; - private Type type; - private int pricePerSqFt; - private int levelNeeded; - private final int MAX_SQ_FT = 100;//TODO Change this later. Not sure how the SqFt thing is going to work yet. - - private int sqFtOwned; - - public void setName(String name){ - this.name = name; - } - public String getName(){ - return this.name; - } - public void setDesc(String desc){ - this.desc = desc; - } - public String getDesc(){ - return this.desc; - } - public void setType(Type type){ - this.type = type; - } - public Type getType(){ - return this.type; - } - public void setPricePerSqFt(int pricePerSqFt){ - this.pricePerSqFt = pricePerSqFt; - } - public int getPricePerSqFt(){ - return this.pricePerSqFt; - } - public void setLevelNeeded(int levelNeeded){ - this.levelNeeded = levelNeeded; - } - public int getLevelNeeded(){ - return this.levelNeeded; - } - public void setSqFtOwned(int sqFtOwned){ - if (sqFtOwned > MAX_SQ_FT){ - this.sqFtOwned = MAX_SQ_FT; - } else { - this.sqFtOwned = sqFtOwned; - } - } - public int getSqFtOwned(){ - return this.sqFtOwned; - } - public static void buyProperty(){ - - } - - public enum Type{ - CROP_FIELD, - ORCHARD, - RIVER; - - @Override - public String toString() { - switch(super.toString()){ - case "CROP_FIELD": - return "Crop Field"; - case "ORCHARD": - return "Orchard"; - case "RIVER": - return "River"; - default: - Handle.error("Unknown Property Type: " + super.toString()); - return null; - } - } - } */ -} - diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Shop.java b/src/com/hotmail/kalebmarc/textfighter/main/Shop.java index 1cb12460..b2557b93 100755 --- a/src/com/hotmail/kalebmarc/textfighter/main/Shop.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Shop.java @@ -1,5 +1,8 @@ package com.hotmail.kalebmarc.textfighter.main; +import com.hotmail.kalebmarc.textfighter.farm.Crop; +import com.hotmail.kalebmarc.textfighter.farm.Farm; +import com.hotmail.kalebmarc.textfighter.farm.Seed; import com.hotmail.kalebmarc.textfighter.item.Armour; import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; @@ -30,8 +33,10 @@ public static void menu() { Ui.println("2) Weapons/Ammo"); Ui.println("3) Body Armour"); Ui.println("4) Property"); - Ui.println("5) XP"); - Ui.println("6) Back"); + Ui.println("5) Seeds"); + Ui.println("6) Crops"); + Ui.println("7) XP"); + Ui.println("8) Back"); Ui.println("-------------------------------------------------------------------"); switch (Ui.getValidInt()) { case 1: @@ -47,9 +52,15 @@ public static void menu() { property(); break; case 5: - xp(); + seeds(); break; case 6: + crops(); + break; + case 7: + xp(); + break; + case 8: return; default: break; @@ -291,7 +302,6 @@ private static void buyAmmo() { private static void property(){ while (true){ - Ui.cls(); Ui.println("________________________________________________"); Ui.println(" Property "); @@ -300,37 +310,122 @@ private static void property(){ Ui.println("Coins: " + Coins.get()); Ui.println("________________________________________________"); - for (int i = 0; i < Property.getPropertyList().size(); i++) { - Property p = Property.getPropertyList().get(i); + for (int i = 0; i < Farm.getFarms().size(); i++) { + Farm p = Farm.getFarms().get(i); Ui.println((i + 1) + ") " + p.getName()); Ui.println(" Price: " + p.getPrice()); Ui.println(" Level: " + p.getLevel()); + Ui.println(" Field count: " + p.getFieldCount()); + Ui.println(); } Ui.println(); - Ui.println((Property.getPropertyList().size() + 1) + ") Back"); - buyProperty(); - return; + Ui.println((Farm.getFarms().size() + 1) + ") Back"); + + int size = Farm.getFarms().size(); + + int menuItem = Ui.getValidInt(); + if (menuItem == size + 1) { + Ui.cls(); + return; + } + + if (menuItem <= size) { + Farm.getFarms().get(menuItem - 1).buy(); + return; + } else { + Ui.println(); + Ui.println(menuItem + " is not an option."); + Ui.cls(); + Ui.pause(); + } } } - private static void buyProperty() { - int size = Property.getPropertyList().size(); - int menuItem = Ui.getValidInt(); - if (menuItem == size + 1) { + public static void seeds() { + while (true){ Ui.cls(); - return; + Ui.printhr(); + Ui.println(Ui.getCentred("Seeds")); + NPC.welcome("seeds"); + Ui.println("Level: " + Xp.getLevel()); + Ui.println("Coins: " + Coins.get()); + Ui.printhr(); + + for (int i = 0; i < Seed.getSeeds().size(); i++) { + Seed s = Seed.getSeeds().get(i); + Ui.println((i + 1) + ") " + s.getName()); + Ui.println(" Price per lot: " + s.getPrice()); + Ui.println(" Pieces per lot: " + s.getLot()); + Ui.println(" Level: " + s.getLevel()); + Ui.println(" Growth time (in fights): " + s.getGrowthTime()); + Ui.println(" Minimal crop yield: " + s.getMinCrops()); + Ui.println(" Maximal crop yield: " + s.getMaxCrops()); + Ui.println(); + } + Ui.println(); + Ui.println((Farm.getFarms().size() + 1) + ") Back"); + + int size = Seed.getSeeds().size(); + + int menuItem = Ui.getValidInt(); + if (menuItem == size + 1) { + Ui.cls(); + return; + } + + if (menuItem <= size) { + Ui.cls(); + Ui.println("How many lots would you like to buy?"); + int multiplier = Ui.getValidInt(); + Seed.getSeeds().get(menuItem - 1).buy(multiplier); + return; + } else { + Ui.println(); + Ui.println(menuItem + " is not an option."); + Ui.cls(); + Ui.pause(); + } } + } - if (menuItem <= size) { - Property.getPropertyList().get(menuItem - 1).buy(); - // NPC.gratitude("Property", "purchase"); // TODO Add property shop - property(); - } else { - Ui.println(); - Ui.println(menuItem + " is not an option."); + private static void crops() { + while (true) { Ui.cls(); - Ui.pause(); - property(); + Ui.printhr(); + Ui.println(Ui.getCentred("Sell Crops")); + Ui.println(); + + for (int i = 0; i < Crop.getCrops().size(); i++) { + Crop c = Crop.getCrops().get(i); + Ui.println((i + 1) + ") " + c.getName()); + Ui.println(" Sell price: " + c.getSellPrice()); + Ui.println(); + } + Ui.println(); + Ui.println((Crop.getCrops().size() + 1) + ") Back"); + + int size = Crop.getCrops().size(); + + int menuItem = Ui.getValidInt(); + if (menuItem == size + 1) { + Ui.cls(); + return; + } + + if (menuItem <= size) { + Crop c = Crop.getCrops().get(menuItem - 1); + + Ui.cls(); + Ui.println("How many bundles would you like to sell?"); + Ui.println("You currently have " + c.getOwned() + " bundles of " + c.getName() + "."); + int multiplier = Ui.getValidInt(); + c.sell(multiplier); + } else { + Ui.println(); + Ui.println(menuItem + " is not an option."); + Ui.cls(); + Ui.pause(); + } } } diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Settings.java b/src/com/hotmail/kalebmarc/textfighter/player/Settings.java index 87575d59..aaeb9e37 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Settings.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Settings.java @@ -1,5 +1,7 @@ package com.hotmail.kalebmarc.textfighter.player; +import com.hotmail.kalebmarc.textfighter.farm.Farm; +import com.hotmail.kalebmarc.textfighter.farm.Seed; import com.hotmail.kalebmarc.textfighter.item.FirstAid; import com.hotmail.kalebmarc.textfighter.item.InstaHealth; import com.hotmail.kalebmarc.textfighter.item.Power; @@ -172,7 +174,18 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi Game.sniper = new Weapon("Sniper", 1, 10, true, 700, 2, 7, 0, 1, 7, 10, firstInit, changeDif); //Properties - Game.farm = new Property("Farm", 200, 10, "A farm", firstInit, changeDif); + Game.farm = new Farm("Farm", "A farm", 500, 10, 2, firstInit, changeDif); + + //Seeds + // Generates crop with the same name + // Seed(String name, int price, int count, int level, String description, int growthTime, int minCrops, int maxCrops, int cropSellPrice, boolean firstInit, boolean changeDif) + // Requires a separately generated crop + // Seed(String name, int price, int count, int level, String description, int growthTime, int minCrops, int maxCrops, Crop crop, boolean firstInit, boolean changeDif) + + Game.wheat = new Seed("Wheat", 20, 3, 10, "Plain old wheat.", 10, 3, 6, 20, firstInit, changeDif); + + //Crops + // Crop(String name, int sellPrice, Seed seed, boolean firstInit, boolean changeDif) //Price Power.price = 25; @@ -226,7 +239,19 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi Game.sniper = new Weapon("Sniper", 1, 10, true, 750, 2, 7, 0, .75, 7, 9, firstInit, changeDif); //Properties - Game.farm = new Property("Farm", 200, 10, "A farm", firstInit, changeDif); + // Farm(String name, String description, int price, int level, int fieldCount, boolean firstInit, boolean changeDif) + Game.farm = new Farm("Farm", "Simply a farm.", 200, 10, 2, firstInit, changeDif); + + //Seeds + // Generates crop with the same name + // Seed(String name, int price, int count, int level, String description, int growthTime, int minCrops, int maxCrops, int cropSellPrice, boolean firstInit, boolean changeDif) + // Requires a separately generated crop + // Seed(String name, int price, int count, int level, String description, int growthTime, int minCrops, int maxCrops, Crop crop, boolean firstInit, boolean changeDif) + + Game.wheat = new Seed("Wheat", 20, 3, 10, "Plain old wheat.", 10, 3, 6, 20, firstInit, changeDif); + + //Crops + // Crop(String name, int sellPrice, Seed seed, boolean firstInit, boolean changeDif) //PRICE Power.price = 75; @@ -254,11 +279,11 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi private static void newGameSetup() { - Coins.set(50000, false); + Coins.set(50, false); FirstAid.set(3, false); Potion.set("survival", 2, false); Potion.set("recovery", 2, false); - Xp.setAll(0, 500, 100); + Xp.setAll(0, 500, 1); Game.none.setOwns(true); Game.none.equipSilent(); diff --git a/src/com/hotmail/kalebmarc/textfighter/player/Stats.java b/src/com/hotmail/kalebmarc/textfighter/player/Stats.java index fee6772b..a0d1a65d 100644 --- a/src/com/hotmail/kalebmarc/textfighter/player/Stats.java +++ b/src/com/hotmail/kalebmarc/textfighter/player/Stats.java @@ -17,6 +17,8 @@ public class Stats { public static int totalCoinsSpent; public static int coinsSpentOnWeapons; public static int coinsSpentOnProperty; + public static int coinsSpentOnSeeds; + public static int coinsGainedOnCrops; public static int coinsSpentOnHealth; public static int coinsSpentOnBankInterest; public static int xpBought; @@ -63,6 +65,8 @@ public static void view() { Ui.println(" Coins spent on bank interest - " + coinsSpentOnBankInterest); Ui.println(" Coins spent on weapons - " + coinsSpentOnWeapons); Ui.println(" Coins spent on buying property - " + coinsSpentOnProperty); + Ui.println(" Coins spent on buying seeds - " + coinsSpentOnSeeds); + Ui.println(" Coins gained on selling crops - " + coinsGainedOnCrops); Ui.println(" Coins spent on health - " + coinsSpentOnHealth); Ui.println(" XP bought - " + xpBought); Ui.println(); From 500ba72880a3508ef72f9f120542d2a8b6168065 Mon Sep 17 00:00:00 2001 From: R1ndT Date: Mon, 27 Dec 2021 11:42:21 +0100 Subject: [PATCH 5/7] Added the new items to help menu --- .../kalebmarc/textfighter/farm/Crop.java | 12 ++ .../kalebmarc/textfighter/farm/Farm.java | 15 ++ .../kalebmarc/textfighter/farm/Seed.java | 18 +++ .../kalebmarc/textfighter/main/Help.java | 132 +++++++++++++++++- 4 files changed, 170 insertions(+), 7 deletions(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/farm/Crop.java b/src/com/hotmail/kalebmarc/textfighter/farm/Crop.java index 4cf941f6..ac49a54e 100644 --- a/src/com/hotmail/kalebmarc/textfighter/farm/Crop.java +++ b/src/com/hotmail/kalebmarc/textfighter/farm/Crop.java @@ -62,4 +62,16 @@ public void setOwned(int owned, boolean add) { this.owned = owned; } } + + public void viewAbout() { + Ui.cls(); + Ui.printhr(); + Ui.println(Ui.getCentred(this.name.toUpperCase())); + Ui.println(); + Ui.println("Sell price: " + this.sellPrice + " coins"); + Ui.println("Seed: " + this.seed.getName()); + + Ui.printhr(); + Ui.pause(); + } } diff --git a/src/com/hotmail/kalebmarc/textfighter/farm/Farm.java b/src/com/hotmail/kalebmarc/textfighter/farm/Farm.java index 077c7c1b..1504da07 100755 --- a/src/com/hotmail/kalebmarc/textfighter/farm/Farm.java +++ b/src/com/hotmail/kalebmarc/textfighter/farm/Farm.java @@ -7,6 +7,7 @@ import com.hotmail.kalebmarc.textfighter.player.Xp; import java.util.ArrayList; +import java.util.Locale; public class Farm { @@ -127,5 +128,19 @@ public void updateFields() { f.updateCycle(); } } + + public void viewAbout() { + Ui.cls(); + Ui.printhr(); + Ui.println(Ui.getCentred(this.name.toUpperCase())); + Ui.println(Ui.getCentred(this.description)); + Ui.println(); + Ui.println("Price: " + this.price + " coins"); + Ui.println("Required level: " + this.level); + Ui.println("Number of fields: " + this.fieldCount); + + Ui.printhr(); + Ui.pause(); + } } diff --git a/src/com/hotmail/kalebmarc/textfighter/farm/Seed.java b/src/com/hotmail/kalebmarc/textfighter/farm/Seed.java index df94cd92..de6586ec 100644 --- a/src/com/hotmail/kalebmarc/textfighter/farm/Seed.java +++ b/src/com/hotmail/kalebmarc/textfighter/farm/Seed.java @@ -121,4 +121,22 @@ public void setOwned(int owned, boolean add) { public Crop getCrop() { return crop; } + + public void viewAbout() { + Ui.cls(); + Ui.printhr(); + Ui.println(Ui.getCentred(this.name.toUpperCase())); + Ui.println(Ui.getCentred(this.description)); + Ui.println(); + Ui.println("Price: " + this.price + " coins"); + Ui.println("Required level: " + this.level); + Ui.println("Bundles per lot: " + this.count); + Ui.println("Growth time: " + this.growthTime); + Ui.println("Crop: " + this.crop.getName()); + Ui.println("Minimal yield: " + this.minCrops); + Ui.println("Maximal yield: " + this.maxCrops); + + Ui.printhr(); + Ui.pause(); + } } \ No newline at end of file diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Help.java b/src/com/hotmail/kalebmarc/textfighter/main/Help.java index b8dccba5..79ecc3ee 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Help.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Help.java @@ -1,5 +1,8 @@ package com.hotmail.kalebmarc.textfighter.main; +import com.hotmail.kalebmarc.textfighter.farm.Crop; +import com.hotmail.kalebmarc.textfighter.farm.Farm; +import com.hotmail.kalebmarc.textfighter.farm.Seed; import com.hotmail.kalebmarc.textfighter.item.Armour; class Help { @@ -20,10 +23,13 @@ public static void view() { Ui.println("3) Weapon"); Ui.println("4) Health"); Ui.println("5) Food"); - Ui.println("6) XP"); - Ui.println("7) Cheats"); - Ui.println("8) Achievements"); - Ui.println("9) Back"); + Ui.println("6) Property"); + Ui.println("7) Seeds"); + Ui.println("8) Crops"); + Ui.println("9) XP"); + Ui.println("10) Cheats"); + Ui.println("11) Achievements"); + Ui.println("12) Back"); Ui.println("------------------------------------------------------------"); switch (Ui.getValidInt()) { case 1: @@ -42,16 +48,27 @@ public static void view() { info_food(); break; case 6: - info_xp(); + info_property(); break; case 7: - info_cheats(); + info_seeds(); break; case 8: - info_achs(); + info_crops(); break; case 9: + info_xp(); + break; + case 10: + info_cheats(); + break; + case 11: + info_achs(); + break; + case 12: return; + default: + break; } } } @@ -194,6 +211,107 @@ private static void info_food() { } } + private static void info_property() { + while (true) { + int size = Farm.getFarms().size(); + + Ui.cls(); + Ui.printhr(); + Ui.println(Ui.getCentred("PROPERTY INFO")); + Ui.println("Which property would you like to know about?"); + Ui.println(); + Ui.println("Farms:"); + for (int i = 0; i < size; i++) { + Ui.println(i + 1 + ") " + Farm.getFarms().get(i).getName()); + } + Ui.println(); + Ui.println((size + 1) + ") Back"); + + int menuItem = Ui.getValidInt(); + + if (menuItem == size + 1) { + return; + } + + if (menuItem <= size) { + Farm.getFarms().get(menuItem - 1).viewAbout(); + } else { + Ui.println(); + Ui.println(menuItem + " is not an option."); + Ui.cls(); + Ui.pause(); + } + } + } + + private static void info_seeds() { + while (true) { + int size = Seed.getSeeds().size(); + + Ui.cls(); + Ui.printhr(); + Ui.println(Ui.getCentred("SEED INFO")); + Ui.println("Which seed would you like to know about?"); + Ui.println(); + Ui.println("Seeds:"); + for (int i = 0; i < size; i++) { + Ui.println(i + 1 + ") " + Seed.getSeeds().get(i).getName()); + } + Ui.println(); + Ui.println((size + 1) + ") Back"); + + int menuItem = Ui.getValidInt(); + + if (menuItem == size + 1) { + return; + } + + if (menuItem <= size) { + Seed.getSeeds().get(menuItem - 1).viewAbout(); + } else { + Ui.println(); + Ui.println(menuItem + " is not an option."); + Ui.cls(); + Ui.pause(); + } + } + } + + private static void info_crops() { + while (true) { + int size = Crop.getCrops().size(); + + Ui.cls(); + Ui.printhr(); + Ui.println(Ui.getCentred("CROP INFO")); + Ui.println("Which crop would you like to know about?"); + Ui.println(); + Ui.println("Crops:"); + for (int i = 0; i < size; i++) { + Ui.println(i + 1 + ") " + Crop.getCrops().get(i).getName()); + } + Ui.println(); + Ui.println((size + 1) + ") Back"); + + int menuItem = Ui.getValidInt(); + + if (menuItem == size + 1) { + return; + } + + if (menuItem <= size) { + Crop.getCrops().get(menuItem - 1).viewAbout(); + } else { + Ui.println(); + Ui.println(menuItem + " is not an option."); + Ui.cls(); + Ui.pause(); + } + } + } + + + private static void info_xp() { Ui.cls(); Ui.println("------------------------------------------------------------"); From f718b7aad0a3c1285be662a7e9b4a8520803156f Mon Sep 17 00:00:00 2001 From: R1ndT Date: Mon, 27 Dec 2021 11:45:29 +0100 Subject: [PATCH 6/7] Small fix --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 73199da1..83c2f8e3 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ mainClassName = 'com.hotmail.kalebmarc.textfighter.main.Start' jar{ manifest{ attributes( - "Main-Class": mainClassName + "Main-Class": mainClassName ) } } From 9088590e5956741e3cf825c6fbfd658e82f54b48 Mon Sep 17 00:00:00 2001 From: R1ndT Date: Mon, 27 Dec 2021 14:05:51 +0100 Subject: [PATCH 7/7] Valid implementation of unused function (minor fix) --- src/com/hotmail/kalebmarc/textfighter/main/Game.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Game.java b/src/com/hotmail/kalebmarc/textfighter/main/Game.java index 9ec7f996..5f1099ee 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Game.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Game.java @@ -191,9 +191,7 @@ public void start() { } for (Farm f : Farm.getFarms()) { - for (Field fi : f.getFields()) { - fi.updateCycle(); - } + f.updateFields(); } break; case 2: