From 1576a0272c4cc3711810d64cc31c43e2b36544c3 Mon Sep 17 00:00:00 2001 From: Freddy Date: Sat, 12 Nov 2022 09:24:58 -0500 Subject: [PATCH 01/16] Added pom, hamurabi, and hamurabitest --- .idea/.gitignore | 3 ++ .idea/compiler.xml | 16 ++++++++++ .idea/jarRepositories.xml | 20 +++++++++++++ .idea/libraries/Maven__junit_junit_4_13_2.xml | 13 ++++++++ ..._org_apiguardian_apiguardian_api_1_1_2.xml | 13 ++++++++ .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 ++++++++ ..._org_junit_jupiter_junit_jupiter_5_9_1.xml | 13 ++++++++ ..._junit_jupiter_junit_jupiter_api_5_9_1.xml | 13 ++++++++ ...nit_jupiter_junit_jupiter_engine_5_9_1.xml | 13 ++++++++ ...nit_jupiter_junit_jupiter_params_5_9_1.xml | 13 ++++++++ ..._platform_junit_platform_commons_1_9_1.xml | 13 ++++++++ ...t_platform_junit_platform_engine_1_9_1.xml | 13 ++++++++ ...Maven__org_opentest4j_opentest4j_1_2_0.xml | 13 ++++++++ .idea/misc.xml | 13 ++++++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 7 +++++ Hamurabi.iml | 25 ++++++++++++++++ pom.xml | 30 +++++++++++++++++++ src/main/java/Hamurabi.java | 23 ++++++++++++++ src/test/java/HamurabiTest.java | 16 ++++++++++ 20 files changed, 291 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/libraries/Maven__junit_junit_4_13_2.xml create mode 100644 .idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_9_1.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_9_1.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_9_1.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_9_1.xml create mode 100644 .idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_9_1.xml create mode 100644 .idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_9_1.xml create mode 100644 .idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Hamurabi.iml create mode 100644 pom.xml create mode 100644 src/main/java/Hamurabi.java create mode 100644 src/test/java/HamurabiTest.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..cc644d4 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_13_2.xml b/.idea/libraries/Maven__junit_junit_4_13_2.xml new file mode 100644 index 0000000..606c352 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_13_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml new file mode 100644 index 0000000..6ac1c42 --- /dev/null +++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_9_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_9_1.xml new file mode 100644 index 0000000..182f93a --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_9_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_9_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_9_1.xml new file mode 100644 index 0000000..f88d0a9 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_9_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_9_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_9_1.xml new file mode 100644 index 0000000..7d13c06 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_9_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_9_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_9_1.xml new file mode 100644 index 0000000..1cbbb38 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_9_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_9_1.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_9_1.xml new file mode 100644 index 0000000..79aa3d3 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_9_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_9_1.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_9_1.xml new file mode 100644 index 0000000..31a3ca5 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_9_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml new file mode 100644 index 0000000..fbc1b16 --- /dev/null +++ b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0f8e7ab --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..16ae36c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..8306744 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Hamurabi.iml b/Hamurabi.iml new file mode 100644 index 0000000..679a871 --- /dev/null +++ b/Hamurabi.iml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3c17dce --- /dev/null +++ b/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + groupId + Hamurabi + 1.0-SNAPSHOT + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + junit + junit + 4.13.2 + test + + + + 19 + 19 + + + + \ No newline at end of file diff --git a/src/main/java/Hamurabi.java b/src/main/java/Hamurabi.java new file mode 100644 index 0000000..9557039 --- /dev/null +++ b/src/main/java/Hamurabi.java @@ -0,0 +1,23 @@ +public class Hamurabi { + + //Field: + //-Year of game ( 1-11) + //-Scanner for land trading (+ to buy, - to sell) + //-Scanner for population feeding (20 bushels per population) + //-Scanner for farming (10 lands per population) + + //Methods: + //-Game over (1/3 population died / < 7 lands per population) + //-Bad ending ( >10% population died / 7<>9 lands per population) + //-Normal ending (10%<>3% population died / 9<>10 lands per population) + //-Good ending ( <3% population died / >10 lands per population) + // + //Always get the worst ending between two outcomes + + Hamurabi() { + + } + public String someTest() { + return "this is a test"; + } +} diff --git a/src/test/java/HamurabiTest.java b/src/test/java/HamurabiTest.java new file mode 100644 index 0000000..4924ec9 --- /dev/null +++ b/src/test/java/HamurabiTest.java @@ -0,0 +1,16 @@ +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.junit.Assert.*; + +public class HamurabiTest { + + Hamurabi hamurabi = new Hamurabi(); + + @Test + public void someTestTest() { + String expected = "this is a test"; + String actual = hamurabi.someTest(); + + Assert.assertEquals(expected, actual); + } +} From 4a18b9f7145ba0a812342766e86e22e622960be3 Mon Sep 17 00:00:00 2001 From: Freddy Date: Sat, 12 Nov 2022 10:48:42 -0500 Subject: [PATCH 02/16] Checkpoint --- HammurabiTest.java | 4 +- src/main/java/Hammurabi.java | 83 +++++++++++++++++++++ src/main/java/Hamurabi.java | 23 ------ src/test/java/HammurabiTest.java | 123 +++++++++++++++++++++++++++++++ src/test/java/HamurabiTest.java | 16 ---- 5 files changed, 207 insertions(+), 42 deletions(-) create mode 100644 src/main/java/Hammurabi.java delete mode 100644 src/main/java/Hamurabi.java create mode 100644 src/test/java/HammurabiTest.java delete mode 100644 src/test/java/HamurabiTest.java diff --git a/HammurabiTest.java b/HammurabiTest.java index 5cf1cc9..de9fa7d 100644 --- a/HammurabiTest.java +++ b/HammurabiTest.java @@ -1,5 +1,3 @@ -package hammurabi; - import static org.junit.Assert.*; import org.junit.Before; @@ -8,7 +6,7 @@ public class HammurabiTest { Hammurabi ham; - + boolean about(double expected, double actual) { return actual > 0.90 * expected && actual < 1.10 * expected; } diff --git a/src/main/java/Hammurabi.java b/src/main/java/Hammurabi.java new file mode 100644 index 0000000..6f000c8 --- /dev/null +++ b/src/main/java/Hammurabi.java @@ -0,0 +1,83 @@ +import java.util.*; + +public class Hammurabi { + public static void main(String[] args) { + + } + + Random random = new Random(); + int randomNum = random.nextInt(); + Scanner scanner = new Scanner (System.in); + + public Hammurabi() { + + } + + public int askHowManyAcresToBuy(int price, int bushels){ + return 0; + } + + public int askHowManyAcresToSell(int acresOwned) { + return 0; + } + + public int askHowMuchGrainToFeedPeople(int bushels) { + return 0; + } + + public int askHowManyAcresToPlant(int acresOwned, int population, int bushels) { + return 0; + } + + public void printSummary() { + //String + } + + public void finalSummary() { + //String + } + + public void playGame() { + //int + } + + public int plagueDeaths(int population) { + return 0; + } + + public int starvationDeaths(int population, int bushelsFedToPeople) { + return 0; + } + + public boolean uprising(int population, int howManyPeopleStarved) { + return true; + } + + public int immigrants (int population, int acresOwned, int grainInStorage) { + return 0; + } + + public int harvest (int bushelsUsedAsSeed) { + return 0; + } + + public int grainEatenByRats (int bushels) { + return random.nextInt(21)+10; + } + + public int newCostOfLand() { + return random.nextInt(7)+17; + } + + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +} diff --git a/src/main/java/Hamurabi.java b/src/main/java/Hamurabi.java deleted file mode 100644 index 9557039..0000000 --- a/src/main/java/Hamurabi.java +++ /dev/null @@ -1,23 +0,0 @@ -public class Hamurabi { - - //Field: - //-Year of game ( 1-11) - //-Scanner for land trading (+ to buy, - to sell) - //-Scanner for population feeding (20 bushels per population) - //-Scanner for farming (10 lands per population) - - //Methods: - //-Game over (1/3 population died / < 7 lands per population) - //-Bad ending ( >10% population died / 7<>9 lands per population) - //-Normal ending (10%<>3% population died / 9<>10 lands per population) - //-Good ending ( <3% population died / >10 lands per population) - // - //Always get the worst ending between two outcomes - - Hamurabi() { - - } - public String someTest() { - return "this is a test"; - } -} diff --git a/src/test/java/HammurabiTest.java b/src/test/java/HammurabiTest.java new file mode 100644 index 0000000..de9fa7d --- /dev/null +++ b/src/test/java/HammurabiTest.java @@ -0,0 +1,123 @@ +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class HammurabiTest { + + Hammurabi ham; + + boolean about(double expected, double actual) { + return actual > 0.90 * expected && actual < 1.10 * expected; + } + + @Before + public void setUp() throws Exception { + ham = new Hammurabi(); + } + + @Test + public final void testPlagueDeaths1() { + int number_of_plagues = 0; + for (int i = 0; i < 10000; i++) { + int deaths = ham.plagueDeaths(100); + if (deaths > 0) { + number_of_plagues += 1; + } + } + int percentPlagues = number_of_plagues / 100; + assertTrue("Number of plagues is about " + percentPlagues + ", not about 15%.", + about(1500, number_of_plagues)); + } + + @Test + public final void testPlagueDeaths2() { + int deaths = 0; + for (int i = 0; i < 10000; i++) { + deaths = ham.plagueDeaths(100); + if (deaths > 0) break; + } + assertEquals("In a plague, " + deaths + "% of your people die, not 50%.", + 50, deaths); + } + + @Test + public final void testStarvationDeaths() { + int deaths = ham.starvationDeaths(100, 1639); + assertEquals("Wrong number of starvations deaths.", 19, deaths); + deaths = ham.starvationDeaths(100, 2500); + if (deaths < 0) { + fail("You starved a negative number of people!"); + } + } + + @Test + public final void testUprising() { + assertTrue("Should have had an uprising!", ham.uprising(1000, 451)); + assertFalse("Should not have had an uprising!", ham.uprising(1000, 449)); + } + + @Test + public final void testImmigrants() { + int imm = ham.immigrants(10, 1200, 500); + assertEquals("Wrong number of immigrants.", 25, imm); + } + + @Test + public final void testHarvest() { + int[] yield = new int[7]; + for (int i = 0; i < 1000; i++) { + int harvest = ham.harvest(1); + assertTrue("Illegal harvest per acre: " + harvest, harvest > 0 && harvest <= 6); + yield[harvest] += 1; + } + for (int j = 1; j <= 6; j++) { + assertTrue("You never have a yield of " + j + " bushels per acre.", yield[j] > 0); + } + } + + @Test + public final void testGrainEatenByRats1() { + int infestations = 0; + for (int i = 0; i < 1000; i++) { + int eaten = ham.grainEatenByRats(100); + if (eaten > 0) { + infestations += 1; + } + } + int percentInfestations = infestations / 100; + assertTrue("Number of rat infestations is about " + percentInfestations + + ", not about 40%.", about(400, infestations)); + } + + @Test + public final void testGrainEatenByRats2() { + int percent = 0; + int[] counts = new int[31]; + for (int i = 0; i < 10000; i++) { + percent = ham.grainEatenByRats(100); + if (percent == 0) continue; + counts[percent] += 1; + assertTrue("Rats ate " + percent + "% of your grain, not 10% to 30%.", + percent >= 10 && percent <= 30); + } + for (int j = 11; j < 30; j++) { + assertTrue("Rats never ate " + j + "% of your grain.", counts[j] > 0); + } + } + + @Test + public final void testNewCostOfLand() { + int[] cost = new int[24]; + for (int i = 0; i < 1000; i++) { + int price = ham.newCostOfLand(); + assertTrue("Illegal cost of land: " + price, price >= 17 && price <= 23); + cost[price] += 1; + } + for (int j = 17; j <= 23; j++) { + assertTrue("You never have a land cost of " + j + " bushels per acre.", cost[j] > 0); + } + } + +} + diff --git a/src/test/java/HamurabiTest.java b/src/test/java/HamurabiTest.java deleted file mode 100644 index 4924ec9..0000000 --- a/src/test/java/HamurabiTest.java +++ /dev/null @@ -1,16 +0,0 @@ -import org.junit.Assert; -import org.junit.jupiter.api.Test; -import org.junit.Assert.*; - -public class HamurabiTest { - - Hamurabi hamurabi = new Hamurabi(); - - @Test - public void someTestTest() { - String expected = "this is a test"; - String actual = hamurabi.someTest(); - - Assert.assertEquals(expected, actual); - } -} From 3786f78c5532bdafa456a86196ab2a49f43b33cc Mon Sep 17 00:00:00 2001 From: Emory Date: Sat, 12 Nov 2022 18:30:03 -0500 Subject: [PATCH 03/16] FREDDY CHECK THIS ONE OUT WHAT DO YOU THINK --- .DS_Store | Bin 0 -> 6148 bytes .idea/.DS_Store | Bin 0 -> 6148 bytes src/.DS_Store | Bin 0 -> 6148 bytes src/main/java/Hammurabi.java | 123 +++++++++++++++++++++++++++++-- src/test/java/HammurabiTest.java | 9 +++ 5 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 .DS_Store create mode 100644 .idea/.DS_Store create mode 100644 src/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a78b4e19997471ff4cee0110e1b34fb0c24d5477 GIT binary patch literal 6148 zcmeHKJxc>Y5S>j)XOBxF9=3$s4=^z8OoxV`>SwqReY-&_|f0)AupBXDQbrAf%%-n8qIoX_3d zeSdiUT=zV`U|yCFcqzx!RHg}CP&Z_)Z!9uC=j`tOML4C;Uu!WN@*Odsnkt|Qr~+RV zz@E)kS$C+TDxeCe0&@lU`w+t!6T#e}{d8ckM*v`iur*xsFD3WHf{9@65E+?*;@;Xtbm@j~dVD1nRnEnV@ L8FWwuepP`FURi%! literal 0 HcmV?d00001 diff --git a/.idea/.DS_Store b/.idea/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c9ee709095ecf23f9dde3a36c83b64cd9815b0e6 GIT binary patch literal 6148 zcmeHKOG*SW5UtW#w7Qv%;4)X38)Sy|1akpxXHcPs9u)VvfmiS-E8feZohLxn9OraH*R-bF{<4zjFHXtc z52(kkJM4XD|Fh-Au-V#{k6-Fuo1tyHe&}Fr)`zc;&-YLBuRK@Z^xR(UuKa*>A;CZ} z5DWwZ!N89)fIC~HIWmks7zhS}fe!}cd`M`5*|8Yv(Sc4&0H8dhRiH~PAu-7@I~GG& zAZ(#P3uP}c*upWN+%G#8LklPN;)8wV_u_?hb>vU#PMi&+4+esPF$4QHoXY)wieIK$ zbkX4A@jL+@PySHKncP=Mz{L?hM-2SYtN(CHNb zSir4@vHsfvBOSmx;a~_4ELbSeLPNS@1Pg~hrge3~!O+4bXlCq_GQVG5f@X(5>T(IS zq4%zUE08O&XVZ%H{}`XlM&}dvYZ~((t mOEFMOF(y1m4wN)LatyvsI2dvl`ZXNrKLRRDDVbyOG&o? literal 0 HcmV?d00001 diff --git a/src/main/java/Hammurabi.java b/src/main/java/Hammurabi.java index 6f000c8..f8ec8df 100644 --- a/src/main/java/Hammurabi.java +++ b/src/main/java/Hammurabi.java @@ -2,30 +2,97 @@ public class Hammurabi { public static void main(String[] args) { + Hammurabi ham = new Hammurabi(100, 1000, 3000, 0, 19); + while(ham.playerWantsNewGame()){ //Initialize a loop to keep the game playing if the game ends and the player wants to play again + ham.setUpNewGame(); + while(ham.getYear() < 11){ // Starts the actual game + ham.initializeRound(); + ham.printSummary(); + // Asks how many acres to buy + + int acresToBuy = ham.getNumber("How many acres would you like to buy? The price is currently " + ham.getPrice() + " bushels per acre."); + if (ham.howManyAcresToBuy(acresToBuy, ham.getPrice(), ham.getBushels()) != 0){ + ham.changeLandsOwned(acresToBuy); + ham.changeBushels(acresToBuy * ham.getPrice()); + System.out.println("AMAZING! You bought " + acresToBuy + "acres!" ); + } + + // Asks how many acres to sell + + int acresToSell = ham.getNumber("How many acres would you like to sell? The Price is currently " + ham.getPrice() + " bushels per acre."); + if (ham.howManyAcresToSell(ham.getLandsOwned()) != 0){ + ham.changeLandsOwned(acresToSell); + ham.changeBushels(acresToSell * ham.getPrice()); + System.out.println("AMAZING! You sold " + acresToSell + "acres!" ); + } + + int acresToPlant = 0 // NOT DONE YET NEED TO KEEP GOIN!!! + + } + } } Random random = new Random(); int randomNum = random.nextInt(); Scanner scanner = new Scanner (System.in); + int population, landsOwned, bushels, year; + int temp; + int price; - public Hammurabi() { + public void setPopulation(int population) { + this.population = population; } - public int askHowManyAcresToBuy(int price, int bushels){ - return 0; + public void setLandsOwned(int landsOwned) { + this.landsOwned = landsOwned; } - public int askHowManyAcresToSell(int acresOwned) { + public void setBushels(int bushels) { + this.bushels = bushels; + } + + public void setYear(int year) { + this.year = year; + } + + public Hammurabi(int population, int landsOwned, int bushels, int year, int price) { + this.population = population; + this.landsOwned = landsOwned; + this.bushels = bushels; + this.year = year; + this.price = price; + } + + public void setUpNewGame(){ + this.setPopulation(100); + this.setLandsOwned(1000); + this.setBushels(3000); + this.setYear(0); + this.setPrice(19); + } + + public void initializeRound(){ + this.setPrice(newCostOfLand()); + this.incrementYear(); + } + public int howManyAcresToBuy(int acresToBuy, int price, int bushels){ + if ( (acresToBuy * price) > bushels){ + System.out.println("You FOOL! You don't have enough bushels to buy that many acres!"); + return 0; + } else return acresToBuy; + } + + public int howManyAcresToSell(int acresOwned) { return 0; } - public int askHowMuchGrainToFeedPeople(int bushels) { + public int howMuchGrainToFeedPeople(int bushels) { return 0; } - public int askHowManyAcresToPlant(int acresOwned, int population, int bushels) { + public int howManyAcresToPlant(int acresOwned, int population, int bushels) { return 0; } @@ -69,6 +136,50 @@ public int newCostOfLand() { return random.nextInt(7)+17; } + public boolean playerWantsNewGame(){ //THIS IS NOT FINISHED YET... NEED TO ADD REAL LOGIC + System.out.println("Would you like to continue playing?"); + return true; + } + public int getPopulation() { + return population; + } + + public void changePopulation(int populationChange) { + this.population += populationChange; + } + + public int getLandsOwned() { + return landsOwned; + } + + public void changeLandsOwned(int acresToChange) { + this.landsOwned += acresToChange; + } + + public int getBushels() { + return bushels; + } + + public void changeBushels(int bushelsChanged) { + this.bushels += bushelsChanged; + } + + public int getYear() { + return year; + } + + public void incrementYear() { + this.year += 1; + } + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } + int getNumber(String message) { while (true) { System.out.print(message); diff --git a/src/test/java/HammurabiTest.java b/src/test/java/HammurabiTest.java index de9fa7d..9947a40 100644 --- a/src/test/java/HammurabiTest.java +++ b/src/test/java/HammurabiTest.java @@ -1,5 +1,6 @@ import static org.junit.Assert.*; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -16,6 +17,14 @@ public void setUp() throws Exception { ham = new Hammurabi(); } + @Test + public void askHowManyAcresToBuyTest(){ + ham.bushels = 2000; + int expected = 10; + int actual = ham.askHowManyAcresToBuy(20, ham.bushels); + Assert.assertEquals(expected, actual); + } + @Test public final void testPlagueDeaths1() { int number_of_plagues = 0; From f32664f041093f0bb329b21e169bab8a463cea3f Mon Sep 17 00:00:00 2001 From: Emory Date: Sat, 12 Nov 2022 18:37:49 -0500 Subject: [PATCH 04/16] I MADE SOME CHANGES --- src/main/java/Hammurabi.java | 76 ++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/src/main/java/Hammurabi.java b/src/main/java/Hammurabi.java index f8ec8df..63bf11f 100644 --- a/src/main/java/Hammurabi.java +++ b/src/main/java/Hammurabi.java @@ -1,9 +1,17 @@ import java.util.*; public class Hammurabi { + + Random random = new Random(); + int randomNum = random.nextInt(); + Scanner scanner = new Scanner (System.in); + int population, landsOwned, bushels, year; + int temp; + int price; + public static void main(String[] args) { Hammurabi ham = new Hammurabi(100, 1000, 3000, 0, 19); - while(ham.playerWantsNewGame()){ //Initialize a loop to keep the game playing if the game ends and the player wants to play again + while(ham.exitGame() == false){ //Initialize a loop to keep the game playing if the game ends and the player wants to play again ham.setUpNewGame(); while(ham.getYear() < 11){ // Starts the actual game ham.initializeRound(); @@ -33,29 +41,8 @@ public static void main(String[] args) { } } - Random random = new Random(); - int randomNum = random.nextInt(); - Scanner scanner = new Scanner (System.in); - int population, landsOwned, bushels, year; - int temp; - int price; - - - public void setPopulation(int population) { - this.population = population; - } - - public void setLandsOwned(int landsOwned) { - this.landsOwned = landsOwned; - } - - public void setBushels(int bushels) { - this.bushels = bushels; - } - - public void setYear(int year) { - this.year = year; - } + // ***************************************************************************************************************** + // ***************** CONSTRUCTOR/GAME INITIALIZATION/ROUND INITILIZATION/EXIT public Hammurabi(int population, int landsOwned, int bushels, int year, int price) { this.population = population; @@ -77,6 +64,16 @@ public void initializeRound(){ this.setPrice(newCostOfLand()); this.incrementYear(); } + + public boolean exitGame(){ //THIS IS NOT FINISHED YET... NEED TO ADD REAL LOGIC + System.out.println("Would you like to continue playing?"); + return false; + } + + // ***************************************************************************************************************** + // ***************** CORE FEATURES + + public int howManyAcresToBuy(int acresToBuy, int price, int bushels){ if ( (acresToBuy * price) > bushels){ System.out.println("You FOOL! You don't have enough bushels to buy that many acres!"); @@ -104,10 +101,13 @@ public void finalSummary() { //String } - public void playGame() { + public void playGame() { // DO WE EVEN NEED THIS? //int } + // ***************************************************************************************************************** + // ***************** SUPPLEMENTARY FEATURES + public int plagueDeaths(int population) { return 0; } @@ -136,14 +136,17 @@ public int newCostOfLand() { return random.nextInt(7)+17; } - public boolean playerWantsNewGame(){ //THIS IS NOT FINISHED YET... NEED TO ADD REAL LOGIC - System.out.println("Would you like to continue playing?"); - return true; - } + // ***************************************************************************************************************** + // ***************** GETTERS/SETTERS/CHANGERS/INCREMENTERS + public int getPopulation() { return population; } + public void setPopulation(int population) { + this.population = population; + } + public void changePopulation(int populationChange) { this.population += populationChange; } @@ -152,6 +155,10 @@ public int getLandsOwned() { return landsOwned; } + public void setLandsOwned(int landsOwned) { + this.landsOwned = landsOwned; + } + public void changeLandsOwned(int acresToChange) { this.landsOwned += acresToChange; } @@ -160,6 +167,10 @@ public int getBushels() { return bushels; } + public void setBushels(int bushels) { + this.bushels = bushels; + } + public void changeBushels(int bushelsChanged) { this.bushels += bushelsChanged; } @@ -168,6 +179,10 @@ public int getYear() { return year; } + public void setYear(int year) { + this.year = year; + } + public void incrementYear() { this.year += 1; } @@ -180,6 +195,9 @@ public void setPrice(int price) { this.price = price; } + // ***************************************************************************************************************** + // ***************** SCANNER + int getNumber(String message) { while (true) { System.out.print(message); From 023b8e43d6c15a440fd740d77972353a04a07266 Mon Sep 17 00:00:00 2001 From: Emory Date: Sat, 12 Nov 2022 21:06:17 -0500 Subject: [PATCH 05/16] Changed everything.... --- src/main/java/App.java | 9 ++ src/main/java/Console.java | 31 +++++++ src/main/java/Hammurabi.java | 155 +------------------------------ src/main/java/State.java | 77 +++++++++++++++ src/main/java/UserInterface.java | 72 ++++++++++++++ src/test/java/StateTest.java | 71 ++++++++++++++ 6 files changed, 261 insertions(+), 154 deletions(-) create mode 100644 src/main/java/App.java create mode 100644 src/main/java/Console.java create mode 100644 src/main/java/State.java create mode 100644 src/main/java/UserInterface.java create mode 100644 src/test/java/StateTest.java diff --git a/src/main/java/App.java b/src/main/java/App.java new file mode 100644 index 0000000..561a086 --- /dev/null +++ b/src/main/java/App.java @@ -0,0 +1,9 @@ +public class App { + public static void main(String[] args) { + + UserInterface ui = new UserInterface(); + + ui.main(); + + } +} diff --git a/src/main/java/Console.java b/src/main/java/Console.java new file mode 100644 index 0000000..27b5177 --- /dev/null +++ b/src/main/java/Console.java @@ -0,0 +1,31 @@ +import java.util.InputMismatchException; +import java.util.Scanner; + +public class Console { +Scanner scanner = new Scanner(System.in); + + // NEED TO CHANGE BOTH METHODS TO ENTER INPUT ON ANOTHER LINE + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } + + String getString(String message){ + while(true){ + System.out.println(message); + try { + return scanner.nextLine(); + } + catch (InputMismatchException e){ + System.out.println("\"" + scanner.next() + "\" isn't a word!"); + } + } + } +} diff --git a/src/main/java/Hammurabi.java b/src/main/java/Hammurabi.java index 63bf11f..caf8cf6 100644 --- a/src/main/java/Hammurabi.java +++ b/src/main/java/Hammurabi.java @@ -4,76 +4,13 @@ public class Hammurabi { Random random = new Random(); int randomNum = random.nextInt(); - Scanner scanner = new Scanner (System.in); - int population, landsOwned, bushels, year; - int temp; - int price; - - public static void main(String[] args) { - Hammurabi ham = new Hammurabi(100, 1000, 3000, 0, 19); - while(ham.exitGame() == false){ //Initialize a loop to keep the game playing if the game ends and the player wants to play again - ham.setUpNewGame(); - while(ham.getYear() < 11){ // Starts the actual game - ham.initializeRound(); - ham.printSummary(); - - // Asks how many acres to buy - - int acresToBuy = ham.getNumber("How many acres would you like to buy? The price is currently " + ham.getPrice() + " bushels per acre."); - if (ham.howManyAcresToBuy(acresToBuy, ham.getPrice(), ham.getBushels()) != 0){ - ham.changeLandsOwned(acresToBuy); - ham.changeBushels(acresToBuy * ham.getPrice()); - System.out.println("AMAZING! You bought " + acresToBuy + "acres!" ); - } - - // Asks how many acres to sell - - int acresToSell = ham.getNumber("How many acres would you like to sell? The Price is currently " + ham.getPrice() + " bushels per acre."); - if (ham.howManyAcresToSell(ham.getLandsOwned()) != 0){ - ham.changeLandsOwned(acresToSell); - ham.changeBushels(acresToSell * ham.getPrice()); - System.out.println("AMAZING! You sold " + acresToSell + "acres!" ); - } - - int acresToPlant = 0 // NOT DONE YET NEED TO KEEP GOIN!!! - - } - } - } // ***************************************************************************************************************** // ***************** CONSTRUCTOR/GAME INITIALIZATION/ROUND INITILIZATION/EXIT - public Hammurabi(int population, int landsOwned, int bushels, int year, int price) { - this.population = population; - this.landsOwned = landsOwned; - this.bushels = bushels; - this.year = year; - this.price = price; + public Hammurabi() { } - public void setUpNewGame(){ - this.setPopulation(100); - this.setLandsOwned(1000); - this.setBushels(3000); - this.setYear(0); - this.setPrice(19); - } - - public void initializeRound(){ - this.setPrice(newCostOfLand()); - this.incrementYear(); - } - - public boolean exitGame(){ //THIS IS NOT FINISHED YET... NEED TO ADD REAL LOGIC - System.out.println("Would you like to continue playing?"); - return false; - } - - // ***************************************************************************************************************** - // ***************** CORE FEATURES - - public int howManyAcresToBuy(int acresToBuy, int price, int bushels){ if ( (acresToBuy * price) > bushels){ System.out.println("You FOOL! You don't have enough bushels to buy that many acres!"); @@ -93,18 +30,6 @@ public int howManyAcresToPlant(int acresOwned, int population, int bushels) { return 0; } - public void printSummary() { - //String - } - - public void finalSummary() { - //String - } - - public void playGame() { // DO WE EVEN NEED THIS? - //int - } - // ***************************************************************************************************************** // ***************** SUPPLEMENTARY FEATURES @@ -131,82 +56,4 @@ public int harvest (int bushelsUsedAsSeed) { public int grainEatenByRats (int bushels) { return random.nextInt(21)+10; } - - public int newCostOfLand() { - return random.nextInt(7)+17; - } - - // ***************************************************************************************************************** - // ***************** GETTERS/SETTERS/CHANGERS/INCREMENTERS - - public int getPopulation() { - return population; - } - - public void setPopulation(int population) { - this.population = population; - } - - public void changePopulation(int populationChange) { - this.population += populationChange; - } - - public int getLandsOwned() { - return landsOwned; - } - - public void setLandsOwned(int landsOwned) { - this.landsOwned = landsOwned; - } - - public void changeLandsOwned(int acresToChange) { - this.landsOwned += acresToChange; - } - - public int getBushels() { - return bushels; - } - - public void setBushels(int bushels) { - this.bushels = bushels; - } - - public void changeBushels(int bushelsChanged) { - this.bushels += bushelsChanged; - } - - public int getYear() { - return year; - } - - public void setYear(int year) { - this.year = year; - } - - public void incrementYear() { - this.year += 1; - } - - public int getPrice() { - return price; - } - - public void setPrice(int price) { - this.price = price; - } - - // ***************************************************************************************************************** - // ***************** SCANNER - - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } } diff --git a/src/main/java/State.java b/src/main/java/State.java new file mode 100644 index 0000000..966c392 --- /dev/null +++ b/src/main/java/State.java @@ -0,0 +1,77 @@ +import java.util.Random; + +public class State { + int population, landsOwned, bushels, price, year; + Random random = new Random(); + + public State(){ + } + + public State(int population, int landsOwned, int bushels, int year, int price) { + this.population = population; + this.landsOwned = landsOwned; + this.bushels = bushels; + this.year = year; + this.price = price; + } + + public int getPopulation() { + return population; + } + + public void setPopulation(int population) { + this.population = population; + } + + public void changePopulation(int populationChange) { + this.population += populationChange; + } + + public int getLandsOwned() { + return landsOwned; + } + + public void setLandsOwned(int landsOwned) { + this.landsOwned = landsOwned; + } + + public void changeLandsOwned(int acresToChange) { + this.landsOwned += acresToChange; + } + + public int newCostOfLand() { + return random.nextInt(7)+17; + } + + public int getBushels() { + return bushels; + } + + public void setBushels(int bushels) { + this.bushels = bushels; + } + public void changeBushels(int bushelsChanged) { + this.bushels += bushelsChanged; + } + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public void incrementYear() { + this.year += 1; + } + +} diff --git a/src/main/java/UserInterface.java b/src/main/java/UserInterface.java new file mode 100644 index 0000000..0700ad1 --- /dev/null +++ b/src/main/java/UserInterface.java @@ -0,0 +1,72 @@ +public class UserInterface { + + Hammurabi game = new Hammurabi(); + Console console = new Console(); + State state = new State(); + + + public void main() { + + while(exitGame() == false){ //Initialize a loop to keep the game playing if the game ends and the player wants to play again + setUpNewGame(); + while(state.getYear() < 11){ // Starts the actual game + initializeRound(); + printSummary(); + + // Asks how many acres to buy + int acresToBuy = console.getNumber("How many acres would you like to buy? The price is currently " + state.getPrice() + " bushels per acre."); + askHowManyAcresToBuy(acresToBuy); + + // Asks how many acres to sell + int acresToSell = console.getNumber("How many acres would you like to sell? The Price is currently " + state.getPrice() + " bushels per acre."); + askHowManyAcresToSell(acresToSell); + +// int acresToPlant = 0 // NOT DONE YET NEED TO KEEP GOIN!!! + + } + } + } + + public void setUpNewGame(){ + state.setPopulation(100); + state.setLandsOwned(1000); + state.setBushels(3000); + state.setYear(0); + state.setPrice(19); + } + + public void initializeRound(){ + state.setPrice(state.newCostOfLand()); + state.incrementYear(); + } + + public void printSummary() { + //String + } + + public void finalSummary() { + //String + } + + public void askHowManyAcresToBuy(int acresToBuy){ + if (game.howManyAcresToBuy(acresToBuy, state.getPrice(), state.getBushels()) != 0){ + state.changeLandsOwned(acresToBuy); + state.changeBushels(acresToBuy * state.getPrice()); + System.out.println("AMAZING! You bought " + acresToBuy + "acres!" ); + } + } + + public void askHowManyAcresToSell(int acresToSell){ + if (game.howManyAcresToSell(state.getLandsOwned()) != 0){ + state.changeLandsOwned(acresToSell); + state.changeBushels(acresToSell * state.getPrice()); + System.out.println("AMAZING! You sold " + acresToSell + "acres!" ); + } + } + + public boolean exitGame(){ //THIS IS NOT FINISHED YET... NEED TO ADD REAL LOGIC + System.out.println("Would you like to continue playing?"); + return false; + } + +} diff --git a/src/test/java/StateTest.java b/src/test/java/StateTest.java new file mode 100644 index 0000000..cd8f2e4 --- /dev/null +++ b/src/test/java/StateTest.java @@ -0,0 +1,71 @@ +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class StateTest { + + @BeforeEach + void setUp() { + } + + @Test + void getPopulation() { + } + + @Test + void setPopulation() { + } + + @Test + void changePopulation() { + } + + @Test + void getLandsOwned() { + } + + @Test + void setLandsOwned() { + } + + @Test + void changeLandsOwned() { + } + + @Test + void newCostOfLand() { + } + + @Test + void getBushels() { + } + + @Test + void setBushels() { + } + + @Test + void changeBushels() { + } + + @Test + void getPrice() { + } + + @Test + void setPrice() { + } + + @Test + void getYear() { + } + + @Test + void setYear() { + } + + @Test + void incrementYear() { + } +} \ No newline at end of file From 0fa8c9ab8f10e082b38d8ee4560910a54c6cd619 Mon Sep 17 00:00:00 2001 From: Emory Date: Sat, 12 Nov 2022 22:02:56 -0500 Subject: [PATCH 06/16] Finished State Class and State Tests --- .DS_Store | Bin 6148 -> 6148 bytes .idea/.DS_Store | Bin 6148 -> 6148 bytes .idea/uiDesigner.xml | 124 ++++++++++++++++++ README.md | 2 +- src/.DS_Store | Bin 6148 -> 6148 bytes .../java/{Hammurabi.java => GameEngine.java} | 25 +++- src/main/java/UserInterface.java | 6 +- ...HammurabiTest.java => GameEngineTest.java} | 80 ++++++----- src/test/java/StateTest.java | 105 +++++++++++++-- target/.DS_Store | Bin 0 -> 6148 bytes 10 files changed, 276 insertions(+), 66 deletions(-) create mode 100644 .idea/uiDesigner.xml rename src/main/java/{Hammurabi.java => GameEngine.java} (57%) rename src/test/java/{HammurabiTest.java => GameEngineTest.java} (61%) create mode 100644 target/.DS_Store diff --git a/.DS_Store b/.DS_Store index a78b4e19997471ff4cee0110e1b34fb0c24d5477..70c17305ffb71eb93494d9df194708ed06e05334 100644 GIT binary patch literal 6148 zcmeHKy-ve05I)lY6(H0BAqIv>Oe{zp5b74HP#&NQ0|Wg*rBX{OTK4b&2v~RxX0{GI z06PQE075J<@SSb7HYtp#LU)q=C3il5@fXDx6Ok&PH;Y6CBFdvN1`FsW7{|F~Y{q(4 zfQsknw2IY6((PqNibE6-1*TB}{&oY}q87Dj;C;Vp=iZHVlQ^z-k~)0(%hJVT<@#aQ zk2imf_fDL>VV?IJngws0nsiJxkC{&2{HV+Q{_^~^Z@8WOZZc+{Ji_BwdW#Ccolt}N zKKtROUYCuz+~v~8@b${BdlVltPl|iIlwxYiQJ>DJ;j?+}d!hYdbJx2Qadj8iWU?Oe)Z%Dtp9GCLR9Jj*Bd& z22DCC&5U_0v$7`?rP<*R^>9*=LFq*SQNULqXKo8z|Mz}A|NBXDCkluH|4IQB#MQWr zCE41VSsd5e5bX$!jmM=1bqYFLj`anX;x#mFh=qIsj4Y-G;epAIfR;fzQQ%J%_yXTC BpG5!w delta 340 zcmZoMXfc=|#>B)qF;Q%yo+6{b#(>?7i~^H+SS0Hiu9z?|Ft9M_F{CqOGL+=zySOCf zoVHlj8pIZRb!@$5~03um|W@j>_Fr+dh=A + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index e4672c9..e465791 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ package hammurabi; // package declaration import java.util.Random; // imports go here import java.util.Scanner; -public class Hammurabi { // must save in a file named Hammurabi.java +public class GameEngine { // must save in a file named GameEngine.java Random rand = new Random(); // this is an instance variable Scanner scanner = new Scanner(System.in); diff --git a/src/.DS_Store b/src/.DS_Store index bfd0f2935357d637dbd35376573d7f2b6f688c0b..44ae82afab448a4db5f3edff3f23d67fc50c8dc8 100644 GIT binary patch delta 174 zcmZoMXffEJ##k@o%)r3F!jQ|5$dJj9mz(e6l9ZF51Qg@=#>D6Lr~il}s(cDw`GO3? z;N<+=0-zos2mlc*3?&Sy48;s3IqAr9%2&a1lb13Ivu@!7+BA7DqcoItmr<56U^62V O8{5PJw$1DufB6Bk2P=dC delta 174 zcmZoMXffEJ##qm^oq>UYg&~(Aks*^IFE`)CB`GIA2`I+#-S78-PyI(6QRP$c$`@o9 z1}Ep|76A1CfdGhLVJKlpWhiDS$w^0%%K^(xUdkxUY8C;sY4To1X(;P1qb#GsW=1A9 OwuuF7o7p-3@&f>rTrijb diff --git a/src/main/java/Hammurabi.java b/src/main/java/GameEngine.java similarity index 57% rename from src/main/java/Hammurabi.java rename to src/main/java/GameEngine.java index caf8cf6..575a010 100644 --- a/src/main/java/Hammurabi.java +++ b/src/main/java/GameEngine.java @@ -1,6 +1,6 @@ import java.util.*; -public class Hammurabi { +public class GameEngine { Random random = new Random(); int randomNum = random.nextInt(); @@ -8,26 +8,37 @@ public class Hammurabi { // ***************************************************************************************************************** // ***************** CONSTRUCTOR/GAME INITIALIZATION/ROUND INITILIZATION/EXIT - public Hammurabi() { + public GameEngine() { } - public int howManyAcresToBuy(int acresToBuy, int price, int bushels){ + public int calculateAcresToBuy(int acresToBuy, int price, int bushels){ if ( (acresToBuy * price) > bushels){ System.out.println("You FOOL! You don't have enough bushels to buy that many acres!"); return 0; } else return acresToBuy; } - public int howManyAcresToSell(int acresOwned) { + public int calculateAcresToSell(int acresOwned) { return 0; } - public int howMuchGrainToFeedPeople(int bushels) { + public int calculateGrainToFeedPeople(int bushels) { return 0; } - public int howManyAcresToPlant(int acresOwned, int population, int bushels) { - return 0; + public int calculateAcresToPlant(int acresToPlant, int acresOwned, int population, int bushels) { + if (acresToPlant > acresOwned){ + System.out.println("You dum dum, you only have " + acresOwned + " acres!"); + return 0; + } else if ( acresToPlant/10 > population){ + System.out.println("You don't have enough people to plant that many acres!!"); + return 0; + } else if (acresToPlant/2 > bushels){ + System.out.println("You don't have enough grain to plant that many acres!"); + return 0; + } else { + return acresToPlant; // do state.changeBushels((acresToPlant*2)*-1) in the UserInterface class... + } } // ***************************************************************************************************************** diff --git a/src/main/java/UserInterface.java b/src/main/java/UserInterface.java index 0700ad1..bba32d5 100644 --- a/src/main/java/UserInterface.java +++ b/src/main/java/UserInterface.java @@ -1,6 +1,6 @@ public class UserInterface { - Hammurabi game = new Hammurabi(); + GameEngine game = new GameEngine(); Console console = new Console(); State state = new State(); @@ -49,7 +49,7 @@ public void finalSummary() { } public void askHowManyAcresToBuy(int acresToBuy){ - if (game.howManyAcresToBuy(acresToBuy, state.getPrice(), state.getBushels()) != 0){ + if (game.calculateAcresToBuy(acresToBuy, state.getPrice(), state.getBushels()) != 0){ state.changeLandsOwned(acresToBuy); state.changeBushels(acresToBuy * state.getPrice()); System.out.println("AMAZING! You bought " + acresToBuy + "acres!" ); @@ -57,7 +57,7 @@ public void askHowManyAcresToBuy(int acresToBuy){ } public void askHowManyAcresToSell(int acresToSell){ - if (game.howManyAcresToSell(state.getLandsOwned()) != 0){ + if (game.calculateAcresToSell(state.getLandsOwned()) != 0){ state.changeLandsOwned(acresToSell); state.changeBushels(acresToSell * state.getPrice()); System.out.println("AMAZING! You sold " + acresToSell + "acres!" ); diff --git a/src/test/java/HammurabiTest.java b/src/test/java/GameEngineTest.java similarity index 61% rename from src/test/java/HammurabiTest.java rename to src/test/java/GameEngineTest.java index 9947a40..537549b 100644 --- a/src/test/java/HammurabiTest.java +++ b/src/test/java/GameEngineTest.java @@ -1,60 +1,61 @@ +import org.junit.Assert; +import org.junit.jupiter.api.Test; + import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -public class HammurabiTest { - - Hammurabi ham; +class GameEngineTest { + boolean about(double expected, double actual) { return actual > 0.90 * expected && actual < 1.10 * expected; } - @Before - public void setUp() throws Exception { - ham = new Hammurabi(); - } @Test - public void askHowManyAcresToBuyTest(){ - ham.bushels = 2000; + public void calculateHowManyAcresToBuyTest(){ + State state = new State(100, 1000, 3000, 0, 19); + GameEngine game = new GameEngine(); int expected = 10; - int actual = ham.askHowManyAcresToBuy(20, ham.bushels); + int actual = game.calculateAcresToBuy(20, state.getPrice(), state.getBushels()); Assert.assertEquals(expected, actual); } @Test public final void testPlagueDeaths1() { + GameEngine game = new GameEngine(); int number_of_plagues = 0; for (int i = 0; i < 10000; i++) { - int deaths = ham.plagueDeaths(100); + int deaths = game.plagueDeaths(100); if (deaths > 0) { number_of_plagues += 1; } } int percentPlagues = number_of_plagues / 100; assertTrue("Number of plagues is about " + percentPlagues + ", not about 15%.", - about(1500, number_of_plagues)); + about(1500, number_of_plagues)); } @Test public final void testPlagueDeaths2() { + GameEngine game = new GameEngine(); int deaths = 0; for (int i = 0; i < 10000; i++) { - deaths = ham.plagueDeaths(100); + deaths = game.plagueDeaths(100); if (deaths > 0) break; } assertEquals("In a plague, " + deaths + "% of your people die, not 50%.", - 50, deaths); + 50, deaths); } - + @Test public final void testStarvationDeaths() { - int deaths = ham.starvationDeaths(100, 1639); + GameEngine game = new GameEngine(); + int deaths = game.starvationDeaths(100, 1639); assertEquals("Wrong number of starvations deaths.", 19, deaths); - deaths = ham.starvationDeaths(100, 2500); + deaths = game.starvationDeaths(100, 2500); if (deaths < 0) { fail("You starved a negative number of people!"); } @@ -62,21 +63,24 @@ public final void testStarvationDeaths() { @Test public final void testUprising() { - assertTrue("Should have had an uprising!", ham.uprising(1000, 451)); - assertFalse("Should not have had an uprising!", ham.uprising(1000, 449)); + GameEngine game = new GameEngine(); + assertTrue("Should have had an uprising!", game.uprising(1000, 451)); + assertFalse("Should not have had an uprising!", game.uprising(1000, 449)); } @Test public final void testImmigrants() { - int imm = ham.immigrants(10, 1200, 500); + GameEngine game = new GameEngine(); + int imm = game.immigrants(10, 1200, 500); assertEquals("Wrong number of immigrants.", 25, imm); } @Test public final void testHarvest() { + GameEngine game = new GameEngine(); int[] yield = new int[7]; for (int i = 0; i < 1000; i++) { - int harvest = ham.harvest(1); + int harvest = game.harvest(1); assertTrue("Illegal harvest per acre: " + harvest, harvest > 0 && harvest <= 6); yield[harvest] += 1; } @@ -87,46 +91,38 @@ public final void testHarvest() { @Test public final void testGrainEatenByRats1() { + GameEngine game = new GameEngine(); int infestations = 0; for (int i = 0; i < 1000; i++) { - int eaten = ham.grainEatenByRats(100); + int eaten = game.grainEatenByRats(100); if (eaten > 0) { infestations += 1; } } int percentInfestations = infestations / 100; - assertTrue("Number of rat infestations is about " + percentInfestations + - ", not about 40%.", about(400, infestations)); + assertTrue("Number of rat infestations is about " + percentInfestations + + ", not about 40%.", about(400, infestations)); } @Test public final void testGrainEatenByRats2() { + GameEngine game = new GameEngine(); int percent = 0; int[] counts = new int[31]; for (int i = 0; i < 10000; i++) { - percent = ham.grainEatenByRats(100); + percent = game.grainEatenByRats(100); if (percent == 0) continue; counts[percent] += 1; assertTrue("Rats ate " + percent + "% of your grain, not 10% to 30%.", - percent >= 10 && percent <= 30); + percent >= 10 && percent <= 30); } for (int j = 11; j < 30; j++) { assertTrue("Rats never ate " + j + "% of your grain.", counts[j] > 0); } } - @Test - public final void testNewCostOfLand() { - int[] cost = new int[24]; - for (int i = 0; i < 1000; i++) { - int price = ham.newCostOfLand(); - assertTrue("Illegal cost of land: " + price, price >= 17 && price <= 23); - cost[price] += 1; - } - for (int j = 17; j <= 23; j++) { - assertTrue("You never have a land cost of " + j + " bushels per acre.", cost[j] > 0); - } - } -} + + +} \ No newline at end of file diff --git a/src/test/java/StateTest.java b/src/test/java/StateTest.java index cd8f2e4..c275476 100644 --- a/src/test/java/StateTest.java +++ b/src/test/java/StateTest.java @@ -1,71 +1,150 @@ +import org.junit.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.*; class StateTest { @BeforeEach - void setUp() { + public void setUp() { + State state = new State(100, 1000, 3000, 0, 19); } @Test - void getPopulation() { + void getPopulationTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 100; + int actual = state.getPopulation(); + Assert.assertEquals(expected, actual); } @Test - void setPopulation() { + void setPopulationTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 200; + state.setPopulation(200); + int actual = state.getPopulation(); + Assert.assertEquals(expected, actual); } @Test - void changePopulation() { + void changePopulationTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 50; + state.changePopulation(-50); + int actual = state.getPopulation(); + Assert.assertEquals(expected, actual); } @Test - void getLandsOwned() { + void getLandsOwnedTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 1000; + int actual = state.getLandsOwned(); + Assert.assertEquals(expected, actual); } @Test - void setLandsOwned() { + void setLandsOwnedTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 2000; + state.setLandsOwned(2000); + int actual = state.getLandsOwned(); + Assert.assertEquals(expected, actual); } @Test - void changeLandsOwned() { + void changeLandsOwnedTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 900; + state.changeLandsOwned(-100); + int actual = state.getLandsOwned(); + Assert.assertEquals(expected, actual); } @Test - void newCostOfLand() { + void getBushelsTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 3000; + int actual = state.getBushels(); + Assert.assertEquals(expected, actual); } @Test - void getBushels() { + void setBushelsTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 5000; + state.setBushels(5000); + int actual = state.getBushels(); + Assert.assertEquals(expected, actual); } @Test - void setBushels() { + void changeBushelsTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 2900; + state.changeBushels(-100); + int actual = state.getBushels(); + Assert.assertEquals(expected, actual); } @Test - void changeBushels() { + void getPriceTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 19; + int actual = state.getPrice(); + Assert.assertEquals(expected, actual); } @Test - void getPrice() { + void setPriceTest() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 23; + state.setPrice(23); + int actual = state.getPrice(); + Assert.assertEquals(expected, actual); } @Test - void setPrice() { + public final void testNewCostOfLand() { + State state = new State(100, 1000, 3000, 0, 19); + int[] cost = new int[24]; + for (int i = 0; i < 1000; i++) { + int price = state.newCostOfLand(); + assertTrue("Illegal cost of land: " + price, price >= 17 && price <= 23); + cost[price] += 1; + } + for (int j = 17; j <= 23; j++) { + assertTrue("You never have a land cost of " + j + " bushels per acre.", cost[j] > 0); + } } + @Test void getYear() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 0; + int actual = state.getYear(); + Assert.assertEquals(expected, actual); } @Test void setYear() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 5; + state.setYear(5); + int actual = state.getYear(); + Assert.assertEquals(expected, actual); } @Test void incrementYear() { + State state = new State(100, 1000, 3000, 0, 19); + int expected = 1; + state.incrementYear(); + int actual = state.getYear(); + Assert.assertEquals(expected, actual); } } \ No newline at end of file diff --git a/target/.DS_Store b/target/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..587b1b8c1cf1962994d907bdf85c950c0f70e15a GIT binary patch literal 6148 zcmeHKy-veG4E8~#R=`k%RCPSDFfmjt3=E+PJE$uIv_%Ecl8VqhZ%}q#0l`b~CJej; z1E0@F+bC&C84#-M$o`T$`_BIIb2%b1%~7{OR3)Mcl(Dn{lOx>Envpf%!okLk5z`gL z{a&Nhi89{WpbRJj|BV5DcgxhFK3!6bWAgqEhLY;;IO{Qp!m!pgMBx*MAn~(RG&#}w9zH1uzwcPr+&KTAHT)go% zf@+lkWgyMKx?EOy{Xdz%|4#?$l`^0VtP}&L6t==9O7d%KrZ`?}E%XA)!hVUM3xV;= gu{+_VxDIuKKFcS-z+)na7Kr``I2zO_1AofE7iK@c^Z)<= literal 0 HcmV?d00001 From c5f6b084df74720f3fc51cd659847b79998320f9 Mon Sep 17 00:00:00 2001 From: Emory Date: Sat, 12 Nov 2022 23:45:01 -0500 Subject: [PATCH 07/16] Added some stuff, rearranged some things --- src/main/java/Console.java | 2 +- src/main/java/GameEngine.java | 42 +++++++++---- src/main/java/State.java | 59 +++++++++++++++++- src/main/java/UserInterface.java | 101 +++++++++++++++++++++++++++++-- 4 files changed, 185 insertions(+), 19 deletions(-) diff --git a/src/main/java/Console.java b/src/main/java/Console.java index 27b5177..3c1c9bd 100644 --- a/src/main/java/Console.java +++ b/src/main/java/Console.java @@ -7,7 +7,7 @@ public class Console { // NEED TO CHANGE BOTH METHODS TO ENTER INPUT ON ANOTHER LINE int getNumber(String message) { while (true) { - System.out.print(message); + System.out.println(message); try { return scanner.nextInt(); } diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java index 575a010..8f7590f 100644 --- a/src/main/java/GameEngine.java +++ b/src/main/java/GameEngine.java @@ -1,5 +1,7 @@ import java.util.*; +import static java.lang.Math.floor; + public class GameEngine { Random random = new Random(); @@ -12,18 +14,30 @@ public GameEngine() { } public int calculateAcresToBuy(int acresToBuy, int price, int bushels){ - if ( (acresToBuy * price) > bushels){ - System.out.println("You FOOL! You don't have enough bushels to buy that many acres!"); + if ( (acresToBuy * price) >= bushels){ + System.out.println("You FOOL! You're trying to buy more than what you can afford, you get nothing and like it!"); return 0; } else return acresToBuy; } - public int calculateAcresToSell(int acresOwned) { - return 0; + public int calculateAcresToSell(int acresToSell, int landOwned, int population) { + if( (landOwned*100)/population < 70){ + //GAME OVER + return 0; + } else if (acresToSell > landOwned) { + return 0; + } else { + return acresToSell; + } } - public int calculateGrainToFeedPeople(int bushels) { - return 0; + public int calculateGrainToFeedPeople(int bushels, int bushelsFed) { + if (bushelsFed > bushels){ + System.out.println("You don't have enough grain for that!"); + return 0; + } else { + return bushelsFed; + } } public int calculateAcresToPlant(int acresToPlant, int acresOwned, int population, int bushels) { @@ -45,26 +59,32 @@ public int calculateAcresToPlant(int acresToPlant, int acresOwned, int populatio // ***************** SUPPLEMENTARY FEATURES public int plagueDeaths(int population) { + if(random.nextInt(101) < 15) return population/2; return 0; } public int starvationDeaths(int population, int bushelsFedToPeople) { - return 0; + //returning the number of deaths + if(population - (int) floor(bushelsFedToPeople/20) < 0) return 0; + return population - (int) floor(bushelsFedToPeople/20); } public boolean uprising(int population, int howManyPeopleStarved) { - return true; + if ((double) howManyPeopleStarved / population > 0.45) return true; + return false; } public int immigrants (int population, int acresOwned, int grainInStorage) { - return 0; + return (20 * acresOwned + grainInStorage) / (100 * population) + 1; } public int harvest (int bushelsUsedAsSeed) { - return 0; + //Returning for the number of bushels harvested per acre + return (random.nextInt(6)+1)*bushelsUsedAsSeed; } public int grainEatenByRats (int bushels) { - return random.nextInt(21)+10; + if(random.nextInt(100) < 40) return (random.nextInt(21)+10)*bushels; + return 0; } } diff --git a/src/main/java/State.java b/src/main/java/State.java index 966c392..6caccfa 100644 --- a/src/main/java/State.java +++ b/src/main/java/State.java @@ -2,17 +2,36 @@ public class State { int population, landsOwned, bushels, price, year; + int pDeaths, sDeaths, immigrants, harvest, rats; Random random = new Random(); public State(){ } - public State(int population, int landsOwned, int bushels, int year, int price) { + public State(int population, int landsOwned, int bushels, int year, int price, int pDeaths, int sDeaths, int immigrants, int harvest, int rats) { this.population = population; this.landsOwned = landsOwned; this.bushels = bushels; this.year = year; this.price = price; + this.pDeaths = pDeaths; + this.sDeaths = sDeaths; + this.immigrants = immigrants; + this.harvest = harvest; + this.rats = rats; + } + + public State(int population, int landsOwned, int bushels, int year, int price){ + this.population = population; + this.landsOwned = landsOwned; + this.bushels = bushels; + this.year = year; + this.price = price; + this.pDeaths = 0; + this.sDeaths = 0; + this.immigrants = 0; + this.harvest = 0; + this.rats = 0; } public int getPopulation() { @@ -73,5 +92,43 @@ public void setYear(int year) { public void incrementYear() { this.year += 1; } + public int getpDeaths() { + return pDeaths; + } + + public void setpDeaths(int pDeaths) { + this.pDeaths = pDeaths; + } + public int getsDeaths() { + return sDeaths; + } + + public void setsDeaths(int sDeaths) { + this.sDeaths = sDeaths; + } + + public int getImmigrants() { + return immigrants; + } + + public void setImmigrants(int immigrants) { + this.immigrants = immigrants; + } + + public int getHarvest() { + return harvest; + } + + public void setHarvest(int harvest) { + this.harvest = harvest; + } + + public int getRats() { + return rats; + } + + public void setRats(int rats) { + this.rats = rats; + } } diff --git a/src/main/java/UserInterface.java b/src/main/java/UserInterface.java index bba32d5..e656963 100644 --- a/src/main/java/UserInterface.java +++ b/src/main/java/UserInterface.java @@ -9,9 +9,9 @@ public void main() { while(exitGame() == false){ //Initialize a loop to keep the game playing if the game ends and the player wants to play again setUpNewGame(); + announceGame(); while(state.getYear() < 11){ // Starts the actual game initializeRound(); - printSummary(); // Asks how many acres to buy int acresToBuy = console.getNumber("How many acres would you like to buy? The price is currently " + state.getPrice() + " bushels per acre."); @@ -21,8 +21,17 @@ public void main() { int acresToSell = console.getNumber("How many acres would you like to sell? The Price is currently " + state.getPrice() + " bushels per acre."); askHowManyAcresToSell(acresToSell); -// int acresToPlant = 0 // NOT DONE YET NEED TO KEEP GOIN!!! + // Asks how many bushels to feed to people + int bushelsFed = console.getNumber("How many bushels would you like to feed your nation?"); + askHowManyBushelsToFeedPeople(bushelsFed); + + // Asks how many acres to plant with grain + int acresToPlant = console.getNumber("How many acres to plant?"); + askHowManyAcresToPlant(acresToPlant); + + processRound(state.getPopulation(), bushelsFed, state.getLandsOwned(), acresToPlant*2, state.getBushels()); + printSummary(); } } } @@ -33,15 +42,56 @@ public void setUpNewGame(){ state.setBushels(3000); state.setYear(0); state.setPrice(19); + state.setpDeaths(0); + state.setsDeaths(0); + state.setImmigrants(0); + state.setHarvest(0); + state.setRats(0); } public void initializeRound(){ + state.setpDeaths(0); + state.setsDeaths(0); + state.setImmigrants(0); + state.setHarvest(0); + state.setRats(0); + } + + public void processRound(int population, int bushelsFedToPeople, int acresOwned, int bushelsUsedAsSeed, int bushels ){ + + state.setpDeaths(game.plagueDeaths(population)); + state.changePopulation(-state.getpDeaths()); + + state.setsDeaths(game.starvationDeaths(population, bushelsFedToPeople)); + state.changePopulation(-state.getsDeaths()); + + state.setImmigrants(game.immigrants(population, acresOwned, bushels)); + state.changePopulation(state.getImmigrants()); + + state.setHarvest(game.harvest(bushelsUsedAsSeed)); + state.changeBushels(state.getHarvest()); + + state.setRats(game.grainEatenByRats(bushels)); + state.changeBushels(-state.getRats()); + state.setPrice(state.newCostOfLand()); + state.incrementYear(); } public void printSummary() { - //String + System.out.println("O great Hammurabi"); + System.out.println("You are now in year " + state.getYear() + " of your ten year rule."); + System.out.println("\n"); + System.out.println("In the previous year " + state.getsDeaths() + " people starved to death."); + System.out.println("In the previous year "+ state.getImmigrants() + " entered the kingdom."); + System.out.println("The population is now " + state.getPopulation()); + System.out.println("We harvested " + state.getHarvest() + " bushels"); + System.out.println("Rats destroyed " + state.getRats() + " bushels"); + System.out.println("There are only " + state.getBushels() + " bushels left in storage."); + System.out.println("The city owns " + state.getLandsOwned() + " acres of land."); + System.out.println("Land is currently worth " + state.getPrice() + " bushels per acre"); + System.out.println("\n"); } public void finalSummary() { @@ -52,18 +102,57 @@ public void askHowManyAcresToBuy(int acresToBuy){ if (game.calculateAcresToBuy(acresToBuy, state.getPrice(), state.getBushels()) != 0){ state.changeLandsOwned(acresToBuy); state.changeBushels(acresToBuy * state.getPrice()); - System.out.println("AMAZING! You bought " + acresToBuy + "acres!" ); + System.out.println("\n"); + System.out.println("AMAZING! You bought " + acresToBuy + " acres!" ); + System.out.println("\n"); + } } public void askHowManyAcresToSell(int acresToSell){ - if (game.calculateAcresToSell(state.getLandsOwned()) != 0){ + if (game.calculateAcresToSell(acresToSell, state.getLandsOwned(), state.getPopulation()) != 0){ state.changeLandsOwned(acresToSell); state.changeBushels(acresToSell * state.getPrice()); - System.out.println("AMAZING! You sold " + acresToSell + "acres!" ); + System.out.println("\n"); + System.out.println("AMAZING! You sold " + acresToSell + " acres!" ); + System.out.println("\n"); + } + } + + public void askHowManyBushelsToFeedPeople(int bushelsFed){ + if (game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed) != 0){ + state.changeBushels(-bushelsFed); } } + public void askHowManyAcresToPlant(int acresToPlant){ + if (game.calculateAcresToPlant(acresToPlant, state.getLandsOwned(), state.getPopulation(), state.getBushels()) >0){ + // NEED TO FINISH THIS + } + } + + public void announceGame() { + System.out.println("Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office."); + System.out.println("Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people."); + System.out.println("Grain is the general currency, measured in bushels."); + System.out.println("\n"); + System.out.println("The following will help you in your decisions:"); + System.out.println("\n"); + System.out.println("**Each person needs at least 20 bushels of grain per year to survive**"); + System.out.println("**Each person can farm at most 10 acres of land**"); + System.out.println("**It takes 2 bushels of grain to farm an acre of land**"); + System.out.println("**The market price for land fluctuates yearly**"); + System.out.println("\n"); + System.out.println("Now, let's begin!"); + System.out.println("\n"); + System.out.println("O great One! Your kingdom await your orders!"); + System.out.println("There are " + state.getPopulation() + " people that you must feed!"); + System.out.println("Our coffers have " + state.getBushels() + " bushels in storage."); + System.out.println("The city owns " + state.getLandsOwned() + " acres of land."); + System.out.println("Land is available to purchase for " + state.getPrice() + " bushels per acre"); + System.out.println("\n"); + } + public boolean exitGame(){ //THIS IS NOT FINISHED YET... NEED TO ADD REAL LOGIC System.out.println("Would you like to continue playing?"); return false; From 8e43f7629a46d9d63d0eddc5e22ea85d983ffacd Mon Sep 17 00:00:00 2001 From: Freddy Mintarja <115741236+fmintar1@users.noreply.github.com> Date: Sun, 13 Nov 2022 10:57:06 -0500 Subject: [PATCH 08/16] Added lots of changes & updates --- src/main/java/GameEngine.java | 56 +++++++++++---- src/main/java/State.java | 62 +++++++++++------ src/main/java/UserInterface.java | 110 +++++++++++++++++++----------- src/test/java/GameEngineTest.java | 100 ++++++++++++++++++++++++++- 4 files changed, 251 insertions(+), 77 deletions(-) diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java index 8f7590f..7286be7 100644 --- a/src/main/java/GameEngine.java +++ b/src/main/java/GameEngine.java @@ -6,6 +6,7 @@ public class GameEngine { Random random = new Random(); int randomNum = random.nextInt(); + State state = new State(); //<- Added this to revise immigrants, can't have immigrants when starvationDeath occurs // ***************************************************************************************************************** // ***************** CONSTRUCTOR/GAME INITIALIZATION/ROUND INITILIZATION/EXIT @@ -14,10 +15,13 @@ public GameEngine() { } public int calculateAcresToBuy(int acresToBuy, int price, int bushels){ - if ( (acresToBuy * price) >= bushels){ + state.setBushels(bushels); + if ( (acresToBuy * price) > bushels){ System.out.println("You FOOL! You're trying to buy more than what you can afford, you get nothing and like it!"); return 0; - } else return acresToBuy; + } else { + return acresToBuy; + } } public int calculateAcresToSell(int acresToSell, int landOwned, int population) { @@ -41,19 +45,40 @@ public int calculateGrainToFeedPeople(int bushels, int bushelsFed) { } public int calculateAcresToPlant(int acresToPlant, int acresOwned, int population, int bushels) { - if (acresToPlant > acresOwned){ - System.out.println("You dum dum, you only have " + acresOwned + " acres!"); - return 0; - } else if ( acresToPlant/10 > population){ - System.out.println("You don't have enough people to plant that many acres!!"); - return 0; - } else if (acresToPlant/2 > bushels){ - System.out.println("You don't have enough grain to plant that many acres!"); - return 0; - } else { - return acresToPlant; // do state.changeBushels((acresToPlant*2)*-1) in the UserInterface class... + + //Tested my own method, 7 tests all passed + while(true) { + if (acresToPlant > population*10) { + acresToPlant = population*10; + } else if (acresToPlant > acresOwned) { + acresToPlant = acresOwned; + } else if (acresToPlant > bushels) { + acresToPlant = bushels; + } + if (acresToPlant <= population*10 && + acresToPlant <= acresOwned && + acresToPlant <= bushels) { + break; + } } +// System.out.println("Update: " + acresToPlant + " " + acresOwned + " " + population + " " + bushels); + return acresToPlant; } + //Original method + +// if (acresToPlant > acresOwned){ +// System.out.println("You dum dum, you only have " + acresOwned + " acres!"); +// return 0; +// } else if ( acresToPlant/10 > population){ +// System.out.println("You don't have enough people to plant that many acres!!"); +// return 0; +// } else if (acresToPlant/2 > bushels){ +// System.out.println("You don't have enough grain to plant that many acres!"); +// return 0; +// } else { +// return acresToPlant; // do state.changeBushels((acresToPlant*2)*-1) in the UserInterface class... +// } +// } // ***************************************************************************************************************** // ***************** SUPPLEMENTARY FEATURES @@ -74,7 +99,8 @@ public boolean uprising(int population, int howManyPeopleStarved) { return false; } - public int immigrants (int population, int acresOwned, int grainInStorage) { + public int immigrants (int population, int acresOwned, int grainInStorage, int bushelsFedToPeople) { + if(starvationDeaths(population, bushelsFedToPeople) > 0) return 0; //Added this, read line 9 return (20 * acresOwned + grainInStorage) / (100 * population) + 1; } @@ -84,7 +110,7 @@ public int harvest (int bushelsUsedAsSeed) { } public int grainEatenByRats (int bushels) { - if(random.nextInt(100) < 40) return (random.nextInt(21)+10)*bushels; + if(random.nextInt(100) < 40) return (random.nextInt(21)+10)*bushels/100; return 0; } } diff --git a/src/main/java/State.java b/src/main/java/State.java index 6caccfa..9053bb4 100644 --- a/src/main/java/State.java +++ b/src/main/java/State.java @@ -9,29 +9,51 @@ public State(){ } public State(int population, int landsOwned, int bushels, int year, int price, int pDeaths, int sDeaths, int immigrants, int harvest, int rats) { - this.population = population; - this.landsOwned = landsOwned; - this.bushels = bushels; - this.year = year; - this.price = price; - this.pDeaths = pDeaths; - this.sDeaths = sDeaths; - this.immigrants = immigrants; - this.harvest = harvest; - this.rats = rats; + setPopulation(population); //<-using setters instead of instance variable + setLandsOwned(landsOwned); + setBushels(bushels); + setYear(year); + setPrice(price); + setpDeaths(pDeaths); + setsDeaths(sDeaths); + setImmigrants(immigrants); + setHarvest(harvest); + setRats(rats); + + // this.population = population; +// this.landsOwned = landsOwned; +// this.bushels = bushels; +// this.year = year; +// this.price = price; +// this.pDeaths = pDeaths; +// this.sDeaths = sDeaths; +// this.immigrants = immigrants; +// this.harvest = harvest; +// this.rats = rats; } public State(int population, int landsOwned, int bushels, int year, int price){ - this.population = population; - this.landsOwned = landsOwned; - this.bushels = bushels; - this.year = year; - this.price = price; - this.pDeaths = 0; - this.sDeaths = 0; - this.immigrants = 0; - this.harvest = 0; - this.rats = 0; + setPopulation(population); //<-Using setters instead of instance variable + setLandsOwned(landsOwned); + setBushels(bushels); + setYear(year); + setPrice(price); + setpDeaths(0); + setsDeaths(0); + setImmigrants(immigrants); + setHarvest(harvest); + setRats(rats); +// +// this.population = population; +// this.landsOwned = landsOwned; +// this.bushels = bushels; +// this.year = year; +// this.price = price; +// this.pDeaths = 0; +// this.sDeaths = 0; +// this.immigrants = 0; +// this.harvest = 0; +// this.rats = 0; } public int getPopulation() { diff --git a/src/main/java/UserInterface.java b/src/main/java/UserInterface.java index e656963..cdfccc9 100644 --- a/src/main/java/UserInterface.java +++ b/src/main/java/UserInterface.java @@ -7,7 +7,7 @@ public class UserInterface { public void main() { - while(exitGame() == false){ //Initialize a loop to keep the game playing if the game ends and the player wants to play again + while(true){ //Initialize a loop to keep the game playing if the game ends and the player wants to play again setUpNewGame(); announceGame(); while(state.getYear() < 11){ // Starts the actual game @@ -20,19 +20,26 @@ public void main() { // Asks how many acres to sell int acresToSell = console.getNumber("How many acres would you like to sell? The Price is currently " + state.getPrice() + " bushels per acre."); askHowManyAcresToSell(acresToSell); + if(state.getLandsOwned() < state.getPopulation()*7) { //<-updated gameover + System.out.println("you are a national fink!"); + break; + } // Asks how many bushels to feed to people int bushelsFed = console.getNumber("How many bushels would you like to feed your nation?"); askHowManyBushelsToFeedPeople(bushelsFed); + if(game.starvationDeaths(state.getPopulation(), bushelsFed) > state.getPopulation()*45/100) { + System.out.println("you are a national fink!"); //<-updated gameover + break; + } // Asks how many acres to plant with grain int acresToPlant = console.getNumber("How many acres to plant?"); askHowManyAcresToPlant(acresToPlant); - processRound(state.getPopulation(), bushelsFed, state.getLandsOwned(), acresToPlant*2, state.getBushels()); - printSummary(); } + if(exitGame() == false) break; } } @@ -65,11 +72,11 @@ public void processRound(int population, int bushelsFedToPeople, int acresOwned, state.setsDeaths(game.starvationDeaths(population, bushelsFedToPeople)); state.changePopulation(-state.getsDeaths()); - state.setImmigrants(game.immigrants(population, acresOwned, bushels)); + state.setImmigrants(game.immigrants(population, acresOwned, bushels, bushelsFedToPeople)); state.changePopulation(state.getImmigrants()); - state.setHarvest(game.harvest(bushelsUsedAsSeed)); - state.changeBushels(state.getHarvest()); +// state.setHarvest(game.harvest(bushelsUsedAsSeed)); +// state.changeBushels(state.getHarvest()); <-Bugged due to RNG, recommend not use state.setRats(game.grainEatenByRats(bushels)); state.changeBushels(-state.getRats()); @@ -86,7 +93,7 @@ public void printSummary() { System.out.println("In the previous year " + state.getsDeaths() + " people starved to death."); System.out.println("In the previous year "+ state.getImmigrants() + " entered the kingdom."); System.out.println("The population is now " + state.getPopulation()); - System.out.println("We harvested " + state.getHarvest() + " bushels"); +// System.out.println("We harvested " + state.getHarvest() + " bushels"); <-Bugged due to RNG System.out.println("Rats destroyed " + state.getRats() + " bushels"); System.out.println("There are only " + state.getBushels() + " bushels left in storage."); System.out.println("The city owns " + state.getLandsOwned() + " acres of land."); @@ -101,18 +108,23 @@ public void finalSummary() { public void askHowManyAcresToBuy(int acresToBuy){ if (game.calculateAcresToBuy(acresToBuy, state.getPrice(), state.getBushels()) != 0){ state.changeLandsOwned(acresToBuy); - state.changeBushels(acresToBuy * state.getPrice()); + state.changeBushels(-(acresToBuy * state.getPrice())); + System.out.println("Bushels left: " + state.getBushels() + + "\nacres bought: " + acresToBuy + + "\nAcres update: " + state.getLandsOwned()); System.out.println("\n"); System.out.println("AMAZING! You bought " + acresToBuy + " acres!" ); System.out.println("\n"); - } } public void askHowManyAcresToSell(int acresToSell){ if (game.calculateAcresToSell(acresToSell, state.getLandsOwned(), state.getPopulation()) != 0){ - state.changeLandsOwned(acresToSell); + state.changeLandsOwned(-acresToSell); state.changeBushels(acresToSell * state.getPrice()); + System.out.println("Bushels left: " + state.getBushels() + + "\nacres sold: " + acresToSell + + "\nAcres update: " + state.getLandsOwned()); System.out.println("\n"); System.out.println("AMAZING! You sold " + acresToSell + " acres!" ); System.out.println("\n"); @@ -122,40 +134,58 @@ public void askHowManyAcresToSell(int acresToSell){ public void askHowManyBushelsToFeedPeople(int bushelsFed){ if (game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed) != 0){ state.changeBushels(-bushelsFed); + System.out.println("Bushels left: " + state.getBushels() + + "\nbushels eaten: " + bushelsFed); } } - public void askHowManyAcresToPlant(int acresToPlant){ - if (game.calculateAcresToPlant(acresToPlant, state.getLandsOwned(), state.getPopulation(), state.getBushels()) >0){ - // NEED TO FINISH THIS - } + public void askHowManyAcresToPlant(int acresToPlant) { +// if (game.calculateAcresToPlant(acresToPlant, state.getLandsOwned(), state.getPopulation(), state.getBushels()) > 0) { + acresToPlant = game.calculateAcresToPlant(acresToPlant, state.getLandsOwned(), state.getPopulation(), state.getBushels()); + state.changeBushels(-acresToPlant); + System.out.println(state.getBushels()); + state.changeBushels(game.harvest(acresToPlant)); + System.out.println("Acres planted: " + acresToPlant + + "\nUpdated Bushels " + state.getBushels()); + // FINISHED +// } else if (game.calculateAcresToPlant(acresToPlant, state.getLandsOwned(), state.getPopulation(), state.getBushels()) == 0) } - public void announceGame() { - System.out.println("Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office."); - System.out.println("Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people."); - System.out.println("Grain is the general currency, measured in bushels."); - System.out.println("\n"); - System.out.println("The following will help you in your decisions:"); - System.out.println("\n"); - System.out.println("**Each person needs at least 20 bushels of grain per year to survive**"); - System.out.println("**Each person can farm at most 10 acres of land**"); - System.out.println("**It takes 2 bushels of grain to farm an acre of land**"); - System.out.println("**The market price for land fluctuates yearly**"); - System.out.println("\n"); - System.out.println("Now, let's begin!"); - System.out.println("\n"); - System.out.println("O great One! Your kingdom await your orders!"); - System.out.println("There are " + state.getPopulation() + " people that you must feed!"); - System.out.println("Our coffers have " + state.getBushels() + " bushels in storage."); - System.out.println("The city owns " + state.getLandsOwned() + " acres of land."); - System.out.println("Land is available to purchase for " + state.getPrice() + " bushels per acre"); - System.out.println("\n"); - } - - public boolean exitGame(){ //THIS IS NOT FINISHED YET... NEED TO ADD REAL LOGIC - System.out.println("Would you like to continue playing?"); - return false; - } + public void announceGame () { + System.out.println("Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office."); + System.out.println("Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people."); + System.out.println("Grain is the general currency, measured in bushels."); + System.out.println("\n"); + System.out.println("The following will help you in your decisions:"); + System.out.println("\n"); + System.out.println("**Each person needs at least 20 bushels of grain per year to survive**"); + System.out.println("**Each person can farm at most 10 acres of land**"); + System.out.println("**It takes 2 bushels of grain to farm an acre of land**"); + System.out.println("**The market price for land fluctuates yearly**"); + System.out.println("\n"); + System.out.println("Now, let's begin!"); + System.out.println("\n"); + System.out.println("O great One! Your kingdom await your orders!"); + System.out.println("There are " + state.getPopulation() + " people that you must feed!"); + System.out.println("Our coffers have " + state.getBushels() + " bushels in storage."); + System.out.println("The city owns " + state.getLandsOwned() + " acres of land."); + System.out.println("Land is available to purchase for " + state.getPrice() + " bushels per acre"); + System.out.println("\n"); + } + public boolean exitGame () { //fixed exitgame + int options = console.getNumber("Would you like to play? 1 = Yes, 2 = No"); + boolean answer = true; + switch (options) { + case 1: + System.out.println("That's the spirit!"); + answer = true; + break; + case 2: + System.out.println("Goodbye"); + answer = false; + break; + } + return answer; + } } diff --git a/src/test/java/GameEngineTest.java b/src/test/java/GameEngineTest.java index 537549b..f542ad1 100644 --- a/src/test/java/GameEngineTest.java +++ b/src/test/java/GameEngineTest.java @@ -8,7 +8,8 @@ class GameEngineTest { - + GameEngine game = new GameEngine(); //<-Added this for test + State state = new State();//<-Added this for test boolean about(double expected, double actual) { return actual > 0.90 * expected && actual < 1.10 * expected; } @@ -23,6 +24,101 @@ public void calculateHowManyAcresToBuyTest(){ Assert.assertEquals(expected, actual); } + @Test + public void HowManyAcresToBuyTest1() { + //If price of acres are at maximum of 24 + state.setBushels(1000); + state.setLandsOwned(100); + int acresBought = game.calculateAcresToBuy(40, state.newCostOfLand(), state.getBushels()); + Assert.assertEquals(40, acresBought); + } + @Test + public void HowManyAcresToBuyTest2() { + //If price of acres are at minimum of 17 + state.setBushels(679); + state.setLandsOwned(100); + int acresBought = game.calculateAcresToBuy(40, state.newCostOfLand(), state.getBushels()); + Assert.assertEquals(0, acresBought); + } + @Test + public void HowManyAcresToBuyTest3() { + //If price of acres are random + state.setBushels(800); + state.setLandsOwned(100); + int acresBought = game.calculateAcresToBuy(40, state.newCostOfLand(), state.getBushels()); + Assert.assertTrue("Acres bought is " + acresBought, + acresBought == 40 || acresBought == 0); + } + @Test + public void HowManyAcresToBuyTest4() { + //Updated acres Owned + state.setBushels(800); + state.setLandsOwned(100); + state.setLandsOwned(100); + Assert.assertTrue("Acres bought is " + state.getLandsOwned(), + state.getLandsOwned() == 140 || state.getLandsOwned() == 100); + } + + + @Test + public void howManyAcresToPlantTest1() { //Added + //If acres to be planted is more than acres owned + state.setLandsOwned(1000); + state.setPopulation(100); + state.setBushels(1001); + Assert.assertEquals(1000, game.calculateAcresToPlant(1001, state.getLandsOwned(),state.getPopulation(), state.getBushels())); + } + @Test + public void howManyAcresToPlantTest2() { //Added + //If acres to be planted is more than population * 10 + state.setLandsOwned(1000); + state.setPopulation(90); + state.setBushels(1001); + Assert.assertEquals(900, game.calculateAcresToPlant(1000, state.getLandsOwned(),state.getPopulation(), state.getBushels())); + } + @Test + public void howManyAcresToPlantTest3() { //Added + //If acres to be planted is more than bushels + state.setLandsOwned(1100); + state.setPopulation(100); + state.setBushels(900); + Assert.assertEquals(900, game.calculateAcresToPlant(1000, state.getLandsOwned(),state.getPopulation(), state.getBushels())); + } + @Test + public void howManyAcresToPlantTest4() { //Added + //If acres to be planted is more than bushels and bushels is more than population + state.setLandsOwned(1100); + state.setPopulation(65); + state.setBushels(900); + Assert.assertEquals(650, game.calculateAcresToPlant(1000, state.getLandsOwned(), state.getPopulation(), state.getBushels())); + } + + @Test + public void howManyAcresToPlantTest5() { //Added + //If acres to be planted is more than population and population is more than acres owned + state.setLandsOwned(500); + state.setPopulation(65); + state.setBushels(1000); + Assert.assertEquals(500, game.calculateAcresToPlant(1000, state.getLandsOwned(),state.getPopulation(), state.getBushels())); + } + + @Test + public void howManyAcresToPlantTest6() { //Added + //If acres to be planted is more than acres owned and acres owned is more than bushels + state.setLandsOwned(800); + state.setPopulation(65); + state.setBushels(500); + Assert.assertEquals(500, game.calculateAcresToPlant(1000, state.getLandsOwned(),state.getPopulation(), state.getBushels())); + } + @Test + public void howManyAcresToPlantTest7() { //Added + //If everything is lower than acres to be planted + state.setLandsOwned(900); + state.setPopulation(90); + state.setBushels(800); + Assert.assertEquals(800, game.calculateAcresToPlant(1000, state.getLandsOwned(),state.getPopulation(), state.getBushels())); + } + @Test public final void testPlagueDeaths1() { GameEngine game = new GameEngine(); @@ -71,7 +167,7 @@ public final void testUprising() { @Test public final void testImmigrants() { GameEngine game = new GameEngine(); - int imm = game.immigrants(10, 1200, 500); + int imm = game.immigrants(10, 1200, 500, 200); assertEquals("Wrong number of immigrants.", 25, imm); } From 8bd5d9fd2045b88c93fee1f85a9e1387deb900ef Mon Sep 17 00:00:00 2001 From: Freddy Mintarja <115741236+fmintar1@users.noreply.github.com> Date: Sun, 13 Nov 2022 11:28:09 -0500 Subject: [PATCH 09/16] Committing take 999 --- src/main/java/GameEngine.java | 12 ++++-------- src/main/java/State.java | 24 ++++++++++++------------ src/main/java/UserInterface.java | 18 +++++++++--------- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java index 7286be7..5114adf 100644 --- a/src/main/java/GameEngine.java +++ b/src/main/java/GameEngine.java @@ -6,7 +6,6 @@ public class GameEngine { Random random = new Random(); int randomNum = random.nextInt(); - State state = new State(); //<- Added this to revise immigrants, can't have immigrants when starvationDeath occurs // ***************************************************************************************************************** // ***************** CONSTRUCTOR/GAME INITIALIZATION/ROUND INITILIZATION/EXIT @@ -15,7 +14,6 @@ public GameEngine() { } public int calculateAcresToBuy(int acresToBuy, int price, int bushels){ - state.setBushels(bushels); if ( (acresToBuy * price) > bushels){ System.out.println("You FOOL! You're trying to buy more than what you can afford, you get nothing and like it!"); return 0; @@ -24,11 +22,9 @@ public int calculateAcresToBuy(int acresToBuy, int price, int bushels){ } } - public int calculateAcresToSell(int acresToSell, int landOwned, int population) { - if( (landOwned*100)/population < 70){ - //GAME OVER - return 0; - } else if (acresToSell > landOwned) { + public int calculateAcresToSell(int acresToSell, int landOwned) { + if (acresToSell > landOwned) { + System.out.println("Selling too much than what you own"); return 0; } else { return acresToSell; @@ -100,7 +96,7 @@ public boolean uprising(int population, int howManyPeopleStarved) { } public int immigrants (int population, int acresOwned, int grainInStorage, int bushelsFedToPeople) { - if(starvationDeaths(population, bushelsFedToPeople) > 0) return 0; //Added this, read line 9 + if(starvationDeaths(population, bushelsFedToPeople) > 0) return 0; return (20 * acresOwned + grainInStorage) / (100 * population) + 1; } diff --git a/src/main/java/State.java b/src/main/java/State.java index 9053bb4..9d31322 100644 --- a/src/main/java/State.java +++ b/src/main/java/State.java @@ -8,17 +8,17 @@ public class State { public State(){ } - public State(int population, int landsOwned, int bushels, int year, int price, int pDeaths, int sDeaths, int immigrants, int harvest, int rats) { - setPopulation(population); //<-using setters instead of instance variable - setLandsOwned(landsOwned); - setBushels(bushels); - setYear(year); - setPrice(price); - setpDeaths(pDeaths); - setsDeaths(sDeaths); - setImmigrants(immigrants); - setHarvest(harvest); - setRats(rats); +// public State(int population, int landsOwned, int bushels, int year, int price, int pDeaths, int sDeaths, int immigrants, int harvest, int rats) { +// setPopulation(population); //<-using setters instead of instance variable +// setLandsOwned(landsOwned); +// setBushels(bushels); +// setYear(year); +// setPrice(price); +// setpDeaths(pDeaths); +// setsDeaths(sDeaths); +// setImmigrants(immigrants); +// setHarvest(harvest); +// setRats(rats); // this.population = population; // this.landsOwned = landsOwned; @@ -30,7 +30,7 @@ public State(int population, int landsOwned, int bushels, int year, int price, i // this.immigrants = immigrants; // this.harvest = harvest; // this.rats = rats; - } +// } public State(int population, int landsOwned, int bushels, int year, int price){ setPopulation(population); //<-Using setters instead of instance variable diff --git a/src/main/java/UserInterface.java b/src/main/java/UserInterface.java index cdfccc9..cf2870a 100644 --- a/src/main/java/UserInterface.java +++ b/src/main/java/UserInterface.java @@ -7,7 +7,7 @@ public class UserInterface { public void main() { - while(true){ //Initialize a loop to keep the game playing if the game ends and the player wants to play again + while(true){ //Changed (exitGame==false) to (true) to keep the game running setUpNewGame(); announceGame(); while(state.getYear() < 11){ // Starts the actual game @@ -39,7 +39,7 @@ public void main() { processRound(state.getPopulation(), bushelsFed, state.getLandsOwned(), acresToPlant*2, state.getBushels()); printSummary(); } - if(exitGame() == false) break; + if(exitGame() == false) break; //<-updated exit game to the bottom } } @@ -112,22 +112,22 @@ public void askHowManyAcresToBuy(int acresToBuy){ System.out.println("Bushels left: " + state.getBushels() + "\nacres bought: " + acresToBuy + "\nAcres update: " + state.getLandsOwned()); - System.out.println("\n"); - System.out.println("AMAZING! You bought " + acresToBuy + " acres!" ); - System.out.println("\n"); +// System.out.println("\n"); +// System.out.println("AMAZING! You bought " + acresToBuy + " acres!" ); +// System.out.println("\n"); } } public void askHowManyAcresToSell(int acresToSell){ - if (game.calculateAcresToSell(acresToSell, state.getLandsOwned(), state.getPopulation()) != 0){ + if (game.calculateAcresToSell(acresToSell, state.getLandsOwned()) != 0){ state.changeLandsOwned(-acresToSell); state.changeBushels(acresToSell * state.getPrice()); System.out.println("Bushels left: " + state.getBushels() + "\nacres sold: " + acresToSell + "\nAcres update: " + state.getLandsOwned()); - System.out.println("\n"); - System.out.println("AMAZING! You sold " + acresToSell + " acres!" ); - System.out.println("\n"); +// System.out.println("\n"); +// System.out.println("AMAZING! You sold " + acresToSell + " acres!" ); +// System.out.println("\n"); } } From 4f6b4a162e6ddc822667fb3f949f52f66e095961 Mon Sep 17 00:00:00 2001 From: Freddy Mintarja <115741236+fmintar1@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:25:35 -0500 Subject: [PATCH 10/16] FINAL PUSH --- src/main/java/GameEngine.java | 4 +- src/main/java/State.java | 18 +++++- src/main/java/UserInterface.java | 104 ++++++++++++++++++++----------- 3 files changed, 87 insertions(+), 39 deletions(-) diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java index 5114adf..f9089b7 100644 --- a/src/main/java/GameEngine.java +++ b/src/main/java/GameEngine.java @@ -24,7 +24,7 @@ public int calculateAcresToBuy(int acresToBuy, int price, int bushels){ public int calculateAcresToSell(int acresToSell, int landOwned) { if (acresToSell > landOwned) { - System.out.println("Selling too much than what you own"); + System.out.println("Selling too much than what you own!"); return 0; } else { return acresToSell; @@ -33,7 +33,6 @@ public int calculateAcresToSell(int acresToSell, int landOwned) { public int calculateGrainToFeedPeople(int bushels, int bushelsFed) { if (bushelsFed > bushels){ - System.out.println("You don't have enough grain for that!"); return 0; } else { return bushelsFed; @@ -85,7 +84,6 @@ public int plagueDeaths(int population) { } public int starvationDeaths(int population, int bushelsFedToPeople) { - //returning the number of deaths if(population - (int) floor(bushelsFedToPeople/20) < 0) return 0; return population - (int) floor(bushelsFedToPeople/20); } diff --git a/src/main/java/State.java b/src/main/java/State.java index 9d31322..bb111ee 100644 --- a/src/main/java/State.java +++ b/src/main/java/State.java @@ -2,7 +2,7 @@ public class State { int population, landsOwned, bushels, price, year; - int pDeaths, sDeaths, immigrants, harvest, rats; + int pDeaths, sDeaths, sDeathsPool, immigrants, harvest, rats, immigrantsPool; Random random = new Random(); public State(){ @@ -153,4 +153,20 @@ public int getRats() { public void setRats(int rats) { this.rats = rats; } + + public int getsDeathsPool() { + return sDeathsPool; + } + + public void setsDeathsPool(int sDeathsPool) { + this.sDeathsPool = sDeathsPool; + } + + public int getImmigrantsPool() { + return immigrantsPool; + } + + public void setImmigrantsPool(int immigrantsPool) { + this.immigrantsPool = immigrantsPool; + } } diff --git a/src/main/java/UserInterface.java b/src/main/java/UserInterface.java index cf2870a..f2e1444 100644 --- a/src/main/java/UserInterface.java +++ b/src/main/java/UserInterface.java @@ -7,11 +7,10 @@ public class UserInterface { public void main() { - while(true){ //Changed (exitGame==false) to (true) to keep the game running + while(true){ setUpNewGame(); announceGame(); - while(state.getYear() < 11){ // Starts the actual game - initializeRound(); + while(state.getYear() < 11){ // Asks how many acres to buy int acresToBuy = console.getNumber("How many acres would you like to buy? The price is currently " + state.getPrice() + " bushels per acre."); @@ -36,17 +35,26 @@ public void main() { // Asks how many acres to plant with grain int acresToPlant = console.getNumber("How many acres to plant?"); askHowManyAcresToPlant(acresToPlant); + processRound(state.getPopulation(), bushelsFed, state.getLandsOwned(), acresToPlant*2, state.getBushels()); + printSummary(); + + initializeRound(); + } + if(state.getYear() == 11) { //<-newly added, it works + badEnding(); + normalEnding(); + goodEnding(); } - if(exitGame() == false) break; //<-updated exit game to the bottom + if(exitGame() == false) break; } } public void setUpNewGame(){ state.setPopulation(100); state.setLandsOwned(1000); - state.setBushels(3000); + state.setBushels(2800); state.setYear(0); state.setPrice(19); state.setpDeaths(0); @@ -66,15 +74,15 @@ public void initializeRound(){ public void processRound(int population, int bushelsFedToPeople, int acresOwned, int bushelsUsedAsSeed, int bushels ){ - state.setpDeaths(game.plagueDeaths(population)); + state.setImmigrants(game.immigrants(population, acresOwned, bushels, bushelsFedToPeople)); + state.changePopulation(state.getImmigrants()); + + state.setpDeaths(game.plagueDeaths(state.getPopulation())); state.changePopulation(-state.getpDeaths()); state.setsDeaths(game.starvationDeaths(population, bushelsFedToPeople)); state.changePopulation(-state.getsDeaths()); - state.setImmigrants(game.immigrants(population, acresOwned, bushels, bushelsFedToPeople)); - state.changePopulation(state.getImmigrants()); - // state.setHarvest(game.harvest(bushelsUsedAsSeed)); // state.changeBushels(state.getHarvest()); <-Bugged due to RNG, recommend not use @@ -83,6 +91,10 @@ public void processRound(int population, int bushelsFedToPeople, int acresOwned, state.setPrice(state.newCostOfLand()); + state.setsDeathsPool(state.getsDeathsPool()+state.getsDeaths()); + + state.setImmigrantsPool(state.getImmigrantsPool() + state.getImmigrants()); + state.incrementYear(); } @@ -90,8 +102,9 @@ public void printSummary() { System.out.println("O great Hammurabi"); System.out.println("You are now in year " + state.getYear() + " of your ten year rule."); System.out.println("\n"); - System.out.println("In the previous year " + state.getsDeaths() + " people starved to death."); System.out.println("In the previous year "+ state.getImmigrants() + " entered the kingdom."); + System.out.println("In the previous year " + state.getsDeaths() + " people starved to death."); + System.out.println("In the previous year " + state.getpDeaths() + " people died from plague"); System.out.println("The population is now " + state.getPopulation()); // System.out.println("We harvested " + state.getHarvest() + " bushels"); <-Bugged due to RNG System.out.println("Rats destroyed " + state.getRats() + " bushels"); @@ -101,20 +114,11 @@ public void printSummary() { System.out.println("\n"); } - public void finalSummary() { - //String - } - public void askHowManyAcresToBuy(int acresToBuy){ if (game.calculateAcresToBuy(acresToBuy, state.getPrice(), state.getBushels()) != 0){ state.changeLandsOwned(acresToBuy); state.changeBushels(-(acresToBuy * state.getPrice())); - System.out.println("Bushels left: " + state.getBushels() - + "\nacres bought: " + acresToBuy - + "\nAcres update: " + state.getLandsOwned()); -// System.out.println("\n"); -// System.out.println("AMAZING! You bought " + acresToBuy + " acres!" ); -// System.out.println("\n"); + prompt(); } } @@ -122,33 +126,27 @@ public void askHowManyAcresToSell(int acresToSell){ if (game.calculateAcresToSell(acresToSell, state.getLandsOwned()) != 0){ state.changeLandsOwned(-acresToSell); state.changeBushels(acresToSell * state.getPrice()); - System.out.println("Bushels left: " + state.getBushels() - + "\nacres sold: " + acresToSell - + "\nAcres update: " + state.getLandsOwned()); -// System.out.println("\n"); -// System.out.println("AMAZING! You sold " + acresToSell + " acres!" ); -// System.out.println("\n"); + prompt(); } } public void askHowManyBushelsToFeedPeople(int bushelsFed){ if (game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed) != 0){ state.changeBushels(-bushelsFed); - System.out.println("Bushels left: " + state.getBushels() - + "\nbushels eaten: " + bushelsFed); + prompt(); + } else if (game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed) == 0) { + if (game.starvationDeaths(state.getPopulation(), game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed)) > state.getPopulation()*45/100){ + System.out.println("You monster! You killed all of your people"); //<-updated gameover + exitGame(); + } } } public void askHowManyAcresToPlant(int acresToPlant) { -// if (game.calculateAcresToPlant(acresToPlant, state.getLandsOwned(), state.getPopulation(), state.getBushels()) > 0) { acresToPlant = game.calculateAcresToPlant(acresToPlant, state.getLandsOwned(), state.getPopulation(), state.getBushels()); state.changeBushels(-acresToPlant); - System.out.println(state.getBushels()); state.changeBushels(game.harvest(acresToPlant)); - System.out.println("Acres planted: " + acresToPlant + - "\nUpdated Bushels " + state.getBushels()); - // FINISHED -// } else if (game.calculateAcresToPlant(acresToPlant, state.getLandsOwned(), state.getPopulation(), state.getBushels()) == 0) + prompt(); } public void announceGame () { @@ -170,10 +168,46 @@ public void announceGame () { System.out.println("Our coffers have " + state.getBushels() + " bushels in storage."); System.out.println("The city owns " + state.getLandsOwned() + " acres of land."); System.out.println("Land is available to purchase for " + state.getPrice() + " bushels per acre"); + System.out.println("Rats destroyed 200 bushels"); System.out.println("\n"); } + public void prompt() { //<-Newly added + System.out.println("Bushels left: " + state.getBushels() + + "\npopulation number: " + state.getPopulation() + + "\nAcres: " + state.getLandsOwned()); + } + public void gameEndingPrompt() { //<-Newly added + System.out.printf("You completed the game with %.4f%% starvation deaths out of %s\n", + (double) state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100, state.getPopulation()); + System.out.printf("You completed the game with %.4f acres per population\n", + (double) state.getLandsOwned() / state.getPopulation()); + } + public void badEnding() { //<- Newly added + if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 >= 10 || + state.getLandsOwned() / state.getPopulation() <= 9) { + gameEndingPrompt(); + System.out.println("While you brought your kingdom to make it through the years, you are " + + "still a terrible ruler. Your people hated your guts!"); + } + } + public void normalEnding() { //<-Newly added + if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 < 10 && + state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 > 3 || + state.getLandsOwned() / state.getPopulation() > 9 && + state.getLandsOwned() / state.getPopulation() <= 10) { + gameEndingPrompt(); + System.out.println("You have brought normalization to your kingdom. You are one boring ruler!"); + } + } + public void goodEnding() { //<-Newly added + if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 < 3 || + state.getLandsOwned() / state.getPopulation() > 10) { + gameEndingPrompt(); + System.out.println("Your kingdom is thriving! You are one superb ruler!"); + } + } - public boolean exitGame () { //fixed exitgame + public boolean exitGame () { int options = console.getNumber("Would you like to play? 1 = Yes, 2 = No"); boolean answer = true; switch (options) { From 9afea137be937612849ea4ab311789dd82228782 Mon Sep 17 00:00:00 2001 From: Emory Date: Sun, 13 Nov 2022 16:48:52 -0500 Subject: [PATCH 11/16] Moved all output/input to the console class --- src/main/java/Console.java | 145 +++++++++++++++++++-- src/main/java/UserInterface.java | 209 +++++++++++++------------------ 2 files changed, 220 insertions(+), 134 deletions(-) diff --git a/src/main/java/Console.java b/src/main/java/Console.java index 3c1c9bd..149e9df 100644 --- a/src/main/java/Console.java +++ b/src/main/java/Console.java @@ -2,30 +2,157 @@ import java.util.Scanner; public class Console { -Scanner scanner = new Scanner(System.in); + Scanner scanner = new Scanner(System.in); - // NEED TO CHANGE BOTH METHODS TO ENTER INPUT ON ANOTHER LINE +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// INPUT +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + public int acresToBuySOUT(int price){ + int acresToBuy = getNumber("How many acres would you like to buy? The price is currently " + price + " bushels per acre."); + return acresToBuy; + } + + public int acresToSellSOUT(int price){ + int acresToSell = getNumber("How many acres would you like to sell? The Price is currently " + price + " bushels per acre."); + return acresToSell; + } + + public int bushelsToFeed(){ + int bushelsFed = getNumber("How many bushels would you like to feed your nation?"); + return bushelsFed; + } + + public int acresToPlant(){ + int acresPlanted = getNumber("How many acres to plant?"); + return acresPlanted; + } + + public boolean exitGame() { + System.out.println("\n"); + int options = getNumber("Would you like to play again? 1 = Yes, 2 = No"); + boolean answer = true; + switch (options) { + case 1: + System.out.println("That's the spirit! Let's play again!"); + answer = true; + break; + case 2: + System.out.println("Goodbye :-("); + answer = false; + break; + } + return answer; + } + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// OUTPUT +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + public void announceGame(int population, int bushels, int landsOwned, int price) { + System.out.println("\n"); + System.out.println("Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office."); + System.out.println("Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people."); + System.out.println("Grain is the general currency, measured in bushels."); + System.out.println("\n"); + System.out.println("The following will help you in your decisions:"); + System.out.println("\n"); + System.out.println("**Each person needs at least 20 bushels of grain per year to survive**"); + System.out.println("**Each person can farm at most 10 acres of land**"); + System.out.println("**It takes 2 bushels of grain to farm an acre of land**"); + System.out.println("**The market price for land fluctuates yearly**"); + System.out.println("\n"); + System.out.println("Now, let's begin!"); + System.out.println("\n"); + System.out.println("O great One! Your kingdom await your orders!"); + System.out.println("There are " + population + " people that you must feed!"); + System.out.println("Our coffers have " + bushels + " bushels in storage."); + System.out.println("The city owns " + landsOwned + " acres of land."); + System.out.println("Land is available to purchase for " + price + " bushels per acre"); + System.out.println("Rats destroyed 200 bushels"); + System.out.println("\n"); + } + + public void printSummary(int year, int immigrants, int sDeaths, int pDeaths, int population, int rats, int bushels, int landsOwned, int price) { + System.out.println("\n"); + System.out.println("\n"); + System.out.println("O great Hammurabi"); + System.out.println("You are now in year " + year + " of your ten year rule."); + System.out.println("\n"); + System.out.println("In the previous year " + immigrants + " people came to the kingdom."); + System.out.println("In the previous year " + sDeaths + " people starved to death."); + System.out.println("In the previous year " + pDeaths + " people died from plague"); + System.out.println("The population is now " + population); +// System.out.println("We harvested " + state.getHarvest() + " bushels"); <-Bugged due to RNG, DO WE WANT TO FIX THIS? --EMORY + System.out.println("Rats destroyed " + rats + " bushels"); + System.out.println("There are only " + bushels + " bushels left in storage."); + System.out.println("The city owns " + landsOwned + " acres of land."); + System.out.println("Land is currently worth " + price + " bushels per acre"); + System.out.println("\n"); + } + + public void prompt(int bushels, int population, int landsOwned) { //<-Newly added + System.out.println("\n"); + System.out.println("Bushels left: " + bushels + + "\npopulation number: " + population + + "\nAcres: " + landsOwned); + System.out.println("\n"); + } + + public void gameEndingPrompt(int deathsPool, int immigrantsPool, int population, int landsOwned) { //<-Newly added + System.out.printf("You completed the game with %.4f%% starvation deaths out of %s\n", + (double) deathsPool / (1000 + immigrantsPool) * 100, population); + System.out.printf("You completed the game with %.4f acres per population\n", + (double) landsOwned / population); + } + + public void monster() { + System.out.println("\n"); + System.out.println("You MONSTER!! You killed so many people!! WE WILL AVENGE THEM!!!!!!"); + System.out.println("\n"); + } + + public void boring() { +// System.out.println("You brought great... okayness... to our kingdom... thanks for not killing all of us?"); + System.out.println("\n"); + System.out.println("You have brought normalization to your kingdom. You are one boring ruler!"); + System.out.println("\n"); + } + + public void thriving() { + System.out.println("\n"); + System.out.println("Your kingdom is thriving! You are one superb ruler!"); + System.out.println("\n"); + + } + + public void guts(){ + System.out.println("\n"); + System.out.println("While you brought your kingdom to make it through the years, you are " + + "still a terrible ruler. Your people hated your guts!"); + System.out.println("\n"); + } +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// SCANNERS +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int getNumber(String message) { while (true) { System.out.println(message); try { return scanner.nextInt(); - } - catch (InputMismatchException e) { + } catch (InputMismatchException e) { System.out.println("\"" + scanner.next() + "\" isn't a number!"); } } } - String getString(String message){ - while(true){ + String getString(String message) { + while (true) { System.out.println(message); try { return scanner.nextLine(); - } - catch (InputMismatchException e){ + } catch (InputMismatchException e) { System.out.println("\"" + scanner.next() + "\" isn't a word!"); } } } -} +} \ No newline at end of file diff --git a/src/main/java/UserInterface.java b/src/main/java/UserInterface.java index f2e1444..1ba9edf 100644 --- a/src/main/java/UserInterface.java +++ b/src/main/java/UserInterface.java @@ -7,51 +7,57 @@ public class UserInterface { public void main() { - while(true){ + while (true) { setUpNewGame(); - announceGame(); - while(state.getYear() < 11){ + console.announceGame(state.getPopulation(), state.getBushels(), state.getLandsOwned(), state.getPrice()); + + while (state.getYear() < 11) { // Asks how many acres to buy - int acresToBuy = console.getNumber("How many acres would you like to buy? The price is currently " + state.getPrice() + " bushels per acre."); - askHowManyAcresToBuy(acresToBuy); + askHowManyAcresToBuy(console.acresToBuySOUT(state.getPrice())); // Asks how many acres to sell - int acresToSell = console.getNumber("How many acres would you like to sell? The Price is currently " + state.getPrice() + " bushels per acre."); - askHowManyAcresToSell(acresToSell); - if(state.getLandsOwned() < state.getPopulation()*7) { //<-updated gameover - System.out.println("you are a national fink!"); + askHowManyAcresToSell(console.acresToSellSOUT(state.getPrice())); + + if (state.getLandsOwned() < state.getPopulation() * 7) { //<-updated gameover + console.monster(); break; } // Asks how many bushels to feed to people - int bushelsFed = console.getNumber("How many bushels would you like to feed your nation?"); + int bushelsFed = console.bushelsToFeed(); askHowManyBushelsToFeedPeople(bushelsFed); - if(game.starvationDeaths(state.getPopulation(), bushelsFed) > state.getPopulation()*45/100) { - System.out.println("you are a national fink!"); //<-updated gameover + if (game.starvationDeaths(state.getPopulation(), bushelsFed) > state.getPopulation() * 45 / 100) { + + console.monster(); //<-updated gameover break; } // Asks how many acres to plant with grain - int acresToPlant = console.getNumber("How many acres to plant?"); - askHowManyAcresToPlant(acresToPlant); + int acresPlanted = console.acresToPlant(); + askHowManyAcresToPlant(acresPlanted); - processRound(state.getPopulation(), bushelsFed, state.getLandsOwned(), acresToPlant*2, state.getBushels()); + //Process the round, print data, and initialize the next round - printSummary(); + processRound(state.getPopulation(), bushelsFed, state.getLandsOwned(), acresPlanted * 2, state.getBushels()); + + console.printSummary(state.getYear(), state.getImmigrants(), state.sDeaths, state.pDeaths, state.getPopulation(), state.getRats(), state.getBushels(), state.getLandsOwned(), state.getPrice()); initializeRound(); + } - if(state.getYear() == 11) { //<-newly added, it works + + if (state.getYear() == 11) { //<-newly added, it works badEnding(); normalEnding(); goodEnding(); } - if(exitGame() == false) break; + + if (console.exitGame() == false) break; } } - public void setUpNewGame(){ + public void setUpNewGame() { state.setPopulation(100); state.setLandsOwned(1000); state.setBushels(2800); @@ -64,7 +70,7 @@ public void setUpNewGame(){ state.setRats(0); } - public void initializeRound(){ + public void initializeRound() { state.setpDeaths(0); state.setsDeaths(0); state.setImmigrants(0); @@ -72,7 +78,7 @@ public void initializeRound(){ state.setRats(0); } - public void processRound(int population, int bushelsFedToPeople, int acresOwned, int bushelsUsedAsSeed, int bushels ){ + public void processRound(int population, int bushelsFedToPeople, int acresOwned, int bushelsUsedAsSeed, int bushels) { state.setImmigrants(game.immigrants(population, acresOwned, bushels, bushelsFedToPeople)); state.changePopulation(state.getImmigrants()); @@ -84,142 +90,95 @@ public void processRound(int population, int bushelsFedToPeople, int acresOwned, state.changePopulation(-state.getsDeaths()); // state.setHarvest(game.harvest(bushelsUsedAsSeed)); -// state.changeBushels(state.getHarvest()); <-Bugged due to RNG, recommend not use +// state.changeBushels(state.getHarvest()); <-Bugged due to RNG, recommend not use DO WE WANT TO FIX THIS??? -- EMORY state.setRats(game.grainEatenByRats(bushels)); state.changeBushels(-state.getRats()); state.setPrice(state.newCostOfLand()); - state.setsDeathsPool(state.getsDeathsPool()+state.getsDeaths()); + state.setsDeathsPool(state.getsDeathsPool() + state.getsDeaths()); state.setImmigrantsPool(state.getImmigrantsPool() + state.getImmigrants()); state.incrementYear(); } - public void printSummary() { - System.out.println("O great Hammurabi"); - System.out.println("You are now in year " + state.getYear() + " of your ten year rule."); - System.out.println("\n"); - System.out.println("In the previous year "+ state.getImmigrants() + " entered the kingdom."); - System.out.println("In the previous year " + state.getsDeaths() + " people starved to death."); - System.out.println("In the previous year " + state.getpDeaths() + " people died from plague"); - System.out.println("The population is now " + state.getPopulation()); -// System.out.println("We harvested " + state.getHarvest() + " bushels"); <-Bugged due to RNG - System.out.println("Rats destroyed " + state.getRats() + " bushels"); - System.out.println("There are only " + state.getBushels() + " bushels left in storage."); - System.out.println("The city owns " + state.getLandsOwned() + " acres of land."); - System.out.println("Land is currently worth " + state.getPrice() + " bushels per acre"); - System.out.println("\n"); - } + public void askHowManyAcresToBuy(int acresToBuy) { + if (game.calculateAcresToBuy(acresToBuy, state.getPrice(), state.getBushels()) != 0) { - public void askHowManyAcresToBuy(int acresToBuy){ - if (game.calculateAcresToBuy(acresToBuy, state.getPrice(), state.getBushels()) != 0){ state.changeLandsOwned(acresToBuy); state.changeBushels(-(acresToBuy * state.getPrice())); - prompt(); + + console.prompt(state.getBushels(), state.getPopulation(), state.getLandsOwned()); } } - public void askHowManyAcresToSell(int acresToSell){ - if (game.calculateAcresToSell(acresToSell, state.getLandsOwned()) != 0){ + public void askHowManyAcresToSell(int acresToSell) { + if (game.calculateAcresToSell(acresToSell, state.getLandsOwned()) != 0) { + state.changeLandsOwned(-acresToSell); state.changeBushels(acresToSell * state.getPrice()); - prompt(); + + console.prompt(state.getBushels(), state.getPopulation(), state.getLandsOwned()); } } - public void askHowManyBushelsToFeedPeople(int bushelsFed){ - if (game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed) != 0){ + public void askHowManyBushelsToFeedPeople(int bushelsFed) { + + if (game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed) != 0) { + state.changeBushels(-bushelsFed); - prompt(); + + console.prompt(state.getBushels(), state.getPopulation(), state.getLandsOwned()); + } else if (game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed) == 0) { - if (game.starvationDeaths(state.getPopulation(), game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed)) > state.getPopulation()*45/100){ - System.out.println("You monster! You killed all of your people"); //<-updated gameover - exitGame(); + if (game.starvationDeaths(state.getPopulation(), game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed)) > state.getPopulation() * 45 / 100) { + + console.monster(); //<-updated gameover + console.exitGame(); + } } } - public void askHowManyAcresToPlant(int acresToPlant) { - acresToPlant = game.calculateAcresToPlant(acresToPlant, state.getLandsOwned(), state.getPopulation(), state.getBushels()); - state.changeBushels(-acresToPlant); - state.changeBushels(game.harvest(acresToPlant)); - prompt(); + public void askHowManyAcresToPlant(int acresPlanted) { + acresPlanted = game.calculateAcresToPlant(acresPlanted, state.getLandsOwned(), state.getPopulation(), state.getBushels()); + + state.changeBushels(-acresPlanted); + state.changeBushels(game.harvest(acresPlanted)); + + console.prompt(state.getBushels(), state.getPopulation(), state.getLandsOwned()); } - public void announceGame () { - System.out.println("Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office."); - System.out.println("Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people."); - System.out.println("Grain is the general currency, measured in bushels."); - System.out.println("\n"); - System.out.println("The following will help you in your decisions:"); - System.out.println("\n"); - System.out.println("**Each person needs at least 20 bushels of grain per year to survive**"); - System.out.println("**Each person can farm at most 10 acres of land**"); - System.out.println("**It takes 2 bushels of grain to farm an acre of land**"); - System.out.println("**The market price for land fluctuates yearly**"); - System.out.println("\n"); - System.out.println("Now, let's begin!"); - System.out.println("\n"); - System.out.println("O great One! Your kingdom await your orders!"); - System.out.println("There are " + state.getPopulation() + " people that you must feed!"); - System.out.println("Our coffers have " + state.getBushels() + " bushels in storage."); - System.out.println("The city owns " + state.getLandsOwned() + " acres of land."); - System.out.println("Land is available to purchase for " + state.getPrice() + " bushels per acre"); - System.out.println("Rats destroyed 200 bushels"); - System.out.println("\n"); - } - public void prompt() { //<-Newly added - System.out.println("Bushels left: " + state.getBushels() - + "\npopulation number: " + state.getPopulation() - + "\nAcres: " + state.getLandsOwned()); - } - public void gameEndingPrompt() { //<-Newly added - System.out.printf("You completed the game with %.4f%% starvation deaths out of %s\n", - (double) state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100, state.getPopulation()); - System.out.printf("You completed the game with %.4f acres per population\n", - (double) state.getLandsOwned() / state.getPopulation()); - } - public void badEnding() { //<- Newly added - if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 >= 10 || - state.getLandsOwned() / state.getPopulation() <= 9) { - gameEndingPrompt(); - System.out.println("While you brought your kingdom to make it through the years, you are " + - "still a terrible ruler. Your people hated your guts!"); - } - } - public void normalEnding() { //<-Newly added - if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 < 10 && - state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 > 3 || - state.getLandsOwned() / state.getPopulation() > 9 && - state.getLandsOwned() / state.getPopulation() <= 10) { - gameEndingPrompt(); - System.out.println("You have brought normalization to your kingdom. You are one boring ruler!"); - } + public void badEnding() { //<- Newly added + if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 >= 10 || + state.getLandsOwned() / state.getPopulation() <= 9) { + + console.gameEndingPrompt(state.getsDeathsPool(), state.getImmigrantsPool(), state.getPopulation(), state.getLandsOwned()); + console.guts(); } - public void goodEnding() { //<-Newly added - if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 < 3 || - state.getLandsOwned() / state.getPopulation() > 10) { - gameEndingPrompt(); - System.out.println("Your kingdom is thriving! You are one superb ruler!"); - } + } + + public void normalEnding() { //<-Newly added + if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 < 10 && + state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 > 3 || + state.getLandsOwned() / state.getPopulation() > 9 && + state.getLandsOwned() / state.getPopulation() <= 10) { + + console.gameEndingPrompt(state.getsDeathsPool(), state.getImmigrantsPool(), state.getPopulation(), state.getLandsOwned()); + console.boring(); } + } + + public void goodEnding() { //<-Newly added + if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 < 3 || + state.getLandsOwned() / state.getPopulation() > 10) { + + console.gameEndingPrompt(state.getsDeathsPool(), state.getImmigrantsPool(), state.getPopulation(), state.getLandsOwned()); + console.thriving(); - public boolean exitGame () { - int options = console.getNumber("Would you like to play? 1 = Yes, 2 = No"); - boolean answer = true; - switch (options) { - case 1: - System.out.println("That's the spirit!"); - answer = true; - break; - case 2: - System.out.println("Goodbye"); - answer = false; - break; - } - return answer; } -} + } + +} \ No newline at end of file From 599a264ab0f97db2e411d109feefe9206e5c9e86 Mon Sep 17 00:00:00 2001 From: Freddy Mintarja <115741236+fmintar1@users.noreply.github.com> Date: Sun, 13 Nov 2022 18:36:45 -0500 Subject: [PATCH 12/16] Wrote all possible tests, all passed --- src/main/java/GameEngine.java | 1 - src/test/java/GameEngineTest.java | 10 -- src/test/java/StateTest.java | 148 +++++++++++++++++++++++------- 3 files changed, 116 insertions(+), 43 deletions(-) diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java index f9089b7..1eb8de2 100644 --- a/src/main/java/GameEngine.java +++ b/src/main/java/GameEngine.java @@ -5,7 +5,6 @@ public class GameEngine { Random random = new Random(); - int randomNum = random.nextInt(); // ***************************************************************************************************************** // ***************** CONSTRUCTOR/GAME INITIALIZATION/ROUND INITILIZATION/EXIT diff --git a/src/test/java/GameEngineTest.java b/src/test/java/GameEngineTest.java index f542ad1..587b5cc 100644 --- a/src/test/java/GameEngineTest.java +++ b/src/test/java/GameEngineTest.java @@ -14,16 +14,6 @@ boolean about(double expected, double actual) { return actual > 0.90 * expected && actual < 1.10 * expected; } - - @Test - public void calculateHowManyAcresToBuyTest(){ - State state = new State(100, 1000, 3000, 0, 19); - GameEngine game = new GameEngine(); - int expected = 10; - int actual = game.calculateAcresToBuy(20, state.getPrice(), state.getBushels()); - Assert.assertEquals(expected, actual); - } - @Test public void HowManyAcresToBuyTest1() { //If price of acres are at maximum of 24 diff --git a/src/test/java/StateTest.java b/src/test/java/StateTest.java index c275476..d19d71c 100644 --- a/src/test/java/StateTest.java +++ b/src/test/java/StateTest.java @@ -2,10 +2,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*; class StateTest { + GameEngine game = new GameEngine(); @BeforeEach public void setUp() { @@ -17,7 +18,7 @@ void getPopulationTest() { State state = new State(100, 1000, 3000, 0, 19); int expected = 100; int actual = state.getPopulation(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -26,7 +27,7 @@ void setPopulationTest() { int expected = 200; state.setPopulation(200); int actual = state.getPopulation(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -35,7 +36,7 @@ void changePopulationTest() { int expected = 50; state.changePopulation(-50); int actual = state.getPopulation(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -43,7 +44,7 @@ void getLandsOwnedTest() { State state = new State(100, 1000, 3000, 0, 19); int expected = 1000; int actual = state.getLandsOwned(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -52,7 +53,7 @@ void setLandsOwnedTest() { int expected = 2000; state.setLandsOwned(2000); int actual = state.getLandsOwned(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -61,15 +62,27 @@ void changeLandsOwnedTest() { int expected = 900; state.changeLandsOwned(-100); int actual = state.getLandsOwned(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); + } + @Test + public final void testNewCostOfLand() { + State state = new State(100, 1000, 3000, 0, 19); + int[] cost = new int[24]; + for (int i = 0; i < 1000; i++) { + int price = state.newCostOfLand(); + assertTrue("Illegal cost of land: " + price, price >= 17 && price <= 23); + cost[price] += 1; + } + for (int j = 17; j <= 23; j++) { + assertTrue("You never have a land cost of " + j + " bushels per acre.", cost[j] > 0); + } } - @Test void getBushelsTest() { State state = new State(100, 1000, 3000, 0, 19); int expected = 3000; int actual = state.getBushels(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -78,7 +91,7 @@ void setBushelsTest() { int expected = 5000; state.setBushels(5000); int actual = state.getBushels(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -87,7 +100,7 @@ void changeBushelsTest() { int expected = 2900; state.changeBushels(-100); int actual = state.getBushels(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -95,7 +108,7 @@ void getPriceTest() { State state = new State(100, 1000, 3000, 0, 19); int expected = 19; int actual = state.getPrice(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -104,30 +117,14 @@ void setPriceTest() { int expected = 23; state.setPrice(23); int actual = state.getPrice(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } - - @Test - public final void testNewCostOfLand() { - State state = new State(100, 1000, 3000, 0, 19); - int[] cost = new int[24]; - for (int i = 0; i < 1000; i++) { - int price = state.newCostOfLand(); - assertTrue("Illegal cost of land: " + price, price >= 17 && price <= 23); - cost[price] += 1; - } - for (int j = 17; j <= 23; j++) { - assertTrue("You never have a land cost of " + j + " bushels per acre.", cost[j] > 0); - } - } - - @Test void getYear() { State state = new State(100, 1000, 3000, 0, 19); int expected = 0; int actual = state.getYear(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -136,7 +133,7 @@ void setYear() { int expected = 5; state.setYear(5); int actual = state.getYear(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -145,6 +142,93 @@ void incrementYear() { int expected = 1; state.incrementYear(); int actual = state.getYear(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); + } + @Test + void getpDeathsTest() { + State state = new State(100, 1000, 3000, 0, 19); + state.setpDeaths(game.plagueDeaths(state.getPopulation())); + assertTrue("Plague deaths are: " + state.getpDeaths(), + state.getpDeaths() == 50 || state.getpDeaths() == 0); + } + @Test + void setpDeathsTest() { + State state = new State(100, 1000, 3000, 0, 19); + state.setpDeaths(50); + assertEquals(50, state.getpDeaths()); + } + @Test + void getsDeathsTest() { + State state = new State(100, 1000, 3000, 0, 19); + state.setsDeaths(game.starvationDeaths(state.getPopulation(), 1200)); + int expected = state.getsDeaths(); + assertEquals(40, expected); + } + @Test + void setsDeathsTest() { + State state = new State(100, 1000, 3000, 0, 19); + state.setsDeaths(40); + assertEquals(40, state.getsDeaths()); } + + @Test + void getImmigrantsTest() { + State state = new State(100, 1000, 3000, 0, 19); + state.setImmigrants(game.immigrants(state.getPopulation(), state.getLandsOwned(), state.getBushels(), 2000)); + assertEquals(3, state.getImmigrants()); + } + @Test + void setImmigrantsTest() { + State state = new State(100, 1000, 3000, 0, 19); + state.setImmigrants(3); + assertEquals(3, state.getImmigrants()); + } + @Test + void getHarvestTest() { + State state = new State(100, 1000, 3000, 0, 19); + state.setHarvest(800); + assertEquals(800, state.getHarvest()); + } + @Test + void setHarvestTest() { + State state = new State(100, 1000, 3000, 0, 19); + } + @Test + void getRats() { + State state = new State(100, 1000, 3000, 0, 19); + state.setRats(game.grainEatenByRats(state.getBushels())); + assertTrue("Infestation: " + state.getRats(), + state.getRats() == 0 || state.getRats() <= 900 && state.getRats() >= 300); + } + @Test + void setRats() { + State state = new State(100, 1000, 3000, 0, 19); + state.setRats(300); + assertEquals(300, state.getRats()); + } + @Test + void getsDeathsPool() { + State state = new State(100, 1000, 3000, 0, 19); + state.setsDeathsPool(state.getsDeathsPool() + state.getsDeaths()); + assertEquals(0, state.getsDeathsPool()); + } + @Test + void setsDeathsPool() { + State state = new State(100, 1000, 3000, 0, 19); + state.setsDeathsPool(10); + assertEquals(10, state.getsDeathsPool()); + } + @Test + void getImmigrantsPoolTest() { + State state = new State(100, 1000, 3000, 0, 19); + state.setImmigrantsPool(state.getImmigrantsPool() + state.getImmigrants()); + assertEquals(0, state.getImmigrantsPool()); + } + @Test + void setImmigrantsPoolTest() { + State state = new State(100, 1000, 3000, 0, 19); + state.setImmigrantsPool(5); + assertEquals(5, state.getImmigrantsPool()); + } + } \ No newline at end of file From 1aff8297079dd2a7678888023edfbb77627ecebf Mon Sep 17 00:00:00 2001 From: Freddy Mintarja <115741236+fmintar1@users.noreply.github.com> Date: Mon, 14 Nov 2022 06:27:01 -0500 Subject: [PATCH 13/16] Space Version --- src/main/java/Console.java | 151 +++++++++++++++++++++++++--------- src/main/java/GameEngine.java | 18 +++- 2 files changed, 130 insertions(+), 39 deletions(-) diff --git a/src/main/java/Console.java b/src/main/java/Console.java index 149e9df..d66bf49 100644 --- a/src/main/java/Console.java +++ b/src/main/java/Console.java @@ -8,22 +8,26 @@ public class Console { // INPUT //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public int acresToBuySOUT(int price){ - int acresToBuy = getNumber("How many acres would you like to buy? The price is currently " + price + " bushels per acre."); +// int acresToBuy = getNumber("How many acres would you like to buy? The price is currently " + price + " bushels per acre."); + int acresToBuy = getNumber("How many galaxies would you like to buy? The price is currently " + price + " stars per galaxy."); return acresToBuy; } public int acresToSellSOUT(int price){ - int acresToSell = getNumber("How many acres would you like to sell? The Price is currently " + price + " bushels per acre."); +// int acresToSell = getNumber("How many acres would you like to sell? The Price is currently " + price + " bushels per acre."); + int acresToSell = getNumber("How many galaxies would you like to sell? The price is currently " + price + " stars per galaxy."); return acresToSell; } public int bushelsToFeed(){ - int bushelsFed = getNumber("How many bushels would you like to feed your nation?"); +// int bushelsFed = getNumber("How many bushels would you like to feed your nation?"); + int bushelsFed = getNumber("How many stars would you like to feed your aliens with?"); return bushelsFed; } public int acresToPlant(){ - int acresPlanted = getNumber("How many acres to plant?"); + int acresPlanted = getNumber("How many galaxies to duplicate stars?"); +// int acresPlanted = getNumber("How many acres to plant?"); return acresPlanted; } @@ -49,86 +53,159 @@ public boolean exitGame() { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void announceGame(int population, int bushels, int landsOwned, int price) { - System.out.println("\n"); - System.out.println("Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office."); - System.out.println("Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people."); - System.out.println("Grain is the general currency, measured in bushels."); +// System.out.println("\n"); +// System.out.println("Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office."); +// System.out.println("Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people."); +// System.out.println("Grain is the general currency, measured in bushels."); +// System.out.println("\n"); +// System.out.println("The following will help you in your decisions:"); +// System.out.println("\n"); +// System.out.println("**Each person needs at least 20 bushels of grain per year to survive**"); +// System.out.println("**Each person can farm at most 10 acres of land**"); +// System.out.println("**It takes 1 bushel of grain to farm an acre of land**"); +// System.out.println("**The market price for land fluctuates yearly**"); +// System.out.println("**It's recommended to calculate before answering, there is no turning back**"); +// System.out.println("\n"); +// System.out.println("**WARNING!!!**"); +// System.out.println("**THE GAME IS OVER WHEN DEATH BY STARVATION IS MORE THAN 45% OF CURRENT POPULATION!!!**"); +// System.out.println("**THE GAME IS OVER WHEN ACRES ARE LESS THAN 7 PER POPULATION!!!**"); +// System.out.println("\n"); +// System.out.println("Now, let's begin!"); +// System.out.println("\n"); +// System.out.println("O great One! Your kingdom await your orders!"); +// System.out.println("There are " + population + " people that you must feed!"); +// System.out.println("Our coffers have " + bushels + " bushels in storage."); +// System.out.println("The city owns " + landsOwned + " acres of land."); +// System.out.println("Land is available to purchase for " + price + " bushels per acre"); +// System.out.println("Rats destroyed 200 bushels"); +// System.out.println("\n"); + System.out.println("\n"); + System.out.println("Greetings, commander. You have been selected by the Universe of ZCW8.2 to lead for ten million years."); + System.out.println("For the sake of the aliens, you need to feed them with stars, and using galaxies to duplicate the stars"); + System.out.println("You may also buy and sell galaxies by the transaction of stars"); System.out.println("\n"); System.out.println("The following will help you in your decisions:"); System.out.println("\n"); - System.out.println("**Each person needs at least 20 bushels of grain per year to survive**"); - System.out.println("**Each person can farm at most 10 acres of land**"); - System.out.println("**It takes 2 bushels of grain to farm an acre of land**"); - System.out.println("**The market price for land fluctuates yearly**"); + System.out.println("**Each alien needs at least 20 stars per 1 million years to survive**"); + System.out.println("**Each alien can utilize at most 10 galaxies to grow stars**"); + System.out.println("**To duplicate stars, each galaxy needs 1 star**"); + System.out.println("**The stars cost for galaxy fluctuates every 1 million years**"); + System.out.println("**It's recommended to calculate before answering, there is no turning back**"); + System.out.println("\n"); + System.out.println("**WARNING!!!**"); + System.out.println("**THE GAME IS OVER WHEN DEATH BY STARVATION IS MORE THAN 45% OF CURRENT ALIENS!!!**"); + System.out.println("**THE GAME IS OVER WHEN GALAXIES ARE LESS THAN 7 PER ALIEN!!!**"); System.out.println("\n"); System.out.println("Now, let's begin!"); System.out.println("\n"); - System.out.println("O great One! Your kingdom await your orders!"); - System.out.println("There are " + population + " people that you must feed!"); - System.out.println("Our coffers have " + bushels + " bushels in storage."); - System.out.println("The city owns " + landsOwned + " acres of land."); - System.out.println("Land is available to purchase for " + price + " bushels per acre"); - System.out.println("Rats destroyed 200 bushels"); + System.out.println("Commander, ZCW8.2 is currently waiting for your order."); + System.out.println("There are " + population + " aliens that you must feed"); + System.out.println("Our wormhole currently has " + bushels + " stars in dimension"); + System.out.println("ZCW8.2 has " + landsOwned + " galaxies in our possession"); + System.out.println("Galaxies are available for trading for " + price + " stars"); + System.out.println("Space pirates destroyed 200 stars"); System.out.println("\n"); } public void printSummary(int year, int immigrants, int sDeaths, int pDeaths, int population, int rats, int bushels, int landsOwned, int price) { System.out.println("\n"); System.out.println("\n"); - System.out.println("O great Hammurabi"); - System.out.println("You are now in year " + year + " of your ten year rule."); + System.out.println("Greetings, Commander"); + System.out.println("You are now in year " + year + " million of your ten million year rule"); System.out.println("\n"); - System.out.println("In the previous year " + immigrants + " people came to the kingdom."); - System.out.println("In the previous year " + sDeaths + " people starved to death."); - System.out.println("In the previous year " + pDeaths + " people died from plague"); + System.out.println("In the previous 1 million years, " + immigrants + " aliens came to ZCW8.2"); + System.out.println("In the previous 1 million years, " + sDeaths + " aliens starved to death"); + System.out.println("In the previous 1 million years, " + pDeaths + " aliens died from EMPs"); System.out.println("The population is now " + population); // System.out.println("We harvested " + state.getHarvest() + " bushels"); <-Bugged due to RNG, DO WE WANT TO FIX THIS? --EMORY - System.out.println("Rats destroyed " + rats + " bushels"); - System.out.println("There are only " + bushels + " bushels left in storage."); - System.out.println("The city owns " + landsOwned + " acres of land."); - System.out.println("Land is currently worth " + price + " bushels per acre"); + System.out.println("Space pirates destroyed " + rats + " stars"); + System.out.println("There are " + bushels + " stars left in the wormhole"); + System.out.println("ZCW8.2 has " + landsOwned + " galaxies in our possession"); + System.out.println("Galaxies are available for trading for " + price + " stars"); System.out.println("\n"); } +// System.out.println("\n"); +// System.out.println("\n"); +// System.out.println("O great Hammurabi"); +// System.out.println("You are now in year " + year + " of your ten year rule."); +// System.out.println("\n"); +// System.out.println("In the previous year " + immigrants + " people came to the kingdom."); +// System.out.println("In the previous year " + sDeaths + " people starved to death."); +// System.out.println("In the previous year " + pDeaths + " people died from plague"); +// System.out.println("The population is now " + population); +//// System.out.println("We harvested " + state.getHarvest() + " bushels"); <-Bugged due to RNG, DO WE WANT TO FIX THIS? --EMORY +// System.out.println("Rats destroyed " + rats + " bushels"); +// System.out.println("There are only " + bushels + " bushels left in storage."); +// System.out.println("The city owns " + landsOwned + " acres of land."); +// System.out.println("Land is currently worth " + price + " bushels per acre"); +// System.out.println("\n"); +//} public void prompt(int bushels, int population, int landsOwned) { //<-Newly added +// System.out.println("\n"); +// System.out.println("Bushels left: " + bushels +// + "\npopulation number: " + population +// + "\nAcres: " + landsOwned); +// System.out.println("\n"); +// } System.out.println("\n"); - System.out.println("Bushels left: " + bushels - + "\npopulation number: " + population - + "\nAcres: " + landsOwned); + System.out.println("Stars remaining: " + bushels + + "\nAliens number: " + population + + "\nGalaxies: " + landsOwned); System.out.println("\n"); } public void gameEndingPrompt(int deathsPool, int immigrantsPool, int population, int landsOwned) { //<-Newly added +// System.out.printf("You completed the game with %.4f%% starvation deaths out of %s\n", +// (double) deathsPool / (1000 + immigrantsPool) * 100, population); +// System.out.printf("You completed the game with %.4f acres per population\n", +// (double) landsOwned / population); +// } System.out.printf("You completed the game with %.4f%% starvation deaths out of %s\n", (double) deathsPool / (1000 + immigrantsPool) * 100, population); - System.out.printf("You completed the game with %.4f acres per population\n", + System.out.printf("You completed the game with %.4f galaxies per alien\n", (double) landsOwned / population); } public void monster() { +// System.out.println("\n"); +// System.out.println("You MONSTER!! You killed so many people!! WE WILL AVENGE THEM!!!!!!"); +// System.out.println("\n"); +// } System.out.println("\n"); - System.out.println("You MONSTER!! You killed so many people!! WE WILL AVENGE THEM!!!!!!"); + System.out.println("Due to your terrible decisions making, you are hereby dethroned from your Commander position and are being hunted by the aliens."); System.out.println("\n"); } public void boring() { // System.out.println("You brought great... okayness... to our kingdom... thanks for not killing all of us?"); +// System.out.println("\n"); +// System.out.println("You have brought normalization to your kingdom. You are one boring ruler!"); +// System.out.println("\n"); +// } System.out.println("\n"); - System.out.println("You have brought normalization to your kingdom. You are one boring ruler!"); + System.out.println("You have made it to the end of the 10 million years without much damage or extra miles. The aliens thanked you."); System.out.println("\n"); } public void thriving() { +// System.out.println("\n"); +// System.out.println("Your kingdom is thriving! You are one superb ruler!"); +// System.out.println("\n"); +// } System.out.println("\n"); - System.out.println("Your kingdom is thriving! You are one superb ruler!"); + System.out.println("On behalf of ZCW8.2, we thank you for your effort to drive the Universe forward. GLaDOS have a cake for you."); System.out.println("\n"); - } public void guts(){ +// System.out.println("\n"); +// System.out.println("While you brought your kingdom to make it through the years, you are " + +// "still a terrible ruler. Your people hated your guts!"); +// System.out.println("\n"); +// } System.out.println("\n"); - System.out.println("While you brought your kingdom to make it through the years, you are " + - "still a terrible ruler. Your people hated your guts!"); + System.out.println("You have made it to the end of 10 million years. However, the aliens are currently building a time machine to undo your mistakes."); System.out.println("\n"); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java index 1eb8de2..ba5a529 100644 --- a/src/main/java/GameEngine.java +++ b/src/main/java/GameEngine.java @@ -13,8 +13,15 @@ public GameEngine() { } public int calculateAcresToBuy(int acresToBuy, int price, int bushels){ +// if ( (acresToBuy * price) > bushels){ +// System.out.println("You FOOL! You're trying to buy more than what you can afford, you get nothing and like it!"); +// return 0; +// } else { +// return acresToBuy; +// } +// } if ( (acresToBuy * price) > bushels){ - System.out.println("You FOOL! You're trying to buy more than what you can afford, you get nothing and like it!"); + System.out.println("Commander, since you are being greedy, ZCW8.2 malfunctions and hereby unable to purchase any galaxies for 1 million years"); return 0; } else { return acresToBuy; @@ -22,8 +29,15 @@ public int calculateAcresToBuy(int acresToBuy, int price, int bushels){ } public int calculateAcresToSell(int acresToSell, int landOwned) { +// if (acresToSell > landOwned) { +// System.out.println("Selling too much than what you own!"); +// return 0; +// } else { +// return acresToSell; +// } +// } if (acresToSell > landOwned) { - System.out.println("Selling too much than what you own!"); + System.out.println("Commander, since you are being greedy, ZCW8.2 malfunctions and hereby unable to sell any galaxies for 1 million years"); return 0; } else { return acresToSell; From 6cbfdfec550dc251a1fb99fd3e65dc2cde404818 Mon Sep 17 00:00:00 2001 From: Emory Date: Mon, 14 Nov 2022 08:45:27 -0500 Subject: [PATCH 14/16] Last minute bug fixes --- src/main/java/Console.java | 17 +++++++++++------ src/main/java/GameEngine.java | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/Console.java b/src/main/java/Console.java index 149e9df..a5c9284 100644 --- a/src/main/java/Console.java +++ b/src/main/java/Console.java @@ -56,10 +56,10 @@ public void announceGame(int population, int bushels, int landsOwned, int price) System.out.println("\n"); System.out.println("The following will help you in your decisions:"); System.out.println("\n"); - System.out.println("**Each person needs at least 20 bushels of grain per year to survive**"); - System.out.println("**Each person can farm at most 10 acres of land**"); - System.out.println("**It takes 2 bushels of grain to farm an acre of land**"); - System.out.println("**The market price for land fluctuates yearly**"); + System.out.println("** Each person needs at least 20 bushels of grain per year to survive"); + System.out.println("** Each person can farm at most 10 acres of land"); + System.out.println("** It takes 2 bushels of grain to farm an acre of land"); + System.out.println("** The market price for land fluctuates yearly"); System.out.println("\n"); System.out.println("Now, let's begin!"); System.out.println("\n"); @@ -99,8 +99,13 @@ public void prompt(int bushels, int population, int landsOwned) { //<-Newly adde } public void gameEndingPrompt(int deathsPool, int immigrantsPool, int population, int landsOwned) { //<-Newly added - System.out.printf("You completed the game with %.4f%% starvation deaths out of %s\n", - (double) deathsPool / (1000 + immigrantsPool) * 100, population); +// System.out.printf("You completed the game with %.4f%% starvation deaths out of %s\n", +// (double) deathsPool / (1000 + immigrantsPool) * 100, population); +// System.out.printf("You completed the game with %.4f acres per population\n", +// (double) landsOwned / population); + + System.out.printf("You completed the game with %.4f%% starvation deaths, %s deaths by starvation vs %s of the total population\n", + (double) deathsPool / (100 + immigrantsPool) * 100, deathsPool, 100 + immigrantsPool); System.out.printf("You completed the game with %.4f acres per population\n", (double) landsOwned / population); } diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java index 1eb8de2..ed046e5 100644 --- a/src/main/java/GameEngine.java +++ b/src/main/java/GameEngine.java @@ -7,7 +7,7 @@ public class GameEngine { Random random = new Random(); // ***************************************************************************************************************** - // ***************** CONSTRUCTOR/GAME INITIALIZATION/ROUND INITILIZATION/EXIT + // ***************** GAME INITIALIZATION/ROUND INITILIZATION/EXIT public GameEngine() { } From 033e5a5b5c6fca78de240a7f8bc5cb17faa42172 Mon Sep 17 00:00:00 2001 From: Freddy Mintarja <115741236+fmintar1@users.noreply.github.com> Date: Mon, 14 Nov 2022 09:30:32 -0500 Subject: [PATCH 15/16] Fixed the different ending bugs & eliminate exit game method --- src/main/java/Console.java | 220 +++++++++++++++---------------- src/main/java/UserInterface.java | 28 ++-- 2 files changed, 124 insertions(+), 124 deletions(-) diff --git a/src/main/java/Console.java b/src/main/java/Console.java index d66bf49..58e79f7 100644 --- a/src/main/java/Console.java +++ b/src/main/java/Console.java @@ -8,26 +8,26 @@ public class Console { // INPUT //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public int acresToBuySOUT(int price){ -// int acresToBuy = getNumber("How many acres would you like to buy? The price is currently " + price + " bushels per acre."); - int acresToBuy = getNumber("How many galaxies would you like to buy? The price is currently " + price + " stars per galaxy."); + int acresToBuy = getNumber("How many acres would you like to buy? The price is currently " + price + " bushels per acre."); +// int acresToBuy = getNumber("How many galaxies would you like to buy? The price is currently " + price + " stars per galaxy."); return acresToBuy; } public int acresToSellSOUT(int price){ -// int acresToSell = getNumber("How many acres would you like to sell? The Price is currently " + price + " bushels per acre."); - int acresToSell = getNumber("How many galaxies would you like to sell? The price is currently " + price + " stars per galaxy."); + int acresToSell = getNumber("How many acres would you like to sell? The Price is currently " + price + " bushels per acre."); +// int acresToSell = getNumber("How many galaxies would you like to sell? The price is currently " + price + " stars per galaxy."); return acresToSell; } public int bushelsToFeed(){ -// int bushelsFed = getNumber("How many bushels would you like to feed your nation?"); - int bushelsFed = getNumber("How many stars would you like to feed your aliens with?"); + int bushelsFed = getNumber("How many bushels would you like to feed your nation?"); +// int bushelsFed = getNumber("How many stars would you like to feed your aliens with?"); return bushelsFed; } public int acresToPlant(){ - int acresPlanted = getNumber("How many galaxies to duplicate stars?"); -// int acresPlanted = getNumber("How many acres to plant?"); +// int acresPlanted = getNumber("How many galaxies to duplicate stars?"); + int acresPlanted = getNumber("How many acres to plant?"); return acresPlanted; } @@ -53,161 +53,161 @@ public boolean exitGame() { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void announceGame(int population, int bushels, int landsOwned, int price) { -// System.out.println("\n"); -// System.out.println("Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office."); -// System.out.println("Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people."); -// System.out.println("Grain is the general currency, measured in bushels."); -// System.out.println("\n"); -// System.out.println("The following will help you in your decisions:"); -// System.out.println("\n"); -// System.out.println("**Each person needs at least 20 bushels of grain per year to survive**"); -// System.out.println("**Each person can farm at most 10 acres of land**"); -// System.out.println("**It takes 1 bushel of grain to farm an acre of land**"); -// System.out.println("**The market price for land fluctuates yearly**"); -// System.out.println("**It's recommended to calculate before answering, there is no turning back**"); -// System.out.println("\n"); -// System.out.println("**WARNING!!!**"); -// System.out.println("**THE GAME IS OVER WHEN DEATH BY STARVATION IS MORE THAN 45% OF CURRENT POPULATION!!!**"); -// System.out.println("**THE GAME IS OVER WHEN ACRES ARE LESS THAN 7 PER POPULATION!!!**"); -// System.out.println("\n"); -// System.out.println("Now, let's begin!"); -// System.out.println("\n"); -// System.out.println("O great One! Your kingdom await your orders!"); -// System.out.println("There are " + population + " people that you must feed!"); -// System.out.println("Our coffers have " + bushels + " bushels in storage."); -// System.out.println("The city owns " + landsOwned + " acres of land."); -// System.out.println("Land is available to purchase for " + price + " bushels per acre"); -// System.out.println("Rats destroyed 200 bushels"); -// System.out.println("\n"); System.out.println("\n"); - System.out.println("Greetings, commander. You have been selected by the Universe of ZCW8.2 to lead for ten million years."); - System.out.println("For the sake of the aliens, you need to feed them with stars, and using galaxies to duplicate the stars"); - System.out.println("You may also buy and sell galaxies by the transaction of stars"); + System.out.println("Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office."); + System.out.println("Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people."); + System.out.println("Grain is the general currency, measured in bushels."); System.out.println("\n"); System.out.println("The following will help you in your decisions:"); System.out.println("\n"); - System.out.println("**Each alien needs at least 20 stars per 1 million years to survive**"); - System.out.println("**Each alien can utilize at most 10 galaxies to grow stars**"); - System.out.println("**To duplicate stars, each galaxy needs 1 star**"); - System.out.println("**The stars cost for galaxy fluctuates every 1 million years**"); + System.out.println("**Each person needs at least 20 bushels of grain per year to survive**"); + System.out.println("**Each person can farm at most 10 acres of land**"); + System.out.println("**It takes 1 bushel of grain to farm an acre of land**"); + System.out.println("**The market price for land fluctuates yearly**"); System.out.println("**It's recommended to calculate before answering, there is no turning back**"); System.out.println("\n"); System.out.println("**WARNING!!!**"); - System.out.println("**THE GAME IS OVER WHEN DEATH BY STARVATION IS MORE THAN 45% OF CURRENT ALIENS!!!**"); - System.out.println("**THE GAME IS OVER WHEN GALAXIES ARE LESS THAN 7 PER ALIEN!!!**"); + System.out.println("**THE GAME IS OVER WHEN DEATH BY STARVATION IS MORE THAN 45% OF CURRENT POPULATION!!!**"); + System.out.println("**THE GAME IS OVER WHEN ACRES ARE LESS THAN 7 PER POPULATION!!!**"); System.out.println("\n"); System.out.println("Now, let's begin!"); System.out.println("\n"); - System.out.println("Commander, ZCW8.2 is currently waiting for your order."); - System.out.println("There are " + population + " aliens that you must feed"); - System.out.println("Our wormhole currently has " + bushels + " stars in dimension"); - System.out.println("ZCW8.2 has " + landsOwned + " galaxies in our possession"); - System.out.println("Galaxies are available for trading for " + price + " stars"); - System.out.println("Space pirates destroyed 200 stars"); + System.out.println("O great One! Your kingdom await your orders!"); + System.out.println("There are " + population + " people that you must feed!"); + System.out.println("Our coffers have " + bushels + " bushels in storage."); + System.out.println("The city owns " + landsOwned + " acres of land."); + System.out.println("Land is available to purchase for " + price + " bushels per acre"); + System.out.println("Rats destroyed 200 bushels"); System.out.println("\n"); +// System.out.println("\n"); +// System.out.println("Greetings, commander. You have been selected by the Universe of ZCW8.2 to lead for ten million years."); +// System.out.println("For the sake of the aliens, you need to feed them with stars, and using galaxies to duplicate the stars"); +// System.out.println("You may also buy and sell galaxies by the transaction of stars"); +// System.out.println("\n"); +// System.out.println("The following will help you in your decisions:"); +// System.out.println("\n"); +// System.out.println("**Each alien needs at least 20 stars per 1 million years to survive**"); +// System.out.println("**Each alien can utilize at most 10 galaxies to grow stars**"); +// System.out.println("**To duplicate stars, each galaxy needs 1 star**"); +// System.out.println("**The stars cost for galaxy fluctuates every 1 million years**"); +// System.out.println("**It's recommended to calculate before answering, there is no turning back**"); +// System.out.println("\n"); +// System.out.println("**WARNING!!!**"); +// System.out.println("**THE GAME IS OVER WHEN DEATH BY STARVATION IS MORE THAN 45% OF CURRENT ALIENS!!!**"); +// System.out.println("**THE GAME IS OVER WHEN GALAXIES ARE LESS THAN 7 PER ALIEN!!!**"); +// System.out.println("\n"); +// System.out.println("Now, let's begin!"); +// System.out.println("\n"); +// System.out.println("Commander, ZCW8.2 is currently waiting for your order."); +// System.out.println("There are " + population + " aliens that you must feed"); +// System.out.println("Our wormhole currently has " + bushels + " stars in dimension"); +// System.out.println("ZCW8.2 has " + landsOwned + " galaxies in our possession"); +// System.out.println("Galaxies are available for trading for " + price + " stars"); +// System.out.println("Space pirates destroyed 200 stars"); +// System.out.println("\n"); } public void printSummary(int year, int immigrants, int sDeaths, int pDeaths, int population, int rats, int bushels, int landsOwned, int price) { - System.out.println("\n"); - System.out.println("\n"); - System.out.println("Greetings, Commander"); - System.out.println("You are now in year " + year + " million of your ten million year rule"); - System.out.println("\n"); - System.out.println("In the previous 1 million years, " + immigrants + " aliens came to ZCW8.2"); - System.out.println("In the previous 1 million years, " + sDeaths + " aliens starved to death"); - System.out.println("In the previous 1 million years, " + pDeaths + " aliens died from EMPs"); - System.out.println("The population is now " + population); -// System.out.println("We harvested " + state.getHarvest() + " bushels"); <-Bugged due to RNG, DO WE WANT TO FIX THIS? --EMORY - System.out.println("Space pirates destroyed " + rats + " stars"); - System.out.println("There are " + bushels + " stars left in the wormhole"); - System.out.println("ZCW8.2 has " + landsOwned + " galaxies in our possession"); - System.out.println("Galaxies are available for trading for " + price + " stars"); - System.out.println("\n"); - } -// System.out.println("\n"); // System.out.println("\n"); -// System.out.println("O great Hammurabi"); -// System.out.println("You are now in year " + year + " of your ten year rule."); // System.out.println("\n"); -// System.out.println("In the previous year " + immigrants + " people came to the kingdom."); -// System.out.println("In the previous year " + sDeaths + " people starved to death."); -// System.out.println("In the previous year " + pDeaths + " people died from plague"); +// System.out.println("Greetings, Commander"); +// System.out.println("You are now in year " + year + " million of your ten million year rule"); +// System.out.println("\n"); +// System.out.println("In the previous 1 million years, " + immigrants + " aliens came to ZCW8.2"); +// System.out.println("In the previous 1 million years, " + sDeaths + " aliens starved to death"); +// System.out.println("In the previous 1 million years, " + pDeaths + " aliens died from EMPs"); // System.out.println("The population is now " + population); //// System.out.println("We harvested " + state.getHarvest() + " bushels"); <-Bugged due to RNG, DO WE WANT TO FIX THIS? --EMORY -// System.out.println("Rats destroyed " + rats + " bushels"); -// System.out.println("There are only " + bushels + " bushels left in storage."); -// System.out.println("The city owns " + landsOwned + " acres of land."); -// System.out.println("Land is currently worth " + price + " bushels per acre"); +// System.out.println("Space pirates destroyed " + rats + " stars"); +// System.out.println("There are " + bushels + " stars left in the wormhole"); +// System.out.println("ZCW8.2 has " + landsOwned + " galaxies in our possession"); +// System.out.println("Galaxies are available for trading for " + price + " stars"); // System.out.println("\n"); -//} +// } + System.out.println("\n"); + System.out.println("\n"); + System.out.println("O great Hammurabi"); + System.out.println("You are now in year " + year + " of your ten year rule."); + System.out.println("\n"); + System.out.println("In the previous year " + immigrants + " people came to the kingdom."); + System.out.println("In the previous year " + sDeaths + " people starved to death."); + System.out.println("In the previous year " + pDeaths + " people died from plague"); + System.out.println("The population is now " + population); +// System.out.println("We harvested " + state.getHarvest() + " bushels"); <-Bugged due to RNG, DO WE WANT TO FIX THIS? --EMORY + System.out.println("Rats destroyed " + rats + " bushels"); + System.out.println("There are only " + bushels + " bushels left in storage."); + System.out.println("The city owns " + landsOwned + " acres of land."); + System.out.println("Land is currently worth " + price + " bushels per acre"); + System.out.println("\n"); +} public void prompt(int bushels, int population, int landsOwned) { //<-Newly added -// System.out.println("\n"); -// System.out.println("Bushels left: " + bushels -// + "\npopulation number: " + population -// + "\nAcres: " + landsOwned); -// System.out.println("\n"); -// } System.out.println("\n"); - System.out.println("Stars remaining: " + bushels - + "\nAliens number: " + population - + "\nGalaxies: " + landsOwned); + System.out.println("Bushels left: " + bushels + + "\npopulation number: " + population + + "\nAcres: " + landsOwned); System.out.println("\n"); } +// System.out.println("\n"); +// System.out.println("Stars remaining: " + bushels +// + "\nAliens number: " + population +// + "\nGalaxies: " + landsOwned); +// System.out.println("\n"); +// } public void gameEndingPrompt(int deathsPool, int immigrantsPool, int population, int landsOwned) { //<-Newly added -// System.out.printf("You completed the game with %.4f%% starvation deaths out of %s\n", -// (double) deathsPool / (1000 + immigrantsPool) * 100, population); -// System.out.printf("You completed the game with %.4f acres per population\n", -// (double) landsOwned / population); -// } System.out.printf("You completed the game with %.4f%% starvation deaths out of %s\n", (double) deathsPool / (1000 + immigrantsPool) * 100, population); - System.out.printf("You completed the game with %.4f galaxies per alien\n", + System.out.printf("You completed the game with %.4f acres per population\n", (double) landsOwned / population); } +// System.out.printf("You completed the game with %.4f%% starvation deaths, %s deaths by starvation vs %s total population\n", +// (double) deathsPool / (100 + immigrantsPool) * 100, deathsPool, 100 + immigrantsPool); +// System.out.printf("You completed the game with %.4f galaxies per alien\n", +// (double) landsOwned / population); +// } public void monster() { -// System.out.println("\n"); -// System.out.println("You MONSTER!! You killed so many people!! WE WILL AVENGE THEM!!!!!!"); -// System.out.println("\n"); -// } System.out.println("\n"); - System.out.println("Due to your terrible decisions making, you are hereby dethroned from your Commander position and are being hunted by the aliens."); + System.out.println("You MONSTER!! You killed so many people!! WE WILL AVENGE THEM!!!!!!"); System.out.println("\n"); } - - public void boring() { -// System.out.println("You brought great... okayness... to our kingdom... thanks for not killing all of us?"); // System.out.println("\n"); -// System.out.println("You have brought normalization to your kingdom. You are one boring ruler!"); +// System.out.println("Due to your terrible decisions making, you are hereby dethroned from your Commander position and are being hunted by the aliens."); // System.out.println("\n"); // } + + public void boring() { + System.out.println("You brought great... okayness... to our kingdom... thanks for not killing all of us?"); System.out.println("\n"); - System.out.println("You have made it to the end of the 10 million years without much damage or extra miles. The aliens thanked you."); + System.out.println("You have brought normalization to your kingdom. You are one boring ruler!"); System.out.println("\n"); } - - public void thriving() { // System.out.println("\n"); -// System.out.println("Your kingdom is thriving! You are one superb ruler!"); +// System.out.println("You have made it to the end of the 10 million years without much damage or extra miles. The aliens thanked you."); // System.out.println("\n"); // } + + public void thriving() { System.out.println("\n"); - System.out.println("On behalf of ZCW8.2, we thank you for your effort to drive the Universe forward. GLaDOS have a cake for you."); + System.out.println("Your kingdom is thriving! You are one superb ruler!"); System.out.println("\n"); } - - public void guts(){ // System.out.println("\n"); -// System.out.println("While you brought your kingdom to make it through the years, you are " + -// "still a terrible ruler. Your people hated your guts!"); +// System.out.println("On behalf of ZCW8.2, we thank you for your effort to drive the Universe forward. GLaDOS have a cake for you."); // System.out.println("\n"); // } + + public void guts(){ System.out.println("\n"); - System.out.println("You have made it to the end of 10 million years. However, the aliens are currently building a time machine to undo your mistakes."); + System.out.println("While you brought your kingdom to make it through the years, you are " + + "still a terrible ruler. Your people hated your guts!"); System.out.println("\n"); } +// System.out.println("\n"); +// System.out.println("You have made it to the end of 10 million years. However, the aliens are currently building a time machine to undo your mistakes."); +// System.out.println("\n"); +// } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // SCANNERS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/main/java/UserInterface.java b/src/main/java/UserInterface.java index 1ba9edf..da616d3 100644 --- a/src/main/java/UserInterface.java +++ b/src/main/java/UserInterface.java @@ -48,12 +48,13 @@ public void main() { } if (state.getYear() == 11) { //<-newly added, it works + console.gameEndingPrompt(state.getsDeathsPool(), state.getImmigrantsPool(), state.getPopulation(), state.getLandsOwned()); badEnding(); normalEnding(); goodEnding(); + break; } - - if (console.exitGame() == false) break; +// if (console.exitGame() == false) break; } } @@ -136,7 +137,7 @@ public void askHowManyBushelsToFeedPeople(int bushelsFed) { if (game.starvationDeaths(state.getPopulation(), game.calculateGrainToFeedPeople(state.getBushels(), bushelsFed)) > state.getPopulation() * 45 / 100) { console.monster(); //<-updated gameover - console.exitGame(); +// console.exitGame(); } } @@ -152,30 +153,29 @@ public void askHowManyAcresToPlant(int acresPlanted) { } public void badEnding() { //<- Newly added - if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 >= 10 || - state.getLandsOwned() / state.getPopulation() <= 9) { + if ((double)state.getsDeathsPool() / (100 + state.getImmigrantsPool()) * 100 >= 10 && (double)state.getLandsOwned() / state.getPopulation() <= 9 || + (double)state.getsDeathsPool() / (100 + state.getImmigrantsPool()) * 100 >= 10 && (double)state.getLandsOwned() / state.getPopulation() > 9 || + (double)state.getsDeathsPool() / (100 + state.getImmigrantsPool()) * 100 < 10 && (double)state.getLandsOwned() / state.getPopulation() <= 9) { - console.gameEndingPrompt(state.getsDeathsPool(), state.getImmigrantsPool(), state.getPopulation(), state.getLandsOwned()); console.guts(); } } public void normalEnding() { //<-Newly added - if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 < 10 && - state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 > 3 || - state.getLandsOwned() / state.getPopulation() > 9 && - state.getLandsOwned() / state.getPopulation() <= 10) { + if ((double)state.getsDeathsPool() / (100 + state.getImmigrantsPool()) * 100 < 10 && (double)state.getsDeathsPool() / (100 + state.getImmigrantsPool()) * 100 >= 3 && + (double)state.getLandsOwned() / state.getPopulation() > 9 && (double)state.getLandsOwned() / state.getPopulation() <= 10 || + (double)state.getsDeathsPool() / (100 + state.getImmigrantsPool()) * 100 < 10 && (double)state.getsDeathsPool() / (100 + state.getImmigrantsPool()) * 100 >= 3 && + (double)state.getLandsOwned() / state.getPopulation() > 9 || + (double)state.getsDeathsPool() / (100 + state.getImmigrantsPool()) * 100 < 3 && + (double)state.getLandsOwned() / state.getPopulation() > 9 && (double)state.getLandsOwned() / state.getPopulation() <= 10) { - console.gameEndingPrompt(state.getsDeathsPool(), state.getImmigrantsPool(), state.getPopulation(), state.getLandsOwned()); console.boring(); } } public void goodEnding() { //<-Newly added - if (state.getsDeathsPool() / (1000 + state.getImmigrantsPool()) * 100 < 3 || - state.getLandsOwned() / state.getPopulation() > 10) { + if ((double)state.getsDeathsPool() / (100 + state.getImmigrantsPool()) * 100 < 3 && (double)state.getLandsOwned() / state.getPopulation() > 10) { - console.gameEndingPrompt(state.getsDeathsPool(), state.getImmigrantsPool(), state.getPopulation(), state.getLandsOwned()); console.thriving(); } From fa30e802c2c8bcd52ff7ff18d38eb5f74186ec4e Mon Sep 17 00:00:00 2001 From: Freddy Mintarja <115741236+fmintar1@users.noreply.github.com> Date: Mon, 14 Nov 2022 09:31:48 -0500 Subject: [PATCH 16/16] final edition --- src/main/java/GameEngine.java | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java index ba5a529..aa2bcb3 100644 --- a/src/main/java/GameEngine.java +++ b/src/main/java/GameEngine.java @@ -13,36 +13,36 @@ public GameEngine() { } public int calculateAcresToBuy(int acresToBuy, int price, int bushels){ -// if ( (acresToBuy * price) > bushels){ -// System.out.println("You FOOL! You're trying to buy more than what you can afford, you get nothing and like it!"); -// return 0; -// } else { -// return acresToBuy; -// } -// } if ( (acresToBuy * price) > bushels){ - System.out.println("Commander, since you are being greedy, ZCW8.2 malfunctions and hereby unable to purchase any galaxies for 1 million years"); + System.out.println("You FOOL! You're trying to buy more than what you can afford, you get nothing and like it!"); return 0; } else { return acresToBuy; } } - - public int calculateAcresToSell(int acresToSell, int landOwned) { -// if (acresToSell > landOwned) { -// System.out.println("Selling too much than what you own!"); +// if ( (acresToBuy * price) > bushels){ +// System.out.println("Commander, since you are being greedy, ZCW8.2 malfunctions and hereby unable to purchase any galaxies for 1 million years"); // return 0; // } else { -// return acresToSell; +// return acresToBuy; // } // } + + public int calculateAcresToSell(int acresToSell, int landOwned) { if (acresToSell > landOwned) { - System.out.println("Commander, since you are being greedy, ZCW8.2 malfunctions and hereby unable to sell any galaxies for 1 million years"); + System.out.println("Selling too much than what you own!"); return 0; } else { return acresToSell; } } +// if (acresToSell > landOwned) { +// System.out.println("Commander, since you are being greedy, ZCW8.2 malfunctions and hereby unable to sell any galaxies for 1 million years"); +// return 0; +// } else { +// return acresToSell; +// } +// } public int calculateGrainToFeedPeople(int bushels, int bushelsFed) { if (bushelsFed > bushels){