From 0495018430c8418f19ac5016dcd9f30ef755a793 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Thu, 2 Mar 2023 13:19:34 -0500 Subject: [PATCH] reformat --- .../src/ca/cosc3p91/a2/gameobjects/Farm.java | 6 ++--- .../ca/cosc3p91/a2/gameobjects/IronMine.java | 2 +- .../cosc3p91/a2/gameobjects/LumberMine.java | 2 +- .../a2/gameobjects/ResourceBuilding.java | 23 ++++++++++++++++++- .../cosc3p91/a2/gameobjects/SaulGoodMine.java | 4 +++- .../src/ca/cosc3p91/a2/util/Time.java | 12 ++-------- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java index 03657fd..b1bded8 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java @@ -8,11 +8,9 @@ public class Farm extends ResourceBuilding { } public int getPopulationContribution() { - return 0; + return getHarvestRate(); } @Override - public void harvest(Village_Hall hall) { - - } + public void harvest(Village_Hall hall) {} } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java index f5ffcb7..a77a0d8 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java @@ -11,6 +11,6 @@ public class IronMine extends ResourceBuilding { @Override public void harvest(Village_Hall hall) { - + hall.addCurrentIron(getHarvestRate()); } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java index 5f56f77..5f87ba3 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java @@ -10,7 +10,7 @@ public class LumberMine extends ResourceBuilding { } public void harvest(Village_Hall hall) { - + hall.addCurrentWood(getHarvestRate()); } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java index e68f02e..04f38dd 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java @@ -1,15 +1,36 @@ package ca.cosc3p91.a2.gameobjects; +import ca.cosc3p91.a2.util.Time; + public abstract class ResourceBuilding extends Building { public static String resource; + + private final Time harvestMinTime = new Time().offsetSeconds(10); + private int harvest_rate; + private Time nextHarvestTime; + + public ResourceBuilding() { + nextHarvestTime = Time.getTime().offsetTime(harvestMinTime); + } public void upgrade(ResourceStage stage) { super.upgrade(stage); this.harvest_rate += stage.getHarvestRateIncrease(); } - public abstract void harvest(Village_Hall hall); + public void update(Village_Hall hall){ + if (nextHarvestTime.occurred()){ + harvest(hall); + nextHarvestTime = Time.getTime().offsetTime(harvestMinTime); + } + } + + protected abstract void harvest(Village_Hall hall); + + public int getHarvestRate(){ + return harvest_rate; + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java index d6663a5..a4135f3 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java @@ -1,5 +1,7 @@ package ca.cosc3p91.a2.gameobjects; +import ca.cosc3p91.a2.util.Time; + public class SaulGoodMine extends ResourceBuilding { public static String resource = "gold"; @@ -11,6 +13,6 @@ public class SaulGoodMine extends ResourceBuilding { @Override public void harvest(Village_Hall hall) { - + hall.addCurrentGold(getHarvestRate()); } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/util/Time.java b/Assignment 2/src/ca/cosc3p91/a2/util/Time.java index 60d5f93..439d17f 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/util/Time.java +++ b/Assignment 2/src/ca/cosc3p91/a2/util/Time.java @@ -37,16 +37,8 @@ public class Time { return timeSeconds; } - public static class FutureTime { - private final Time futureTime; - - public FutureTime(Time futureTime) { - this.futureTime = futureTime; - } - - public boolean occurred() { - return getTime().timeSeconds >= futureTime.timeSeconds; - } + public boolean occurred() { + return getTime().timeSeconds >= timeSeconds; } public static Time getTime() {