Skip to content

Commit

Permalink
Added some stuff, rearranged some things
Browse files Browse the repository at this point in the history
  • Loading branch information
Emory authored and Emory committed Nov 13, 2022
1 parent 0fa8c9a commit c5f6b08
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
42 changes: 31 additions & 11 deletions src/main/java/GameEngine.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import java.util.*;

import static java.lang.Math.floor;

public class GameEngine {

Random random = new Random();
Expand All @@ -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) {
Expand All @@ -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;
}
}
59 changes: 58 additions & 1 deletion src/main/java/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
101 changes: 95 additions & 6 deletions src/main/java/UserInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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();
}
}
}
Expand All @@ -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() {
Expand All @@ -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;
Expand Down

0 comments on commit c5f6b08

Please sign in to comment.