From debb59bc3900a3fe9c8c5d51290c8abfc1933094 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Fri, 3 Mar 2023 14:24:33 -0500 Subject: [PATCH] Updating + stages --- .idea/runConfigurations.xml | 10 --- Assignment 2/src/ca/cosc3p91/a2/Main.java | 4 +- .../src/ca/cosc3p91/a2/game/GameEngine.java | 47 +++++++++++--- Assignment 2/src/ca/cosc3p91/a2/game/Map.java | 10 +-- .../{VillageHall.java => CasaDeNarino.java} | 4 +- .../src/ca/cosc3p91/a2/gameobjects/Farm.java | 4 +- .../ca/cosc3p91/a2/gameobjects/IronMine.java | 4 +- .../cosc3p91/a2/gameobjects/LumberMine.java | 5 +- .../a2/gameobjects/ResourceBuilding.java | 10 ++- .../a2/gameobjects/ResourceStage.java | 4 +- .../a2/gameobjects/ResourceStages.java | 61 +++++++++++++++++++ .../cosc3p91/a2/gameobjects/SaulGoodMine.java | 4 +- .../src/ca/cosc3p91/a2/gameobjects/Stage.java | 8 ++- .../cosc3p91/a2/gameobjects/VillageStage.java | 4 +- 14 files changed, 137 insertions(+), 42 deletions(-) delete mode 100644 .idea/runConfigurations.xml rename Assignment 2/src/ca/cosc3p91/a2/gameobjects/{VillageHall.java => CasaDeNarino.java} (92%) create mode 100644 Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStages.java diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Assignment 2/src/ca/cosc3p91/a2/Main.java b/Assignment 2/src/ca/cosc3p91/a2/Main.java index 18130b1..6b832ae 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/Main.java +++ b/Assignment 2/src/ca/cosc3p91/a2/Main.java @@ -5,9 +5,7 @@ import ca.cosc3p91.a2.game.GameEngine; public class Main { public static void main(String[] args) { - GameEngine engine = new GameEngine(); - - engine.run(); + new GameEngine().run(); } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java b/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java index 14a37a2..40c7ee8 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java @@ -3,7 +3,11 @@ package ca.cosc3p91.a2.game; import ca.cosc3p91.a2.gameobjects.*; import ca.cosc3p91.a2.player.*; import ca.cosc3p91.a2.util.Print; +import ca.cosc3p91.a2.util.Time; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.Scanner; public class GameEngine implements Runnable { @@ -19,9 +23,7 @@ public class GameEngine implements Runnable { public GameEngine() { player = new Player(); - VillageStage vInitialStage = new VillageStage(100, 0, 2, 30, 0, - 0, 1000, 2500, 5000); - map = new Map(new VillageHall(1, vInitialStage), 30); + map = generateMap(); } private void printState() { @@ -71,21 +73,52 @@ public class GameEngine implements Runnable { } public void attackVillage(Map map) { + + } + + private Map generateInitialMap(){ + VillageStage villageHallInitialStage = new VillageStage(100, 0, 2, new Time(), 0, + 0, 1000, 2500, 5000); + return new Map(new CasaDeNarino(1, villageHallInitialStage), 30); } public Map generateMap() { - return null; + Map initialMap = generateInitialMap(); + initialMap.build(new Tile(), new SaulGoodMine(1, new ResourceStage(50, 0, 0, new Time(), 0, 0, 25))); + return initialMap; } public void getScore(Map map) { + } @Override public void run() { - Scanner sc = new Scanner(System.in); + BufferedReader rd = new BufferedReader(new InputStreamReader(System.in)); + Scanner sc = new Scanner(rd); + printState(); + System.out.println(); while (running) { - printState(); - int in = sc.nextInt(); + for (Building b : map.contains){ + if ((b instanceof ResourceBuilding)) { + ((ResourceBuilding) b).update(map.getTownHall()); + } + } + //System.out.println("Updating"); + try { + if (rd.ready()) { + char in = sc.next().charAt(0); + switch (in) { + case 'p': + printState(); + break; + default: + break; + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } } } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/game/Map.java b/Assignment 2/src/ca/cosc3p91/a2/game/Map.java index 9d64419..028469d 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/game/Map.java +++ b/Assignment 2/src/ca/cosc3p91/a2/game/Map.java @@ -9,7 +9,7 @@ public class Map { static int MAXSIZE = 400; - private VillageHall townHall; + private CasaDeNarino townHall; private int guardTime; @@ -17,11 +17,11 @@ public class Map { public List inhabitants; - public Map(VillageHall villageHall, int gTime) { + public Map(CasaDeNarino casaDeNarino, int gTime) { contains = new ArrayList<>(); inhabitants = new ArrayList<>(); - this.townHall = villageHall; - this.contains.add(villageHall); + this.townHall = casaDeNarino; + this.contains.add(casaDeNarino); this.guardTime = gTime; } @@ -45,7 +45,7 @@ public class Map { this.guardTime = gTime; } - public VillageHall getTownHall(){ + public CasaDeNarino getTownHall(){ return townHall; } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageHall.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/CasaDeNarino.java similarity index 92% rename from Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageHall.java rename to Assignment 2/src/ca/cosc3p91/a2/gameobjects/CasaDeNarino.java index edd8d81..5ee3f13 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageHall.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/CasaDeNarino.java @@ -2,7 +2,7 @@ package ca.cosc3p91.a2.gameobjects; import java.util.ArrayList; -public class VillageHall extends Building { +public class CasaDeNarino extends Building { private int goldCapacity = 0; private int ironCapacity = 0; @@ -12,7 +12,7 @@ public class VillageHall extends Building { private int currentIron; private int currentWood; - public VillageHall(int lvl, VillageStage baseStage) { + public CasaDeNarino(int lvl, VillageStage baseStage) { setLevel(lvl); upgrade(baseStage); } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java index eb1437d..3f1892b 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java @@ -12,5 +12,7 @@ public class Farm extends ResourceBuilding { } @Override - public void harvest(VillageHall hall) {} + protected ResourceHarvestHandler getHarvestHandler() { + return hall -> {}; + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java index 390791d..e1d675d 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java @@ -10,7 +10,7 @@ public class IronMine extends ResourceBuilding { } @Override - public void harvest(VillageHall hall) { - hall.addCurrentIron(getHarvestRate()); + protected ResourceHarvestHandler getHarvestHandler() { + return 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 7c2c4cc..420d219 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java @@ -9,8 +9,9 @@ public class LumberMine extends ResourceBuilding { upgrade(baseStage); } - public void harvest(VillageHall hall) { - hall.addCurrentWood(getHarvestRate()); + @Override + protected ResourceHarvestHandler getHarvestHandler() { + return 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 5763b16..400446e 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java @@ -4,6 +4,10 @@ import ca.cosc3p91.a2.util.Time; public abstract class ResourceBuilding extends Building { + protected interface ResourceHarvestHandler { + void harvest(CasaDeNarino hall); + } + public static String resource; private final Time harvestMinTime = new Time().offsetSeconds(10); @@ -20,14 +24,14 @@ public abstract class ResourceBuilding extends Building { this.harvest_rate += stage.getHarvestRateIncrease(); } - public void update(VillageHall hall){ + public void update(CasaDeNarino hall){ if (nextHarvestTime.occurred()){ - harvest(hall); + getHarvestHandler().harvest(hall); nextHarvestTime = Time.getTime().offsetTime(harvestMinTime); } } - protected abstract void harvest(VillageHall hall); + protected abstract ResourceHarvestHandler getHarvestHandler(); public int getHarvestRate(){ return harvest_rate; diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java index e953c1d..7585e2d 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java @@ -1,10 +1,12 @@ package ca.cosc3p91.a2.gameobjects; +import ca.cosc3p91.a2.util.Time; + public class ResourceStage extends Stage { protected int harvestRateIncrease; - public ResourceStage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost, + public ResourceStage(int dHealth, int goldCost, int requiredVillageLevel, Time upgradeTime, int ironCost, int woodCost, int harvestRateIncr) { super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost); this.harvestRateIncrease = harvestRateIncr; diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStages.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStages.java new file mode 100644 index 0000000..1d29221 --- /dev/null +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStages.java @@ -0,0 +1,61 @@ +package ca.cosc3p91.a2.gameobjects; + +import ca.cosc3p91.a2.util.Time; + +public class ResourceStages { + + public static class GoldStage1 extends ResourceStage { + public GoldStage1() { + super(100, 0, 0, new Time().offsetMinutes(1), 25, 250, 25); + } + } + + public static class GoldStage2 extends ResourceStage { + public GoldStage2() { + super(100, 100, 1, new Time().offsetMinutes(15), 25, 275, 35); + } + } + + public static class GoldStage3 extends ResourceStage { + public GoldStage3() { + super(100, 150, 2, new Time().offsetHours(1), 50, 325, 50); + } + } + + public static class IronStage1 extends ResourceStage { + public IronStage1() { + super(100, 0, 0, new Time().offsetMinutes(1), 0, 125, 25); + } + } + + public static class IronStage2 extends ResourceStage { + public IronStage2() { + super(100, 15, 1, new Time().offsetMinutes(15), 25, 155, 35); + } + } + + public static class IronStage3 extends ResourceStage { + public IronStage3() { + super(100, 50, 2, new Time().offsetHours(1), 50, 250, 50); + } + } + + public static class WoodStage1 extends ResourceStage { + public WoodStage1() { + super(100, 0, 0, new Time().offsetMinutes(1), 0, 50, 25); + } + } + + public static class WoodStage2 extends ResourceStage { + public WoodStage2() { + super(100, 5, 1, new Time().offsetMinutes(15), 5, 75, 35); + } + } + + public static class WoodStage3 extends ResourceStage { + public WoodStage3() { + super(100, 10, 2, new Time().offsetHours(1), 25, 100, 50); + } + } + +} diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java index 600b143..ff56bfa 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java @@ -10,7 +10,7 @@ public class SaulGoodMine extends ResourceBuilding { } @Override - public void harvest(VillageHall hall) { - hall.addCurrentGold(getHarvestRate()); + protected ResourceHarvestHandler getHarvestHandler() { + return hall -> hall.addCurrentGold(getHarvestRate()); } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java index 2e148cb..3e5973b 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java @@ -1,5 +1,7 @@ package ca.cosc3p91.a2.gameobjects; +import ca.cosc3p91.a2.util.Time; + abstract class Stage { protected int dHealth; @@ -8,13 +10,13 @@ abstract class Stage { protected int requiredVillageLevel; - protected int upgradeTime; + protected Time upgradeTime; protected int ironCost; protected int woodCost; - public Stage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost) { + public Stage(int dHealth, int goldCost, int requiredVillageLevel, Time upgradeTime, int ironCost, int woodCost) { this.dHealth = dHealth; this.goldCost = goldCost; this.requiredVillageLevel = requiredVillageLevel; @@ -36,7 +38,7 @@ abstract class Stage { return requiredVillageLevel; } - public int getUpgradeTime() { + public Time getUpgradeTime() { return upgradeTime; } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java index afd0a5f..8600fc2 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java @@ -1,5 +1,7 @@ package ca.cosc3p91.a2.gameobjects; +import ca.cosc3p91.a2.util.Time; + public class VillageStage extends Stage { protected int goldCapacityIncrease; @@ -8,7 +10,7 @@ public class VillageStage extends Stage { protected int woodCapacityIncrease; - public VillageStage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost, + public VillageStage(int dHealth, int goldCost, int requiredVillageLevel, Time upgradeTime, int ironCost, int woodCost, int goldCapIncrease, int ironCapIncrease, int woodCapIncrease) { super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost); this.goldCapacityIncrease = goldCapIncrease;