diff --git a/Assignment 2/src/ca/cosc3p91/a2/Main.java b/Assignment 2/src/ca/cosc3p91/a2/Main.java index 0e78c10..9553242 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/Main.java +++ b/Assignment 2/src/ca/cosc3p91/a2/Main.java @@ -1,7 +1,7 @@ -package ca.cosc3p91.a3; +package ca.cosc3p91.a4; -import ca.cosc3p91.a3.game.GameEngine; -import ca.cosc3p91.a3.gameobjects.Stage; +import ca.cosc3p91.a4.game.GameEngine; +import ca.cosc3p91.a4.gameobjects.Stage; public class Main { diff --git a/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java b/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java index b1430cd..0d8bed4 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java @@ -1,10 +1,10 @@ -package ca.cosc3p91.a3.game; +package ca.cosc3p91.a4.game; -import ca.cosc3p91.a3.gameobjects.*; -import ca.cosc3p91.a3.player.*; -import ca.cosc3p91.a3.util.Print; -import ca.cosc3p91.a3.util.Time; -import ca.cosc3p91.a3.util.Util; +import ca.cosc3p91.a4.gameobjects.*; +import ca.cosc3p91.a4.player.*; +import ca.cosc3p91.a4.util.Print; +import ca.cosc3p91.a4.util.Time; +import ca.cosc3p91.a4.util.Util; import java.io.BufferedReader; import java.io.IOException; diff --git a/Assignment 2/src/ca/cosc3p91/a2/game/Map.java b/Assignment 2/src/ca/cosc3p91/a2/game/Map.java index 529676b..cc9497e 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/game/Map.java +++ b/Assignment 2/src/ca/cosc3p91/a2/game/Map.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.game; +package ca.cosc3p91.a4.game; -import ca.cosc3p91.a3.gameobjects.*; +import ca.cosc3p91.a4.gameobjects.*; import java.util.ArrayList; import java.util.List; diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Archer.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Archer.java index dd5e141..1c2a5c6 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Archer.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Archer.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Archer extends Infantry { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ArcherTower.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ArcherTower.java index 6b4a97f..b166412 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ArcherTower.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ArcherTower.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class ArcherTower extends DefenseBuilding { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Building.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Building.java index ae6de98..f8ff980 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Building.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Building.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; import java.util.ArrayList; diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Cannon.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Cannon.java index e925b2f..98dcb0b 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Cannon.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Cannon.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Cannon extends DefenseBuilding { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/CasaDeNarino.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/CasaDeNarino.java index cc5dc95..c359934 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/CasaDeNarino.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/CasaDeNarino.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class CasaDeNarino extends Building { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Catapult.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Catapult.java index b54dbc0..1976916 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Catapult.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Catapult.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Catapult extends Infantry { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Collector.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Collector.java index 6e206d0..a9ace15 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Collector.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Collector.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Collector implements Inhabitant { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseBuilding.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseBuilding.java index 5fddb8d..bf1096c 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseBuilding.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseBuilding.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public abstract class DefenseBuilding extends Building { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStage.java index edcab79..661b4bb 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStage.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; class DefenseStage extends Stage { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStages.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStages.java index 9d7c4e3..235e2ac 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStages.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStages.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public class DefenseStages { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java index 0e7b613..2072a62 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Farm extends ResourceBuilding { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Infantry.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Infantry.java index 64b4468..7d4cadd 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Infantry.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Infantry.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public abstract class Infantry implements Inhabitant { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Inhabitant.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Inhabitant.java index 2003cbd..af2895d 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Inhabitant.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Inhabitant.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.game.Map; +import ca.cosc3p91.a4.game.Map; public interface Inhabitant { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java index e505e45..3537145 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class IronMine extends ResourceBuilding { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Knight.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Knight.java index a01768a..3a7d4e4 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Knight.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Knight.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Knight extends Infantry { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java index 523f538..464cb2c 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class LumberMine extends ResourceBuilding { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java index 7c68ca3..6f1b9da 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public abstract class ResourceBuilding extends Building { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java index a361086..db02f18 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public class ResourceStage extends Stage { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStages.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStages.java index fea808d..8e33d1e 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStages.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStages.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public class ResourceStages { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java index 5e06583..9bf821b 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class SaulGoodMine extends ResourceBuilding { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Soldier.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Soldier.java index 94520a0..eb997bd 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Soldier.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Soldier.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Soldier extends Infantry { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java index 5d60966..17a6966 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; import java.util.HashMap; diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Tile.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Tile.java index 2449e5c..ee11ed2 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Tile.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Tile.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; import java.util.List; diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageHallStages.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageHallStages.java index 775bf05..dfd3eab 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageHallStages.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageHallStages.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public class VillageHallStages { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java index 87eaec6..248d612 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public class VillageStage extends Stage { diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Worker.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Worker.java index 8a14141..4230bcb 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Worker.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Worker.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Worker implements Inhabitant { diff --git a/Assignment 2/src/ca/cosc3p91/a2/player/Player.java b/Assignment 2/src/ca/cosc3p91/a2/player/Player.java index af70351..3b16dfc 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/player/Player.java +++ b/Assignment 2/src/ca/cosc3p91/a2/player/Player.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.player; +package ca.cosc3p91.a4.player; public class Player { diff --git a/Assignment 2/src/ca/cosc3p91/a2/userinterface/GuiManager.java b/Assignment 2/src/ca/cosc3p91/a2/userinterface/GuiManager.java index 65f61ca..0db0e33 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/userinterface/GuiManager.java +++ b/Assignment 2/src/ca/cosc3p91/a2/userinterface/GuiManager.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.userinterface; +package ca.cosc3p91.a4.userinterface; public class GuiManager { } \ No newline at end of file diff --git a/Assignment 2/src/ca/cosc3p91/a2/util/Print.java b/Assignment 2/src/ca/cosc3p91/a2/util/Print.java index 538a566..4211364 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/util/Print.java +++ b/Assignment 2/src/ca/cosc3p91/a2/util/Print.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.util; +package ca.cosc3p91.a4.util; import java.util.ArrayList; import java.util.Arrays; diff --git a/Assignment 2/src/ca/cosc3p91/a2/util/Time.java b/Assignment 2/src/ca/cosc3p91/a2/util/Time.java index 254411a..e9a56f1 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/util/Time.java +++ b/Assignment 2/src/ca/cosc3p91/a2/util/Time.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.util; +package ca.cosc3p91.a4.util; public class Time { diff --git a/Assignment 2/src/ca/cosc3p91/a2/util/Util.java b/Assignment 2/src/ca/cosc3p91/a2/util/Util.java index f9efe4b..78d27a5 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/util/Util.java +++ b/Assignment 2/src/ca/cosc3p91/a2/util/Util.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.util; +package ca.cosc3p91.a4.util; import java.util.Random; diff --git a/Assignment 3/src/ca/cosc3p91/a3/Main.java b/Assignment 3/src/ca/cosc3p91/a3/Main.java index 13cdbc0..e06aa2f 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/Main.java +++ b/Assignment 3/src/ca/cosc3p91/a3/Main.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3; +package ca.cosc3p91.a4; -import ca.cosc3p91.a3.game.GameEngine; +import ca.cosc3p91.a4.game.GameEngine; public class Main { diff --git a/Assignment 3/src/ca/cosc3p91/a3/game/GameEngine.java b/Assignment 3/src/ca/cosc3p91/a3/game/GameEngine.java index b378419..fba0bc3 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/game/GameEngine.java +++ b/Assignment 3/src/ca/cosc3p91/a3/game/GameEngine.java @@ -1,11 +1,11 @@ -package ca.cosc3p91.a3.game; +package ca.cosc3p91.a4.game; -import ca.cosc3p91.a3.gameobjects.*; -import ca.cosc3p91.a3.gameobjects.factory.BuildingFactory; -import ca.cosc3p91.a3.gameobjects.factory.InhabitantFactory; -import ca.cosc3p91.a3.player.*; -import ca.cosc3p91.a3.userinterface.GameDisplay; -import ca.cosc3p91.a3.util.ChallengeAdapter; +import ca.cosc3p91.a4.gameobjects.*; +import ca.cosc3p91.a4.gameobjects.factory.BuildingFactory; +import ca.cosc3p91.a4.gameobjects.factory.InhabitantFactory; +import ca.cosc3p91.a4.player.*; +import ca.cosc3p91.a4.userinterface.GameDisplay; +import ca.cosc3p91.a4.util.ChallengeAdapter; import java.beans.XMLEncoder; import java.io.BufferedOutputStream; diff --git a/Assignment 3/src/ca/cosc3p91/a3/game/Map.java b/Assignment 3/src/ca/cosc3p91/a3/game/Map.java index 529676b..cc9497e 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/game/Map.java +++ b/Assignment 3/src/ca/cosc3p91/a3/game/Map.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.game; +package ca.cosc3p91.a4.game; -import ca.cosc3p91.a3.gameobjects.*; +import ca.cosc3p91.a4.gameobjects.*; import java.util.ArrayList; import java.util.List; diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Archer.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Archer.java index dd5e141..1c2a5c6 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Archer.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Archer.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Archer extends Infantry { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ArcherTower.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ArcherTower.java index 6b4a97f..b166412 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ArcherTower.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ArcherTower.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class ArcherTower extends DefenseBuilding { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Building.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Building.java index e9d93b9..c6e4019 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Building.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Building.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; import java.io.Serializable; import java.util.ArrayList; diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Cannon.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Cannon.java index e925b2f..98dcb0b 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Cannon.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Cannon.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Cannon extends DefenseBuilding { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/CasaDeNarino.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/CasaDeNarino.java index cc5dc95..c359934 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/CasaDeNarino.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/CasaDeNarino.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class CasaDeNarino extends Building { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Catapult.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Catapult.java index b54dbc0..1976916 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Catapult.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Catapult.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Catapult extends Infantry { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Collector.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Collector.java index 6e206d0..a9ace15 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Collector.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Collector.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Collector implements Inhabitant { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseBuilding.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseBuilding.java index 0df9819..e7f9a6a 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseBuilding.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseBuilding.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public abstract class DefenseBuilding extends Building { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseStage.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseStage.java index edcab79..661b4bb 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseStage.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseStage.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; class DefenseStage extends Stage { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseStages.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseStages.java index 9d7c4e3..235e2ac 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseStages.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/DefenseStages.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public class DefenseStages { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Farm.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Farm.java index 16ccc5d..7c236a3 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Farm.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Farm.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Farm extends ResourceBuilding { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Infantry.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Infantry.java index 64b4468..7d4cadd 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Infantry.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Infantry.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public abstract class Infantry implements Inhabitant { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Inhabitant.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Inhabitant.java index e30118f..95f51ab 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Inhabitant.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Inhabitant.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; import java.io.Serializable; diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/IronMine.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/IronMine.java index fad54f3..3e88b06 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/IronMine.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/IronMine.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class IronMine extends ResourceBuilding { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Knight.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Knight.java index a01768a..3a7d4e4 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Knight.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Knight.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Knight extends Infantry { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/LumberMine.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/LumberMine.java index 71d89d8..412aba5 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/LumberMine.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/LumberMine.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class LumberMine extends ResourceBuilding { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceBuilding.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceBuilding.java index 9301cf9..37680f4 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceBuilding.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceBuilding.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public abstract class ResourceBuilding extends Building { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceStage.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceStage.java index a361086..db02f18 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceStage.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceStage.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public class ResourceStage extends Stage { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceStages.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceStages.java index fea808d..8e33d1e 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceStages.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/ResourceStages.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public class ResourceStages { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/SaulGoodMine.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/SaulGoodMine.java index 0834003..a7c8d1d 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/SaulGoodMine.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/SaulGoodMine.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class SaulGoodMine extends ResourceBuilding { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Soldier.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Soldier.java index 94520a0..eb997bd 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Soldier.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Soldier.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Soldier extends Infantry { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Stage.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Stage.java index d5d2a05..b554e9c 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Stage.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Stage.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; import java.io.Serializable; diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Tile.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Tile.java index 20ede00..e4078e9 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Tile.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Tile.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Tile { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/VillageHallStages.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/VillageHallStages.java index 775bf05..dfd3eab 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/VillageHallStages.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/VillageHallStages.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public class VillageHallStages { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/VillageStage.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/VillageStage.java index 87eaec6..248d612 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/VillageStage.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/VillageStage.java @@ -1,6 +1,6 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; -import ca.cosc3p91.a3.util.Time; +import ca.cosc3p91.a4.util.Time; public class VillageStage extends Stage { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Worker.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Worker.java index 8a14141..4230bcb 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Worker.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/Worker.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.gameobjects; +package ca.cosc3p91.a4.gameobjects; public class Worker implements Inhabitant { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/factory/BuildingFactory.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/factory/BuildingFactory.java index bc8bdfb..1fc283d 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/factory/BuildingFactory.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/factory/BuildingFactory.java @@ -1,7 +1,7 @@ -package ca.cosc3p91.a3.gameobjects.factory; +package ca.cosc3p91.a4.gameobjects.factory; -import ca.cosc3p91.a3.gameobjects.*; -import ca.cosc3p91.a3.util.Util; +import ca.cosc3p91.a4.gameobjects.*; +import ca.cosc3p91.a4.util.Util; public class BuildingFactory { public Building getBuilding(String buildingName) { diff --git a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/factory/InhabitantFactory.java b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/factory/InhabitantFactory.java index b984154..6b4aacc 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/gameobjects/factory/InhabitantFactory.java +++ b/Assignment 3/src/ca/cosc3p91/a3/gameobjects/factory/InhabitantFactory.java @@ -1,7 +1,7 @@ -package ca.cosc3p91.a3.gameobjects.factory; +package ca.cosc3p91.a4.gameobjects.factory; -import ca.cosc3p91.a3.gameobjects.*; -import ca.cosc3p91.a3.util.Util; +import ca.cosc3p91.a4.gameobjects.*; +import ca.cosc3p91.a4.util.Util; public class InhabitantFactory { public Inhabitant getInhabitant(String inhabitantName) { diff --git a/Assignment 3/src/ca/cosc3p91/a3/player/Player.java b/Assignment 3/src/ca/cosc3p91/a3/player/Player.java index af70351..3b16dfc 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/player/Player.java +++ b/Assignment 3/src/ca/cosc3p91/a3/player/Player.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.player; +package ca.cosc3p91.a4.player; public class Player { diff --git a/Assignment 3/src/ca/cosc3p91/a3/userinterface/GameDisplay.java b/Assignment 3/src/ca/cosc3p91/a3/userinterface/GameDisplay.java index 7a60d00..19e06fd 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/userinterface/GameDisplay.java +++ b/Assignment 3/src/ca/cosc3p91/a3/userinterface/GameDisplay.java @@ -1,9 +1,9 @@ -package ca.cosc3p91.a3.userinterface; +package ca.cosc3p91.a4.userinterface; -import ca.cosc3p91.a3.game.Map; -import ca.cosc3p91.a3.gameobjects.Building; -import ca.cosc3p91.a3.gameobjects.Inhabitant; -import ca.cosc3p91.a3.util.Print; +import ca.cosc3p91.a4.game.Map; +import ca.cosc3p91.a4.gameobjects.Building; +import ca.cosc3p91.a4.gameobjects.Inhabitant; +import ca.cosc3p91.a4.util.Print; import java.io.BufferedReader; import java.io.IOException; diff --git a/Assignment 3/src/ca/cosc3p91/a3/util/ChallengeAdapter.java b/Assignment 3/src/ca/cosc3p91/a3/util/ChallengeAdapter.java index 76d3269..d1c47bf 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/util/ChallengeAdapter.java +++ b/Assignment 3/src/ca/cosc3p91/a3/util/ChallengeAdapter.java @@ -1,8 +1,8 @@ -package ca.cosc3p91.a3.util; +package ca.cosc3p91.a4.util; import ChallengeDecision.*; -import ca.cosc3p91.a3.game.Map; -import ca.cosc3p91.a3.gameobjects.*; +import ca.cosc3p91.a4.game.Map; +import ca.cosc3p91.a4.gameobjects.*; import java.util.ArrayList; import java.util.List; diff --git a/Assignment 3/src/ca/cosc3p91/a3/util/Print.java b/Assignment 3/src/ca/cosc3p91/a3/util/Print.java index 538a566..4211364 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/util/Print.java +++ b/Assignment 3/src/ca/cosc3p91/a3/util/Print.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.util; +package ca.cosc3p91.a4.util; import java.util.ArrayList; import java.util.Arrays; diff --git a/Assignment 3/src/ca/cosc3p91/a3/util/Time.java b/Assignment 3/src/ca/cosc3p91/a3/util/Time.java index 6f5ee06..04fb156 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/util/Time.java +++ b/Assignment 3/src/ca/cosc3p91/a3/util/Time.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.util; +package ca.cosc3p91.a4.util; import java.io.Serializable; diff --git a/Assignment 3/src/ca/cosc3p91/a3/util/Util.java b/Assignment 3/src/ca/cosc3p91/a3/util/Util.java index 634092d..140545c 100644 --- a/Assignment 3/src/ca/cosc3p91/a3/util/Util.java +++ b/Assignment 3/src/ca/cosc3p91/a3/util/Util.java @@ -1,4 +1,4 @@ -package ca.cosc3p91.a3.util; +package ca.cosc3p91.a4.util; import java.util.Random; diff --git a/Assignment 4/assignment3_instructions.pdf b/Assignment 4/assignment3_instructions.pdf new file mode 100644 index 0000000..3ceffc6 Binary files /dev/null and b/Assignment 4/assignment3_instructions.pdf differ diff --git a/Assignment 4/src/ChallengeDecision/Arbitrer.java b/Assignment 4/src/ChallengeDecision/Arbitrer.java new file mode 100644 index 0000000..91c265a --- /dev/null +++ b/Assignment 4/src/ChallengeDecision/Arbitrer.java @@ -0,0 +1,84 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package ChallengeDecision; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +/** + * + * @author robson + */ +public class Arbitrer { + + public static ChallengeResult challengeDecide( ChallengeEntitySet challenger, ChallengeEntitySet challengee ) { + ChallengeResult challengeResult = new ChallengeResult( false ); + int i = 0, j = 0, challengerSize, challengeeSize; + FightResult fr; + ChallengeEntity tempCE; + Boolean challengerTurn = true; + double challengerPower = 0; + List> resultingResources = new ArrayList<>(); + + challengerSize = challenger.getEntityAttackList().size(); + challengeeSize = challengee.getEntityDefenseList().size(); + + for ( ChallengeAttack ce : challenger.getEntityAttackList() ) + challengerPower += ce.getProperty().doubleValue(); + + if ( challengerSize > 0 ) { + tempCE = challenger.getEntityAttackList().get( i++ ); + + while ( i < challengerSize && j < challengeeSize ) { + if ( challengerTurn ) { //tempCE is the challenger + fr = tempCE.fight( challengee.entityDefenseList.get( j ) ); + challengerTurn = fr.getResult(); + tempCE = fr.getChallengeEntity(); + if ( challengerTurn ) + j++; + else i++; + } else { //tempCE is the challengee + fr = challenger.getEntityAttackList().get( i ).fight( tempCE ); + challengerTurn = fr.getResult(); + tempCE = fr.getChallengeEntity(); + if ( challengerTurn ) + j++; + else i++; + } + } + + // check what is remaining + + if ( i < challengerSize ) { // 1 - there are still reamaining challengers + double sum = 0; + double proportion; + + while ( i < challengerSize ) { + sum += challenger.getEntityAttackList().get( i++ ).getProperty().doubleValue(); + } + + proportion = sum / challengerPower; + + challengee.getEntityResourceList().forEach((ce) -> { + resultingResources.add( new ChallengeResource( ce.getProperty().doubleValue() * ( proportion * getLootChance() ) ) ); + }); + + challengeResult = new ChallengeResult( true, resultingResources ); + } else if ( j < challengerSize ) { // 2 - there are still reamaining challengees + // no resources got back from attack + challengeResult = new ChallengeResult( false ); + } + + } + + return challengeResult; + } + + private static double getLootChance() { + return ( ThreadLocalRandom.current().nextInt(1, 10 ) + 10 ) / 20.0; + } +} diff --git a/Assignment 4/src/ChallengeDecision/ChallengeAttack.java b/Assignment 4/src/ChallengeDecision/ChallengeAttack.java new file mode 100644 index 0000000..53c22c0 --- /dev/null +++ b/Assignment 4/src/ChallengeDecision/ChallengeAttack.java @@ -0,0 +1,104 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package ChallengeDecision; + +import java.util.concurrent.ThreadLocalRandom; + +/** + * + * @author robson + * @param + */ +public class ChallengeAttack extends ChallengeEntity { + T attack; + V hit; + + public ChallengeAttack( T attack, V hit ) { + this.attack = attack; + this.hit = hit; + } + + public ChallengeAttack( T attack ) { + this.attack = attack; + } + + @Override + public T getProperty() { + return this.attack; + } + + @Override + public void setProperty( T attack ) { + this.attack = attack; + } + + @Override + public V getHitPoints() { + return hit; + } + + @Override + public void setHitPoints( V value ) { + hit = value; + } + + + @Override + public int compare( ChallengeEntity ce ) { + double result; + result = this.attack.doubleValue() - ce.getProperty().doubleValue(); + + if ( result == 0 ) + return 0; + else if ( result > 0 ) + return 1; + else return -1; + } + + @Override + public double checkDifference( ChallengeEntity ce ) { + return this.attack.doubleValue() - ce.getProperty().doubleValue(); + } + + public FightResult fight( ChallengeEntity ce ) { + Boolean fightOutcome = false; + ChallengeEntity re; + + double result; + result = ( attack.doubleValue() + hit.doubleValue() ) - ( ce.getProperty().doubleValue() + ce.getHitPoints().doubleValue() ); + + if ( result > 0 ) { + if ( result / ( attack.doubleValue() + hit.doubleValue() ) > 0.2 ) { // it won by a large difference + fightOutcome = ThreadLocalRandom.current().nextInt(1, 100) > 10; //attack success + if ( fightOutcome ) { //attack success -> attacker remains + re = new ChallengeAttack<>( attack.doubleValue() ); + re.setHitPoints( ce.getHitPoints().doubleValue() * 0.75 ); + } else { //attack fail -> defense remains + re = new ChallengeDefense<>( ce.getProperty().doubleValue() ); + re.setHitPoints( ce.getHitPoints().doubleValue() * 0.3 ); + } + } else { // it won by a small difference + fightOutcome = ThreadLocalRandom.current().nextInt(1, 100) > 50; //attack success + if ( fightOutcome ) { //attack success -> attacker remains + re = new ChallengeAttack<>( attack.doubleValue() ); + re.setHitPoints( ce.getHitPoints().doubleValue() * 0.5 ); + } else { //attack fail -> defense remains + re = new ChallengeDefense<>( ce.getProperty().doubleValue() ); + re.setHitPoints( ce.getHitPoints().doubleValue() * 0.5 ); + } + } + } else { // attack fail + re = new ChallengeDefense<>( ce.getProperty().doubleValue() ); + if ( ( result * -1 ) / ( ce.getProperty().doubleValue() + ce.getHitPoints().doubleValue() ) > 0.5 ) { // it defended by a large difference -> it keeps 80% of health + re.setHitPoints( ce.getHitPoints().doubleValue() * 0.75 ); + } else { // it defended by a small difference -> it keeps 505 of health + re.setHitPoints( ce.getHitPoints().doubleValue() * 0.5 ); + } + } + + return new FightResult( fightOutcome, re ); + } +} diff --git a/Assignment 4/src/ChallengeDecision/ChallengeDefense.java b/Assignment 4/src/ChallengeDecision/ChallengeDefense.java new file mode 100644 index 0000000..bc02c6a --- /dev/null +++ b/Assignment 4/src/ChallengeDecision/ChallengeDefense.java @@ -0,0 +1,68 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package ChallengeDecision; + +/** + * + * @author robson + * @param + */ +public class ChallengeDefense extends ChallengeEntity { + T defense; + V hit; + + public ChallengeDefense( T defense ) { + this.defense = defense; + } + + public ChallengeDefense( T defense, V hit ) { + this.defense = defense; + this.hit = hit; + } + + @Override + public T getProperty() { + return this.defense; + } + + @Override + public void setProperty( T defense ) { + this.defense = defense; + } + + @Override + public V getHitPoints() { + return hit; + } + + @Override + public void setHitPoints( V value ) { + hit = value; + } + + @Override + public int compare( ChallengeEntity ce ) { + double result; + result = this.defense.doubleValue() - ce.getProperty().doubleValue(); + + if ( result == 0 ) + return 0; + else if ( result > 0 ) + return 1; + else return -1; + } + + @Override + public double checkDifference( ChallengeEntity ce ) { + return this.defense.doubleValue() - ce.getProperty().doubleValue(); + } + + @Override + public FightResult fight(ChallengeEntity ce) { + return new FightResult( false, new ChallengeDefense( 0 ) ); + } + +} diff --git a/Assignment 4/src/ChallengeDecision/ChallengeEntity.java b/Assignment 4/src/ChallengeDecision/ChallengeEntity.java new file mode 100644 index 0000000..16d3b41 --- /dev/null +++ b/Assignment 4/src/ChallengeDecision/ChallengeEntity.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package ChallengeDecision; + +/** + * + * @author robson + */ +public abstract class ChallengeEntity { + + public abstract T getProperty(); + + public abstract void setProperty( T property ); + + public abstract V getHitPoints(); + + public abstract void setHitPoints( V value ); + + public abstract int compare( ChallengeEntity ce ); + + public abstract FightResult fight( ChallengeEntity ce ); + + public abstract double checkDifference( ChallengeEntity ce ); +} diff --git a/Assignment 4/src/ChallengeDecision/ChallengeEntitySet.java b/Assignment 4/src/ChallengeDecision/ChallengeEntitySet.java new file mode 100644 index 0000000..9752248 --- /dev/null +++ b/Assignment 4/src/ChallengeDecision/ChallengeEntitySet.java @@ -0,0 +1,56 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package ChallengeDecision; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author robson + */ +public class ChallengeEntitySet { + List> entityAttackList; + List> entityDefenseList; + List> entityResourceList; + + public ChallengeEntitySet( List> entityAttackList, List> entityDefenseList, List> entityResourceList ) { + this.entityAttackList = entityAttackList; + this.entityDefenseList = entityDefenseList; + this.entityResourceList = entityResourceList; + } + + public ChallengeEntitySet() { + entityAttackList = new ArrayList(); + entityDefenseList = new ArrayList(); + entityResourceList = new ArrayList(); + } + + public void setEntityAttackList( List> entityAttackList ) { + this.entityAttackList = entityAttackList; + + } + + public void setEntityDefenseList( List> entityDefenseList ) { + this.entityDefenseList = entityDefenseList; + } + + public void setEntityResourceList( List> entityResourceList ) { + this.entityResourceList = entityResourceList; + } + + public List> getEntityAttackList(){ + return this.entityAttackList; + } + + public List> getEntityDefenseList(){ + return this.entityDefenseList; + } + + public List> getEntityResourceList(){ + return this.entityResourceList; + } +} diff --git a/Assignment 4/src/ChallengeDecision/ChallengeResource.java b/Assignment 4/src/ChallengeDecision/ChallengeResource.java new file mode 100644 index 0000000..9556efc --- /dev/null +++ b/Assignment 4/src/ChallengeDecision/ChallengeResource.java @@ -0,0 +1,75 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package ChallengeDecision; + +/** + * + * @author robson + * @param + */ +public class ChallengeResource extends ChallengeEntity { + T resource; + V hit; + + public ChallengeResource() { + } + + public ChallengeResource( T resource ) { + this.resource = resource; + } + + public ChallengeResource( T resource, V hit ) { + this.resource = resource; + this.hit = hit; + } + + @Override + public T getProperty() { + return this.resource; + } + + @Override + public void setProperty( T resource ) { + this.resource = resource; + } + + @Override + public V getHitPoints() { + return hit; + } + + @Override + public void setHitPoints( V value ) { + hit = value; + } + + + @Override + public int compare( ChallengeEntity ce ) { + double result; + result = this.resource.doubleValue() - ce.getProperty().doubleValue(); + + if ( result == 0 ) + return 0; + else if ( result > 0 ) + return 1; + else return -1; + } + + @Override + public double checkDifference( ChallengeEntity ce ) { + return this.resource.doubleValue() - ce.getProperty().doubleValue(); + } + + @Override + public FightResult fight(ChallengeEntity ce) { + return new FightResult( false, new ChallengeDefense( 0 ) ); + } + + public void print() { + System.out.println( "Resource: " + resource + " / Hit: " + hit ); + } +} diff --git a/Assignment 4/src/ChallengeDecision/ChallengeResult.java b/Assignment 4/src/ChallengeDecision/ChallengeResult.java new file mode 100644 index 0000000..1c7b7ff --- /dev/null +++ b/Assignment 4/src/ChallengeDecision/ChallengeResult.java @@ -0,0 +1,43 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package ChallengeDecision; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author robson + */ +public class ChallengeResult { + Boolean challengeWon; + List> loot; + + public ChallengeResult( Boolean won, List> loot ) { + challengeWon = won; + this.loot = loot; + } + + public ChallengeResult( Boolean won ) { + challengeWon = won; + loot = new ArrayList<>(); + } + + public Boolean getChallengeWon() { + return challengeWon; + } + + public List> getLoot() { + return loot; + } + + public void print() { + System.out.println( "Result: " + challengeWon ); + for ( ChallengeResource e : loot ) { + e.print(); + } + } +} diff --git a/Assignment 4/src/ChallengeDecision/FightResult.java b/Assignment 4/src/ChallengeDecision/FightResult.java new file mode 100644 index 0000000..0ea9187 --- /dev/null +++ b/Assignment 4/src/ChallengeDecision/FightResult.java @@ -0,0 +1,28 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package ChallengeDecision; + +/** + * + * @author robson + */ +class FightResult { + Boolean result; + ChallengeEntity ce; + + public FightResult( Boolean result, ChallengeEntity ce ) { + this.result = result; + this.ce = ce; + } + + public Boolean getResult() { + return this.result; + } + + public ChallengeEntity getChallengeEntity() { + return ce; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/Main.java b/Assignment 4/src/ca/cosc3p91/a4/Main.java new file mode 100644 index 0000000..e06aa2f --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/Main.java @@ -0,0 +1,11 @@ +package ca.cosc3p91.a4; + +import ca.cosc3p91.a4.game.GameEngine; + +public class Main { + + public static void main(String[] args) { + new GameEngine().run(); + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/game/GameEngine.java b/Assignment 4/src/ca/cosc3p91/a4/game/GameEngine.java new file mode 100644 index 0000000..fba0bc3 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/game/GameEngine.java @@ -0,0 +1,265 @@ +package ca.cosc3p91.a4.game; + +import ca.cosc3p91.a4.gameobjects.*; +import ca.cosc3p91.a4.gameobjects.factory.BuildingFactory; +import ca.cosc3p91.a4.gameobjects.factory.InhabitantFactory; +import ca.cosc3p91.a4.player.*; +import ca.cosc3p91.a4.userinterface.GameDisplay; +import ca.cosc3p91.a4.util.ChallengeAdapter; + +import java.beans.XMLEncoder; +import java.io.BufferedOutputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Random; + +public class GameEngine implements Runnable { + + public static final double GOLD_FACTOR = 5; + public static final double IRON_FACTOR = 1; + public static final double WOOD_FACTOR = 0.1; + + private Player player; + boolean running = true; + + private float pillageFactor = 0.5f; + + private int currentTime; + + private final Random random = new Random(System.nanoTime()); + + public Map map; + public GameDisplay view; + + public GameEngine() { + player = new Player(); + map = generateInitialMap(); + } + + public void attackVillage(Map map) { +// int defenseiveCounter = 1; +// int inhabCounter = 0; +// for (Building b : map.contains) +// if (b instanceof DefenseBuilding) +// defenseiveCounter++; +// for (Inhabitant i : map.inhabitants) +// if (i instanceof Infantry) +// inhabCounter++; +// pillageFactor = (float) inhabCounter / (float) defenseiveCounter; +// if (pillageFactor < 0) +// pillageFactor = 0; +// if (pillageFactor > 1) +// pillageFactor = 1; +// this.map.getTownHall().addWood((int) (map.getTownHall().getCurrentWood() * pillageFactor)); +// this.map.getTownHall().addIron((int) (map.getTownHall().getCurrentIron() * pillageFactor)); +// this.map.getTownHall().addGold((int) (map.getTownHall().getCurrentGold() * pillageFactor)); + ChallengeAdapter adapter = new ChallengeAdapter(this.map); + adapter.attack(map); + } + + private Map generateInitialMap(){ + return new Map(new CasaDeNarino(1, VillageHallStages.villageStages[0]), 30); + } + + public Map generateMap() { + Map initialMap = generateInitialMap(); + + CasaDeNarino hall = initialMap.getTownHall(); + + // generate a similar town hall + int levelChange = random.nextInt(2) - 1; + int nextLevel = this.map.getTownHall().getLevel() + levelChange; + // only need to change if the new village level is higher than initial + if (nextLevel > 0) + hall.upgrade(VillageHallStages.villageStages[nextLevel]); + + hall.addWood(this.map.getTownHall().getCurrentWood() + random.nextInt(500) - 150); + hall.addIron(this.map.getTownHall().getCurrentIron() + random.nextInt(500) - 150); + hall.addGold(this.map.getTownHall().getCurrentGold() + random.nextInt(500) - 150); + + int buildingCount = this.map.contains.size(); + + int saulGoodMines = 0; + int ironMines = 0; + int woodMines = 0; + int archerTowers = 0; + int cannons = 0; + + // count buildings in our map + for (Building b : this.map.contains){ + if (b instanceof SaulGoodMine) + saulGoodMines++; + else if (b instanceof IronMine) + ironMines++; + else if (b instanceof LumberMine) + woodMines++; + else if (b instanceof ArcherTower) + archerTowers++; + else if (b instanceof Cannon) + cannons++; + } + + // variate + saulGoodMines += random.nextInt();; + ironMines += random.nextInt(); + woodMines += random.nextInt(); + archerTowers += random.nextInt(); + cannons += random.nextInt(); + + // generate a map with a similar number of buildings + for (int i = 0; i < Math.max(buildingCount + random.nextInt(5) - 2, 1); i++) { + int selection = random.nextInt(5); + // select a random building. Doing it this way because if we build based on buildings we have + // then the maps will be VERY boring as they would be all the same + switch (selection) { + case 0: + initialMap.contains.add(new LumberMine(ResourceStages.woodStages[random.nextInt(ResourceStages.woodStages.length)])); + break; + case 1: + if (ironMines > 0) + initialMap.contains.add(new IronMine(ResourceStages.ironStages[random.nextInt(ResourceStages.ironStages.length)])); + break; + case 2: + if (saulGoodMines > 0) + initialMap.contains.add(new SaulGoodMine(ResourceStages.goldStages[random.nextInt(ResourceStages.goldStages.length)])); + break; + case 3: + initialMap.contains.add(new ArcherTower()); + break; + case 4: + initialMap.contains.add(new Cannon()); + break; + default: + break; + } + } + + return initialMap; + } + + public int getScore(Map map) { + CasaDeNarino hall = map.getTownHall(); + int score = (int)(hall.getCurrentGold() * GOLD_FACTOR + hall.getCurrentIron() * IRON_FACTOR + hall.getCurrentWood() * WOOD_FACTOR); + score += map.contains.size(); + score += map.inhabitants.size(); + return score; + } + + @Override + public void run() { + String in; + + view = new GameDisplay(); + view.printVillageState(this.map,"Current Village State"); + view.printGameMenu(); + + Map exploringMap = null; + boolean deleteMyHeart = true; + while (running) { + for (Building b : this.map.contains){ + if ((b instanceof ResourceBuilding)) { + ((ResourceBuilding) b).update(this.map.getTownHall()); + } + } + try { + if ((in = view.nextInput()) != null) { + String[] args = in.split(" "); + + view.printLastInput(); + // reset the map if they aren't exploring + if (in.charAt(0) != '4') + deleteMyHeart = true; + switch (in.charAt(0)) { + case '1': + if (args.length < 2) { + System.err.println("Args must include type!"); + } else { + BuildingFactory bfactory = new BuildingFactory(); + Building type = bfactory.getBuilding(args[1]); + if (type == null) + System.err.println("Args are not a valid building!"); + else if (this.map.build(new Tile(), type) ) { + System.out.println(type.getClass().getSimpleName()+" successfully built\n"); + } else + System.out.println("Missing resources to build "+type.getClass().getSimpleName()); + } + break; + case '2': + if (args.length < 2) { + System.err.println("Args must include type!"); + } else { + InhabitantFactory ifactory = new InhabitantFactory(); + Inhabitant type = ifactory.getInhabitant(args[1]); + if (type == null) + System.err.println("Args are not a valid inhabitant!"); + else if (this.map.train(type) ) { + System.out.println("successfully trained a(n) "+type.getClass().getSimpleName()); + } else System.out.println("Missing gold to train "+type.getClass().getSimpleName()); + } + break; + case '3': + if (args.length < 2) { + System.err.println("Args must include type!"); + } else { + int unitIndex = Integer.parseInt(args[1].substring(1)); + + if (unitIndex < 0) { + System.err.println("Invalid Index"); + break; + } + + if (args[1].contains("i") && (unitIndex < map.inhabitants.size()) ) { + if ( map.upgradeInhabitant(unitIndex) ) { + System.out.println("successfully upgraded a(n) "+map.inhabitants.get(unitIndex).getClass().getSimpleName()); + } else System.out.println("Missing Resources to upgrade "+map.inhabitants.get(unitIndex).getClass().getSimpleName()); + } else if (args[1].contains("b") && (unitIndex < map.contains.size()) ) { + if ( map.upgradeBuilding(unitIndex) ) { + System.out.println("successfully upgraded a(n) "+map.contains.get(unitIndex).getClass().getSimpleName()); + } else System.out.println("Missing Resources to upgrade "+map.contains.get(unitIndex).getClass().getSimpleName()); + } else { + System.err.println("Args are not a valid unit!"); + } + } + break; + case '4': + deleteMyHeart = false; + exploringMap = generateMap(); + view.printVillageState(exploringMap,"Other Village"); + break; + case '7': + if (exploringMap != null) + attackVillage(exploringMap); + else + System.out.println("Error: Explored map is null. Have you explored last command?"); + break; + case '5': + view.printVillageState(this.map,"Home Village"); + break; + case '6': + System.exit(0); + break; + default: + break; + } + view.printGameMenu(); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + if (deleteMyHeart) + exploringMap = null; + } + save("test.xml", this.map); + } + + public void save(String file, Map map){ + try (XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(Files.newOutputStream(Paths.get(file))))) { + map.contains.forEach(encoder::writeObject); + map.inhabitants.forEach(encoder::writeObject); + System.out.println("Wrote map"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/game/Map.java b/Assignment 4/src/ca/cosc3p91/a4/game/Map.java new file mode 100644 index 0000000..cc9497e --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/game/Map.java @@ -0,0 +1,142 @@ +package ca.cosc3p91.a4.game; + +import ca.cosc3p91.a4.gameobjects.*; + +import java.util.ArrayList; +import java.util.List; + +public class Map { + + static int MAXSIZE = 50; + + private CasaDeNarino townHall; + + private int guardTime; + + public List contains; + + public List inhabitants; + + public Map(CasaDeNarino casaDeNarino, int gTime) { + contains = new ArrayList<>(); + inhabitants = new ArrayList<>(); + this.townHall = casaDeNarino; + this.contains.add(casaDeNarino); + this.inhabitants.add(new Worker()); this.inhabitants.add(new Worker()); + this.inhabitants.add(new Collector()); + this.guardTime = gTime; + } + + public void move(Infantry i, Tile t) { + + } + + public void inRange(Infantry i, Building b) { + + } + + public boolean build(Tile t, Building b) { + int goldCost = b.getStage().getCost(SaulGoodMine.resource); + int ironCost = b.getStage().getCost(IronMine.resource); + int woodCost = b.getStage().getCost(LumberMine.resource); + CasaDeNarino hall = getTownHall(); + if (hall.getCurrentGold() >= goldCost && hall.getCurrentIron() >= ironCost && hall.getCurrentWood() >= woodCost) { + if(!hall.addGold(-goldCost)) + throw new RuntimeException("Unable to subtract gold despite valid check!"); + if(!hall.addIron(-ironCost)) + throw new RuntimeException("Unable to subtract iron despite valid check!"); + if(!hall.addWood(-woodCost)) + throw new RuntimeException("Unable to subtract wood despite valid check!"); + contains.add(b); + return true; + } else + return false; + } + + public boolean upgradeBuilding(int buildingIndex) { + + if (buildingIndex >= contains.size()) return false; + + Building b = contains.get(buildingIndex); + + int currentLevel = b.getLevel(); + CasaDeNarino hall = getTownHall(); + + if (currentLevel >= 2) return false; + else if (b instanceof Farm) return true; + + int goldCost = b.getUpgradeStage().getCost(SaulGoodMine.resource); + int ironCost = b.getUpgradeStage().getCost(IronMine.resource); + int woodCost = b.getUpgradeStage().getCost(LumberMine.resource); + + if (hall.getCurrentGold() >= goldCost && hall.getCurrentIron() >= ironCost && hall.getCurrentWood() >= woodCost) { + + if (b instanceof DefenseBuilding) { + ((DefenseBuilding) b).upgrade( + (b instanceof ArcherTower) ? (DefenseStages.archerTowerStages[currentLevel + 1]) : + (DefenseStages.cannonStages[currentLevel + 1]) + ); + } else if (b instanceof ResourceBuilding) { + ((ResourceBuilding) b).upgrade( + (b instanceof IronMine) ? (ResourceStages.ironStages[currentLevel + 1]) : + (b instanceof SaulGoodMine) ? (ResourceStages.goldStages[currentLevel + 1]) : + (ResourceStages.woodStages[currentLevel + 1]) + ); + } else { + b.upgrade(VillageHallStages.villageStages[currentLevel + 1]); + } + } else return false; + + return true; + } + + public boolean upgradeInhabitant(int inhabitantIndex) { + + if (inhabitantIndex >= inhabitants.size()) return false; + + Inhabitant i = inhabitants.get(inhabitantIndex); + + int currentLevel = i.getLevel(); + CasaDeNarino hall = getTownHall(); + + if (currentLevel >= 2 || hall.getCurrentGold() < 5) return false; + + i.setLevel(++currentLevel); + hall.addGold(-5); + + if (i instanceof Infantry) { + ((Infantry) i).setHealth(((Infantry) i).getHealth() + 1); + ((Infantry) i).setDamage(((Infantry) i).getDamage() + 1); + ((Infantry) i).setRange(((Infantry) i).getRange() + 1); + } else if (i instanceof Collector) { + ((Collector) i).setCollectionRate(((Collector) i).getCollectionRate() + 1); + } + + return true; + } + + public boolean train(Inhabitant i) { + CasaDeNarino hall = getTownHall(); + int goldCost = i.getCost(); + + if (hall.getCurrentGold() >= goldCost) { + if(!hall.addGold(-goldCost)) + throw new RuntimeException("Unable to subtract gold despite valid check!"); + inhabitants.add(i); + return true; + } else return false; + } + + public int getGuardTime() { + return guardTime; + } + + public void setGuardTime(int gTime) { + this.guardTime = gTime; + } + + public CasaDeNarino getTownHall(){ + return townHall; + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Archer.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Archer.java new file mode 100644 index 0000000..1c2a5c6 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Archer.java @@ -0,0 +1,38 @@ +package ca.cosc3p91.a4.gameobjects; + +public class Archer extends Infantry { + + static int cost = 4; + + private int lvl = 0; + + public Archer() { + super(90, 2, 10); + } + + @Override + public void move(Tile t) { + + } + + @Override + public void getPosition() { + + } + + @Override + public int getLevel() { + return lvl; + } + + @Override + public int getCost() { + return cost; + } + + @Override + public void setLevel(int level) { + lvl = level; + } + +} \ No newline at end of file diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ArcherTower.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ArcherTower.java new file mode 100644 index 0000000..b166412 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ArcherTower.java @@ -0,0 +1,14 @@ +package ca.cosc3p91.a4.gameobjects; + +public class ArcherTower extends DefenseBuilding { + + public ArcherTower() { + setLevel(1); + upgrade(DefenseStages.archerTowerStages[0]); + } + + @Override + public Stage getUpgradeStage() { + return DefenseStages.archerTowerStages[getLevel()+1]; + } +} \ No newline at end of file diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Building.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Building.java new file mode 100644 index 0000000..c6e4019 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Building.java @@ -0,0 +1,73 @@ +package ca.cosc3p91.a4.gameobjects; + +import java.io.Serializable; +import java.util.ArrayList; + +public abstract class Building implements Serializable { + + // members + private int level; + private int health; + + private Stage stage; + + private int goldCost; + private int ironCost; + private int woodCost; + + private int buildTime; + + public ArrayList tiles = new ArrayList<>(); + public ArrayList inhabitants = new ArrayList<>(); + + // functions + + public int getLevel() { + return level; + } + + public int getHealth() { + return health; + } + + public int getCost(String type) { + return (type.equals("gold")) ? (goldCost) : + (type.equals("iron")) ? (ironCost) : woodCost; + } + + public Stage getStage() { + return stage; + } + + public abstract Stage getUpgradeStage(); + + public void setLevel(int level) { + this.level = level; + } + + public void setHealth(int health) { + this.health = health; + } + + public void setStage(Stage stage) { + this.stage = stage; + } + + public void addInhabitant(Inhabitant newMember) { + inhabitants.add(newMember); + // newMember.setBuilding(this); + } + + public void upgrade(Stage stage) { + this.stage = stage; + this.health += stage.dHealth; + // evil hack + String name = stage.getClass().getSimpleName(); + this.level = Integer.parseInt(name.charAt(name.length()-1) + "") - 1; + // interact with the timer regarding Upgrade time + } + + public int getBuildTime() { + return buildTime; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Cannon.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Cannon.java new file mode 100644 index 0000000..98dcb0b --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Cannon.java @@ -0,0 +1,14 @@ +package ca.cosc3p91.a4.gameobjects; + +public class Cannon extends DefenseBuilding { + + public Cannon() { + setLevel(1); + upgrade(DefenseStages.cannonStages[0]); + } + + @Override + public Stage getUpgradeStage() { + return DefenseStages.cannonStages[getLevel()+1]; + } +} \ No newline at end of file diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/CasaDeNarino.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/CasaDeNarino.java new file mode 100644 index 0000000..c359934 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/CasaDeNarino.java @@ -0,0 +1,79 @@ +package ca.cosc3p91.a4.gameobjects; + +public class CasaDeNarino extends Building { + + private int goldCapacity = 0; + private int ironCapacity = 0; + private int woodCapacity = 0; + + private int currentGold = 0; + private int currentIron = 0; + private int currentWood = 50; + + public CasaDeNarino(int lvl, VillageStage baseStage) { + setLevel(lvl); + upgrade(baseStage); + } + + @Override + public Stage getUpgradeStage() { + return VillageHallStages.villageStages[getLevel()+1]; + } + + public void upgrade(VillageStage stage) { + super.upgrade(stage); + this.goldCapacity += stage.getGoldCapacityIncrease(); + this.ironCapacity += stage.getIronCapacityIncrease(); + this.woodCapacity += stage.getWoodCapacityIncrease(); + } + + + public int getGoldCapacity() { + return goldCapacity; + } + + public int getIronCapacity() { + return ironCapacity; + } + + public int getWoodCapacity() { + return woodCapacity; + } + + public int getCurrentGold() { + return currentGold; + } + + public int getCurrentIron() { + return currentIron; + } + + public int getCurrentWood() {return currentWood;} + + public boolean addGold(int amount) { + int newGold = this.currentGold + amount; + if (newGold <= goldCapacity && this.currentGold + amount >= 0){ + this.currentGold += amount; + return true; + } + return false; + } + + public boolean addIron(int amount) { + int newIron = this.currentIron + amount; + if (newIron <= ironCapacity && newIron >= 0) { + this.currentIron += amount; + return true; + } + return false; + } + + public boolean addWood(int amount) { + int newWood = this.currentWood + amount; + if (newWood <= woodCapacity && newWood >= 0) { + this.currentWood += amount; + return true; + } + return false; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Catapult.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Catapult.java new file mode 100644 index 0000000..1976916 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Catapult.java @@ -0,0 +1,37 @@ +package ca.cosc3p91.a4.gameobjects; + +public class Catapult extends Infantry { + + static int cost = 6; + + private int lvl = 0; + + public Catapult() { + super(80, 12, 12); + } + + @Override + public void move(Tile t) { + + } + + @Override + public void getPosition() { + + } + + @Override + public int getLevel() { + return lvl; + } + + @Override + public int getCost() { + return cost; + } + + @Override + public void setLevel(int level) { + lvl = level; + } +} \ No newline at end of file diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Collector.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Collector.java new file mode 100644 index 0000000..a9ace15 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Collector.java @@ -0,0 +1,43 @@ +package ca.cosc3p91.a4.gameobjects; + +public class Collector implements Inhabitant { + + private int averageCollectionRate; + + static int cost = 2; + + private int lvl = 0; + + public int getCollectionRate() { + return averageCollectionRate; + } + + public void setCollectionRate(int rate) { + averageCollectionRate = rate; + } + + @Override + public void move(Tile t) { + + } + + @Override + public void getPosition() { + + } + + @Override + public int getLevel() { + return lvl; + } + + @Override + public int getCost() { + return cost; + } + + @Override + public void setLevel(int level) { + lvl = level; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/DefenseBuilding.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/DefenseBuilding.java new file mode 100644 index 0000000..e7f9a6a --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/DefenseBuilding.java @@ -0,0 +1,22 @@ +package ca.cosc3p91.a4.gameobjects; + +public abstract class DefenseBuilding extends Building { + + private int damage = 0; + private int range = 0; + + public void upgrade(DefenseStage stage) { + super.upgrade(stage); + this.damage += stage.getDamageChange(); + this.range += stage.getRangeChange(); + } + + public void attack(Infantry attacker) { + + } + + public int getDamage(){ + return damage; + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/DefenseStage.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/DefenseStage.java new file mode 100644 index 0000000..661b4bb --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/DefenseStage.java @@ -0,0 +1,26 @@ +package ca.cosc3p91.a4.gameobjects; + +import ca.cosc3p91.a4.util.Time; + +class DefenseStage extends Stage { + + protected int dDamage; + + protected int dRange; + + public DefenseStage(int dHealth, int goldCost, int requiredVillageLevel, Time upgradeTime, int ironCost, int woodCost, + int damageIncrease, int rangeIncrease) { + super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost); + this.dDamage = damageIncrease; + this.dRange = rangeIncrease; + } + + public int getDamageChange() { + return dDamage; + } + + public int getRangeChange() { + return dRange; + } + +} \ No newline at end of file diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/DefenseStages.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/DefenseStages.java new file mode 100644 index 0000000..235e2ac --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/DefenseStages.java @@ -0,0 +1,46 @@ +package ca.cosc3p91.a4.gameobjects; + +import ca.cosc3p91.a4.util.Time; + +public class DefenseStages { + + public static class ArcherTowerStage1 extends DefenseStage { + public ArcherTowerStage1() { + super(100, 0, 0, new Time().offsetMinutes(1), 25, 75, 4,6); + } + } + + public static class ArcherTowerStage2 extends DefenseStage { + public ArcherTowerStage2() { + super(150, 50, 1, new Time().offsetMinutes(15), 25, 200, 8,8); + } + } + + public static class ArcherTowerStage3 extends DefenseStage { + public ArcherTowerStage3() { + super(200, 100, 2, new Time().offsetHours(1), 50, 300, 12,12); + } + } + + public static class CannonStage1 extends DefenseStage { + public CannonStage1() { + super(125, 0, 0, new Time().offsetMinutes(2), 100, 25, 8,4); + } + } + + public static class CannonStage2 extends DefenseStage { + public CannonStage2() { + super(175, 50, 1, new Time().offsetMinutes(20), 125, 25, 12,6); + } + } + + public static class CannonStage3 extends DefenseStage { + public CannonStage3() { + super(225, 100, 2, new Time().offsetHours(1), 200, 50, 14,8); + } + } + + public static DefenseStage[] archerTowerStages = {new DefenseStages.ArcherTowerStage1(), new DefenseStages.ArcherTowerStage2(), new DefenseStages.ArcherTowerStage3()}; + public static DefenseStage[] cannonStages = {new DefenseStages.CannonStage1(), new DefenseStages.CannonStage2(), new DefenseStages.CannonStage3()}; + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Farm.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Farm.java new file mode 100644 index 0000000..7c236a3 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Farm.java @@ -0,0 +1,28 @@ +package ca.cosc3p91.a4.gameobjects; + +public class Farm extends ResourceBuilding { + + public Farm(int lvl, ResourceStage baseStage) { + setLevel(lvl); + upgrade(baseStage); + } + + public int getPopulationContribution() { + return getHarvestRate(); + } + + @Override + protected ResourceHarvestHandler getHarvestHandler() { + return hall -> {}; + } + + @Override + public String getResource() { + return "UNUSED"; + } + + @Override + public Stage getUpgradeStage() { + return ResourceStages.goldStages[getLevel()+1]; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Infantry.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Infantry.java new file mode 100644 index 0000000..7d4cadd --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Infantry.java @@ -0,0 +1,43 @@ +package ca.cosc3p91.a4.gameobjects; + +public abstract class Infantry implements Inhabitant { + + private int health; + + private int damage; + + private int range; + + public Infantry(int hitPoints, int damage, int range) { + this.health = hitPoints; + this.damage = damage; + this.range = range; + } + + public void attack(Building b) { + } + + public int getHealth() { + return health; + } + + public int getDamage() { + return damage; + } + + public int getRange() { + return range; + } + + public void setHealth(int health) { + this.health = health; + } + + public void setDamage(int damage) { + this.damage = damage; + } + + public void setRange(int range) { + this.range = range; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Inhabitant.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Inhabitant.java new file mode 100644 index 0000000..95f51ab --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Inhabitant.java @@ -0,0 +1,17 @@ +package ca.cosc3p91.a4.gameobjects; + +import java.io.Serializable; + +public interface Inhabitant extends Serializable { + + int lvl = 0; + + void move(Tile t); + + void getPosition(); + + int getLevel(); + void setLevel(int level); + int getCost(); + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/IronMine.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/IronMine.java new file mode 100644 index 0000000..3e88b06 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/IronMine.java @@ -0,0 +1,25 @@ +package ca.cosc3p91.a4.gameobjects; + +public class IronMine extends ResourceBuilding { + + public static String resource = "iron"; + + public IronMine(ResourceStage baseStage) { + upgrade(baseStage); + } + + @Override + protected ResourceHarvestHandler getHarvestHandler() { + return hall -> hall.addIron(getHarvestRate()); + } + + @Override + public String getResource() { + return resource; + } + + @Override + public Stage getUpgradeStage() { + return ResourceStages.ironStages[getLevel()+1]; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Knight.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Knight.java new file mode 100644 index 0000000..3a7d4e4 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Knight.java @@ -0,0 +1,37 @@ +package ca.cosc3p91.a4.gameobjects; + +public class Knight extends Infantry { + + static int cost = 6; + + private int lvl = 0; + + public Knight() { + super(150, 6, 6); + } + + @Override + public void move(Tile t) { + + } + + @Override + public void getPosition() { + + } + + @Override + public int getLevel() { + return lvl; + } + + @Override + public int getCost() { + return cost; + } + + @Override + public void setLevel(int level) { + lvl = level; + } +} \ No newline at end of file diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/LumberMine.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/LumberMine.java new file mode 100644 index 0000000..412aba5 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/LumberMine.java @@ -0,0 +1,25 @@ +package ca.cosc3p91.a4.gameobjects; + +public class LumberMine extends ResourceBuilding { + + public static String resource = "wood"; + + public LumberMine(ResourceStage baseStage) { + upgrade(baseStage); + } + + @Override + protected ResourceHarvestHandler getHarvestHandler() { + return hall -> hall.addWood(getHarvestRate()); + } + + @Override + public String getResource() { + return resource; + } + + @Override + public Stage getUpgradeStage() { + return ResourceStages.woodStages[getLevel()+1]; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ResourceBuilding.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ResourceBuilding.java new file mode 100644 index 0000000..37680f4 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ResourceBuilding.java @@ -0,0 +1,42 @@ +package ca.cosc3p91.a4.gameobjects; + +import ca.cosc3p91.a4.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); + + 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 void update(CasaDeNarino hall){ + if (nextHarvestTime.occurred()){ + getHarvestHandler().harvest(hall); + nextHarvestTime = Time.getTime().offsetTime(harvestMinTime); + } + } + + protected abstract ResourceHarvestHandler getHarvestHandler(); + + public int getHarvestRate(){ + return harvest_rate; + } + + public abstract String getResource(); + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ResourceStage.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ResourceStage.java new file mode 100644 index 0000000..db02f18 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ResourceStage.java @@ -0,0 +1,19 @@ +package ca.cosc3p91.a4.gameobjects; + +import ca.cosc3p91.a4.util.Time; + +public class ResourceStage extends Stage { + + protected int harvestRateIncrease; + + 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; + } + + public int getHarvestRateIncrease() { + return harvestRateIncrease; + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ResourceStages.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ResourceStages.java new file mode 100644 index 0000000..8e33d1e --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/ResourceStages.java @@ -0,0 +1,65 @@ +package ca.cosc3p91.a4.gameobjects; + +import ca.cosc3p91.a4.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); + } + } + + public static ResourceStage[] goldStages = {new GoldStage1(), new GoldStage2(), new GoldStage3()}; + public static ResourceStage[] ironStages = {new IronStage1(), new IronStage2(), new IronStage3()}; + public static ResourceStage[] woodStages = {new WoodStage1(), new WoodStage2(), new WoodStage3()}; + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/SaulGoodMine.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/SaulGoodMine.java new file mode 100644 index 0000000..a7c8d1d --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/SaulGoodMine.java @@ -0,0 +1,25 @@ +package ca.cosc3p91.a4.gameobjects; + +public class SaulGoodMine extends ResourceBuilding { + + public static String resource = "gold"; + + public SaulGoodMine(ResourceStage baseStage) { + upgrade(baseStage); + } + + @Override + protected ResourceHarvestHandler getHarvestHandler() { + return hall -> hall.addGold(getHarvestRate()); + } + + @Override + public String getResource() { + return resource; + } + + @Override + public Stage getUpgradeStage() { + return ResourceStages.goldStages[getLevel()+1]; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Soldier.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Soldier.java new file mode 100644 index 0000000..eb997bd --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Soldier.java @@ -0,0 +1,37 @@ +package ca.cosc3p91.a4.gameobjects; + +public class Soldier extends Infantry { + + static int cost = 4; + + int lvl = 0; + + public Soldier() { + super(100, 4, 4); + } + + @Override + public void move(Tile t) { + + } + + @Override + public void getPosition() { + + } + + @Override + public int getLevel() { + return lvl; + } + + @Override + public int getCost() { + return cost; + } + + @Override + public void setLevel(int level) { + lvl = level; + } +} \ No newline at end of file diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Stage.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Stage.java new file mode 100644 index 0000000..b554e9c --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Stage.java @@ -0,0 +1,47 @@ +package ca.cosc3p91.a4.gameobjects; + +import ca.cosc3p91.a4.util.Time; + +import java.io.Serializable; + +public abstract class Stage implements Serializable { + + protected int dHealth; + + protected int goldCost; + + protected int requiredVillageLevel; + + protected Time upgradeTime; + + protected int ironCost; + + protected 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; + this.upgradeTime = upgradeTime; + this.ironCost = ironCost; + this.woodCost = woodCost; + } + + public int getHealthChange() { + return dHealth; + } + + public int getCost(String type) { + return (type.equals("gold")) ? (goldCost) : + (type.equals("iron")) ? (ironCost) : woodCost; + } + + public int getRequiredVillageLevel() { + return requiredVillageLevel; + } + + public Time getUpgradeTime() { + return upgradeTime; + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Tile.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Tile.java new file mode 100644 index 0000000..e4078e9 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Tile.java @@ -0,0 +1,9 @@ +package ca.cosc3p91.a4.gameobjects; + +public class Tile { + + public int x; + + public int y; + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/VillageHallStages.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/VillageHallStages.java new file mode 100644 index 0000000..dfd3eab --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/VillageHallStages.java @@ -0,0 +1,30 @@ +package ca.cosc3p91.a4.gameobjects; + +import ca.cosc3p91.a4.util.Time; + +public class VillageHallStages { + + public static class VillageStage1 extends VillageStage { + public VillageStage1() { + super(100, 0, 0, new Time(), 0, + 0, 1000, 2500, 5000); + } + } + + public static class VillageStage2 extends VillageStage { + public VillageStage2() { + super(550, 1000, 0, new Time().offsetHours(2), 2500, + 5000, 2500, 5000, 10000); + } + } + + public static class VillageStage3 extends VillageStage { + public VillageStage3() { + super(550, 2500, 0, new Time().offsetHours(2), 5000, + 10000, 5000, 7500, 15000); + } + } + + public static VillageStage[] villageStages = {new VillageStage1(), new VillageStage2(), new VillageStage3()}; + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/VillageStage.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/VillageStage.java new file mode 100644 index 0000000..248d612 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/VillageStage.java @@ -0,0 +1,33 @@ +package ca.cosc3p91.a4.gameobjects; + +import ca.cosc3p91.a4.util.Time; + +public class VillageStage extends Stage { + + protected int goldCapacityIncrease; + + protected int ironCapacityIncrease; + + protected int woodCapacityIncrease; + + 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; + this.ironCapacityIncrease = ironCapIncrease; + this.woodCapacityIncrease = woodCapIncrease; + } + + public int getGoldCapacityIncrease() { + return goldCapacityIncrease; + } + + public int getIronCapacityIncrease() { + return ironCapacityIncrease; + } + + public int getWoodCapacityIncrease() { + return woodCapacityIncrease; + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Worker.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Worker.java new file mode 100644 index 0000000..4230bcb --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/Worker.java @@ -0,0 +1,43 @@ +package ca.cosc3p91.a4.gameobjects; + +public class Worker implements Inhabitant { + + private boolean currentlyBuilding; + + static int cost = 2; + + private int lvl = 0; + + public void set_IsBuilding(boolean state) { + currentlyBuilding = state; + } + + public boolean isCurrentlyBuilding() { + return currentlyBuilding; + } + + @Override + public void move(Tile t) { + + } + + @Override + public void getPosition() { + + } + + @Override + public int getLevel() { + return lvl; + } + + @Override + public int getCost() { + return cost; + } + + @Override + public void setLevel(int level) { + lvl = level; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/factory/BuildingFactory.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/factory/BuildingFactory.java new file mode 100644 index 0000000..1fc283d --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/factory/BuildingFactory.java @@ -0,0 +1,25 @@ +package ca.cosc3p91.a4.gameobjects.factory; + +import ca.cosc3p91.a4.gameobjects.*; +import ca.cosc3p91.a4.util.Util; + +public class BuildingFactory { + public Building getBuilding(String buildingName) { + buildingName = buildingName.toLowerCase(); + char c = Util.getFirstChar(buildingName); + + if (buildingName.contains("gold") || buildingName.contains("good") || c == 'g') { + return new SaulGoodMine(ResourceStages.goldStages[0]); + } else if (buildingName.contains("iron") || c == 'i') { + return new IronMine(ResourceStages.ironStages[0]); + } else if (buildingName.contains("wood") || buildingName.contains("lumber") || c == 'w' || c == 'l') { + return new LumberMine(ResourceStages.woodStages[0]); + } else if (buildingName.contains("archer") || c == 'a') { + return new ArcherTower(); + } else if (buildingName.contains("can") || c == 'c') { + return new Cannon(); + } + + return null; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/gameobjects/factory/InhabitantFactory.java b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/factory/InhabitantFactory.java new file mode 100644 index 0000000..6b4aacc --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/gameobjects/factory/InhabitantFactory.java @@ -0,0 +1,27 @@ +package ca.cosc3p91.a4.gameobjects.factory; + +import ca.cosc3p91.a4.gameobjects.*; +import ca.cosc3p91.a4.util.Util; + +public class InhabitantFactory { + public Inhabitant getInhabitant(String inhabitantName) { + inhabitantName = inhabitantName.toLowerCase(); + char c = Util.getFirstChar(inhabitantName); + + if (inhabitantName.contains("soldier") || c == 's') { + return new Soldier(); + } else if (inhabitantName.contains("knight") || c == 'k') { + return new Knight(); + } else if (inhabitantName.contains("work") || c == 'w') { + return new Worker(); + } else if (inhabitantName.contains("collect") || c == 'c') { + return new Collector(); + } else if (inhabitantName.contains("cat")) { + return new Catapult(); + } else if (inhabitantName.contains("arch") || c == 'a') { + return new Archer(); + } + + return null; + } +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/player/Player.java b/Assignment 4/src/ca/cosc3p91/a4/player/Player.java new file mode 100644 index 0000000..3b16dfc --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/player/Player.java @@ -0,0 +1,6 @@ +package ca.cosc3p91.a4.player; + +public class Player { + + +} \ No newline at end of file diff --git a/Assignment 4/src/ca/cosc3p91/a4/userinterface/GameDisplay.java b/Assignment 4/src/ca/cosc3p91/a4/userinterface/GameDisplay.java new file mode 100644 index 0000000..19e06fd --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/userinterface/GameDisplay.java @@ -0,0 +1,90 @@ +package ca.cosc3p91.a4.userinterface; + +import ca.cosc3p91.a4.game.Map; +import ca.cosc3p91.a4.gameobjects.Building; +import ca.cosc3p91.a4.gameobjects.Inhabitant; +import ca.cosc3p91.a4.util.Print; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; + +public class GameDisplay { + private BufferedReader reader; + private Scanner scanner; + private String input; + + public GameDisplay() { + reader = new BufferedReader(new InputStreamReader(System.in)); + scanner = new Scanner(reader); + } + + public String nextInput() throws IOException { + if (reader.ready()) { + return (input = scanner.nextLine()); + } else return null; + } + + public void printLastInput() { + System.out.println("\nYour Input: "); + System.out.println("\t->" + input + '\n'); + } + + public void printVillageState(Map map, String displayName) { + Print resourcesPrinter = new Print(displayName, 2); + + resourcesPrinter.addColumn(new Print.Column("Resource Type")); + resourcesPrinter.addColumn(new Print.Column("Max")); + resourcesPrinter.addColumn(new Print.Column("Amount")); + + resourcesPrinter.addRow(new Print.Row( + "Wood", + Integer.toString(map.getTownHall().getWoodCapacity()), + Integer.toString(map.getTownHall().getCurrentWood()))); + + resourcesPrinter.addRow(new Print.Row( + "Iron", + Integer.toString(map.getTownHall().getIronCapacity()), + Integer.toString(map.getTownHall().getCurrentIron()))); + + resourcesPrinter.addRow(new Print.Row( + "Gold", + Integer.toString(map.getTownHall().getGoldCapacity()), + Integer.toString(map.getTownHall().getCurrentGold()))); + + Print.print(resourcesPrinter.createTable(true, false, true)); + + Print buildingPrinter = new Print("Village Buildings", 2, resourcesPrinter.getWidth()); + buildingPrinter.addColumn(new Print.Column("Name")); + buildingPrinter.addColumn(new Print.Column("Level")); + buildingPrinter.addColumn(new Print.Column("Health")); + + for (Building b : map.contains) + buildingPrinter.addRow(new Print.Row(b.getClass().getSimpleName(), + Integer.toString(b.getLevel() + 1), + Integer.toString(b.getHealth()))); + + Print.print(buildingPrinter.createTable(true, false, true)); + + Print inhabs = new Print("Village Inhabitants", 2, buildingPrinter.getWidth()); + inhabs.addColumn(new Print.Column("Name")); + inhabs.addColumn(new Print.Column("Level")); + + for (Inhabitant i : map.inhabitants) + inhabs.addRow(new Print.Row(i.getClass().getSimpleName(), Integer.toString(i.getLevel() + 1))); + + Print.print(inhabs.createTable(true, true, true)); + } + + public void printGameMenu() { + System.out.println("\n~ Player Options:\n" + + "1. Build {command: '1 '}\n" + + "2. Train inhabitants {command: '2 '}\n"+ + "3. Upgrade {command: '3 i'} / {command: '3 b'}\n"+ + "4. Explore\n"+ + "5. Print Village Stats\n"+ + "6. Quit\n" + + "7. Attack last explored\n"); + } +} \ No newline at end of file diff --git a/Assignment 4/src/ca/cosc3p91/a4/util/ChallengeAdapter.java b/Assignment 4/src/ca/cosc3p91/a4/util/ChallengeAdapter.java new file mode 100644 index 0000000..d1c47bf --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/util/ChallengeAdapter.java @@ -0,0 +1,143 @@ +package ca.cosc3p91.a4.util; + +import ChallengeDecision.*; +import ca.cosc3p91.a4.game.Map; +import ca.cosc3p91.a4.gameobjects.*; + +import java.util.ArrayList; +import java.util.List; + +public class ChallengeAdapter { + + private static class MapChallengeConverter { + private final Map map; + public MapChallengeConverter(Map map){ + this.map = map; + } + + public List> getAttackers(){ + List> entityAttackList = new ArrayList<>(); + + map.inhabitants.stream() + .filter(i -> i instanceof Infantry) + .map(i -> (Infantry) i) + .forEach(i -> { + entityAttackList.add(new ChallengeAttack<>((double) i.getDamage(), (double) i.getHealth())); + }); + + return entityAttackList; + } + + public List> getDefenders(){ + List> entityDefenseList = new ArrayList<>(); + + map.contains.stream() + .filter(b -> b instanceof DefenseBuilding) + .map(b -> (DefenseBuilding) b) + .forEach(d -> { + entityDefenseList.add(new ChallengeDefense<>((double) d.getDamage(), (double) d.getHealth())); + }); + + return entityDefenseList; + } + + public List> getResources(String type){ + List> entityResourceList = new ArrayList<>(); + + CasaDeNarino th = map.getTownHall(); + + int resourceCount; + int thResourceCount = + type.equals(SaulGoodMine.resource) ? th.getCurrentGold() + : type.equals(IronMine.resource) + ? th.getCurrentIron() : th.getCurrentWood(); + + resourceCount = (int) map.contains.stream() + .filter(b -> b instanceof ResourceBuilding).map(b -> (ResourceBuilding) b) + .filter(r -> r.getResource().equals(type)) + .count(); + + map.contains.stream() + .filter(b -> b instanceof ResourceBuilding) + .map(b -> (ResourceBuilding) b) + .filter(r -> r.getResource().equals(type)) + .forEach((r) -> { + entityResourceList.add( + new ChallengeResource<>( + (double) thResourceCount / (double) resourceCount, + (double) r.getHealth()) + ); + }); + + return entityResourceList; + } + } + + private final Map map; + + public ChallengeAdapter(Map map){ + this.map = map; + } + + public void attack(Map enemy){ + MapChallengeConverter enemyMap = new MapChallengeConverter(enemy); + MapChallengeConverter ourMap = new MapChallengeConverter(this.map); + + List> ourAttackers = ourMap.getAttackers(); + // not needed + List> ourDefenders = ourMap.getDefenders(); + + ChallengeEntitySet ourSet = new ChallengeEntitySet<>(); + ourSet.setEntityAttackList(ourAttackers); + ourSet.setEntityDefenseList(ourDefenders); + + List> enemyDefenders = enemyMap.getDefenders(); + + List> enemyGold = enemyMap.getResources(SaulGoodMine.resource); + List> enemyIron = enemyMap.getResources(IronMine.resource); + List> enemyWood = enemyMap.getResources(LumberMine.resource); + + // split is required because challengeResource lacks any resource specifier + ChallengeEntitySet enemyGoldSet = new ChallengeEntitySet<>(); + ChallengeEntitySet enemyIronSet = new ChallengeEntitySet<>(); + ChallengeEntitySet enemyWoodSet = new ChallengeEntitySet<>(); + + enemyGoldSet.setEntityDefenseList(enemyDefenders); + enemyIronSet.setEntityDefenseList(enemyDefenders); + enemyWoodSet.setEntityDefenseList(enemyDefenders); + + enemyGoldSet.setEntityResourceList(enemyGold); + enemyIronSet.setEntityResourceList(enemyIron); + enemyWoodSet.setEntityResourceList(enemyWood); + + ChallengeResult goldResults = Arbitrer.challengeDecide(ourSet, enemyGoldSet); + ChallengeResult ironResults = Arbitrer.challengeDecide(ourSet, enemyIronSet); + ChallengeResult woodResults = Arbitrer.challengeDecide(ourSet, enemyWoodSet); + + // if any fail to attack we need to pretend like it was one big attack that failed + if (!goldResults.getChallengeWon() || !ironResults.getChallengeWon() || !woodResults.getChallengeWon()) + return; + + System.out.println("We won gold: "); + goldResults.print(); + System.out.println("We won iron: "); + ironResults.print(); + System.out.println("We won wood: "); + woodResults.print(); + + CasaDeNarino th = map.getTownHall(); + + goldResults.getLoot().forEach(r -> { + th.addGold((int)r.getProperty().doubleValue()); + }); + + ironResults.getLoot().forEach(r -> { + th.addIron((int)r.getProperty().doubleValue()); + }); + + woodResults.getLoot().forEach(r -> { + th.addWood((int)r.getProperty().doubleValue()); + }); + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/util/PacketTable.java b/Assignment 4/src/ca/cosc3p91/a4/util/PacketTable.java new file mode 100644 index 0000000..6a77770 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/util/PacketTable.java @@ -0,0 +1,7 @@ +package ca.cosc3p91.a4.util; + +public class PacketTable { + + + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/util/Print.java b/Assignment 4/src/ca/cosc3p91/a4/util/Print.java new file mode 100644 index 0000000..4211364 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/util/Print.java @@ -0,0 +1,249 @@ +package ca.cosc3p91.a4.util; + +import java.util.ArrayList; +import java.util.Arrays; + +/** + * Ported from blt::TableFormatter (C++) + * https://github.com/Tri11Paragon/BLT/ + */ +public class Print { + + public static class Row { + private final ArrayList values; + + public Row(ArrayList row) { + this.values = row; + } + + public Row() { + this.values = new ArrayList<>(); + } + + public Row(String... values){ + this(); + this.values.addAll(Arrays.asList(values)); + } + + public void add(String value) { + values.add(value); + } + } + + public static class Column { + private String columnName; + private long maxColumnLength = 0; + + public Column(String columnName) { + this.columnName = columnName; + } + } + + private final ArrayList rows = new ArrayList<>(); + private final ArrayList columns = new ArrayList<>(); + + private final String tableName; + private final int columnPadding; + private int width; + private final int targetWidth; + + public Print(String tableName, int columnPadding, int targetWidth) { + this.tableName = tableName; + this.columnPadding = columnPadding; + this.targetWidth = targetWidth; + } + + public Print(String tableName, int columnPadding){this(tableName, columnPadding, -1);} + + public Print(String tableName){this(tableName, 2);} + + public Print() { + this(""); + } + + private String createPadding(int amount) { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < amount; i++) { + builder.append(' '); + } + return builder.toString(); + } + + private String generateTopSelector(long size) { + long sizeOfName = tableName.isEmpty() ? 0 : tableName.length() + 4; + long sizeNameRemoved = size - sizeOfName; + + StringBuilder halfWidthLeftSeparator = new StringBuilder(); + StringBuilder halfWidthRightSeparator = new StringBuilder(); + + long sizeNameFloor = (long) Math.floor((double) sizeNameRemoved / 2.0); + long sizeNameCeil = (long) Math.ceil((double) sizeNameRemoved / 2.0); + + halfWidthLeftSeparator.append('+'); + + for (int i = 0; i < sizeNameFloor - 1; i++) + halfWidthLeftSeparator.append('-'); + for (int i = 0; i < sizeNameCeil - 1; i++) + halfWidthRightSeparator.append('-'); + + halfWidthRightSeparator.append('+'); + + StringBuilder separator = new StringBuilder(); + separator.append(halfWidthLeftSeparator.toString()); + if (sizeOfName != 0) { + separator.append("{ "); + separator.append(tableName); + separator.append(" }"); + } + separator.append(halfWidthRightSeparator); + return separator.toString(); + } + + private String generateColumnHeader() { + updateColumnLengths(); + StringBuilder header = new StringBuilder(); + header.append('|'); + + for (int i = 0; i < columns.size(); i++) { + Column column = columns.get(i); + double columnPaddingLength = ((int) (column.maxColumnLength) - (int) (column.columnName.length())) / 2.0; + header.append(createPadding((int) (columnPadding + (int) Math.floor(columnPaddingLength)))); + + header.append(column.columnName); + + header.append(createPadding((int) (columnPadding + (int) Math.ceil(columnPaddingLength)))); + if (i < columns.size() - 1) + header.append('|'); + } + header.append('|'); + + return header.toString(); + } + + private String generateSeparator(long size) { + int nextIndex = 0; + int currentColumnIndex = 0; + StringBuilder wholeWidthSeparator = new StringBuilder(); + for (int i = 0; i < size; i++) { + if (i == nextIndex) { + //System.out.println(currentColumnIndex + " " + nextIndex + " " + size); + int currentColumnSize = (int) (columns.get(currentColumnIndex++).maxColumnLength + columnPadding * 2); + nextIndex += currentColumnSize + 1; + wholeWidthSeparator.append('+'); + } else + wholeWidthSeparator.append('-'); + } + wholeWidthSeparator.append('+'); + return wholeWidthSeparator.toString(); + } + + private void updateColumnLengths() { + for (int i = 0; i < columns.size(); i++) { + Column column = columns.get(i); + column.maxColumnLength = column.columnName.length(); + for (Row row : rows) { + column.maxColumnLength = Math.max(column.maxColumnLength, row.values.get(i).length()); + } + } + } + + public long columnSize(Column column) { + return column.columnName.length() + columnPadding * 2L; + } + + public Print addColumn(Column column) { + columns.add(column); + return this; + } + + public Print addRow(Row row) { + if (row.values.size() > columns.size()) + throw new RuntimeException("Unable to create row with more values than columns!"); + if (row.values.size() < columns.size()) + for (int i = row.values.size(); i < columns.size(); i++) + row.values.add(""); + rows.add(row); + return this; + } + + public Print addRow(ArrayList row) { + return addRow(new Row(row)); + } + + public ArrayList createTable(boolean top, boolean bottom, boolean separators) { + String header = generateColumnHeader(); + String topSeparator = generateTopSelector(header.length()); + String lineSeparator = generateSeparator(header.length() - 1); + + if (targetWidth > 0) { + int diff = targetWidth - header.length(); + + if (diff > 0) { + + int left = (int) Math.floor(diff / 2.0); + int right = (int) Math.ceil(diff / 2.0); + + int leftleft = (int) Math.floor(left / 2.0); + int leftright = (int) Math.ceil(left / 2.0); + + int rightleft = (int) Math.floor(right / 2.0); + int rightright = (int) Math.ceil(right / 2.0); + + columns.get(0).columnName = createPadding(leftleft) + columns.get(0).columnName + createPadding(leftright); + columns.get(columns.size() - 1).columnName = createPadding(rightleft) + columns.get(columns.size() - 1).columnName + createPadding(rightright); + + header = generateColumnHeader(); + topSeparator = generateTopSelector(header.length()); + lineSeparator = generateSeparator(header.length() - 1); + } + } + + width = header.length(); + + ArrayList lines = new ArrayList<>(); + + if (top) + lines.add(topSeparator); + + lines.add(header); + lines.add(lineSeparator); + + for (Row row : rows) { + StringBuilder rowLine = new StringBuilder(); + rowLine.append('|'); + for (int i = 0; i < row.values.size(); i++) { + String value = row.values.get(i); + Column column = columns.get(i); + int spaceLeft = (int) (column.maxColumnLength - value.length()); + rowLine.append(createPadding((int) Math.floor(spaceLeft / 2.0) + columnPadding)); + rowLine.append(value); + rowLine.append(createPadding((int) Math.ceil(spaceLeft / 2.0) + columnPadding)); + rowLine.append('|'); + } + lines.add(rowLine.toString()); + } + + if (bottom) + lines.add(lineSeparator); + + return lines; + } + + public ArrayList createBox() { + return new ArrayList<>(); + } + + public ArrayList createTable() { + return createTable(true, true, true); + } + + public int getWidth(){ + return width; + } + + public static void print(ArrayList lines) { + for (String line : lines) + System.out.println(line); + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/util/Server.java b/Assignment 4/src/ca/cosc3p91/a4/util/Server.java new file mode 100644 index 0000000..cbe4286 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/util/Server.java @@ -0,0 +1,11 @@ +package ca.cosc3p91.a4.util; + +public class Server { + + public static final int SERVER_PORT = 42069; + + public Server() { + + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/util/Time.java b/Assignment 4/src/ca/cosc3p91/a4/util/Time.java new file mode 100644 index 0000000..04fb156 --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/util/Time.java @@ -0,0 +1,50 @@ +package ca.cosc3p91.a4.util; + +import java.io.Serializable; + +public class Time implements Serializable { + + private long timeSeconds; + + public Time() { + this.timeSeconds = 0; + } + + protected Time(long timeSeconds) { + this.timeSeconds = timeSeconds; + } + + public Time offsetSeconds(long seconds) { + this.timeSeconds += seconds; + return this; + } + + public Time offsetMinutes(long minutes) { + return offsetSeconds(minutes * 60); + } + + public Time offsetHours(long hours) { + return offsetMinutes(hours * 60); + } + + public Time offsetDays(long days) { + return offsetHours(days * 24); + } + + public Time offsetTime(Time time) { + return offsetSeconds(time.timeSeconds); + } + + public long get() { + return timeSeconds; + } + + public boolean occurred() { + return getTime().timeSeconds >= timeSeconds; + } + + public static Time getTime() { + return new Time(System.currentTimeMillis() / 1000); + } + +} diff --git a/Assignment 4/src/ca/cosc3p91/a4/util/Util.java b/Assignment 4/src/ca/cosc3p91/a4/util/Util.java new file mode 100644 index 0000000..140545c --- /dev/null +++ b/Assignment 4/src/ca/cosc3p91/a4/util/Util.java @@ -0,0 +1,22 @@ +package ca.cosc3p91.a4.util; + +import java.util.Random; + +public class Util { + + public static int randomInt(int min, int max, Random random) { + return random.nextInt(max - min) + min; + } + + public static int clamp(int min, int max, int i){ + return Math.min(Math.max(i, min), max); + } + + public static char getFirstChar(String str){ + char c = ' '; + if (str.trim().length() == 1) + c = str.charAt(0); + return c; + } + +} diff --git a/Assignment 4/suggestedSolutionA1.png b/Assignment 4/suggestedSolutionA1.png new file mode 100644 index 0000000..f656bf4 Binary files /dev/null and b/Assignment 4/suggestedSolutionA1.png differ diff --git a/untitled104.iml b/untitled104.iml index af7f350..9613e44 100644 --- a/untitled104.iml +++ b/untitled104.iml @@ -3,7 +3,7 @@ - +