diff --git a/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java b/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java index 1ba887e..05fd90a 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/game/GameEngine.java @@ -5,47 +5,47 @@ import ca.cosc3p91.a2.player.*; public class GameEngine implements Runnable { - private Player player; + private Player player; - private int pillageFactor; + private int pillageFactor; - private int currentTime; + private int currentTime; - public Map map; + public Map map; - public GameEngine () { - player = new Player(); - VillageStage vInitialStage = new VillageStage(100,0,2,30,0, - 0, 12,12,12); - map = new Map(new Village_Hall(1,vInitialStage),30); - } - - public void printState() { - // Print toPrint = new Print("~ Current Village Buildings ~",2); - - System.out.println("In Map:\n"); - System.out.println("\t~ Current Village Buildings ~\n"); - for (Building b : map.contains) { - System.out.println("\t|> "+b.getClass().getSimpleName()+" lvl: "+b.getLevel()+" health: "+b.getHealth()); + public GameEngine() { + player = new Player(); + VillageStage vInitialStage = new VillageStage(100, 0, 2, 30, 0, + 0, 12, 12, 12); + map = new Map(new Village_Hall(1, vInitialStage), 30); } - System.out.println("\n\t~ Current Village Inhabitants ~\n\n"); - for (Inhabitant i : map.inhabitants) { - System.out.println("\t|> "+i.getClass().getSimpleName()+" lvl: "+i.getLevel()); + + public void printState() { + // Print toPrint = new Print("~ Current Village Buildings ~",2); + + System.out.println("In Map:\n"); + System.out.println("\t~ Current Village Buildings ~\n"); + for (Building b : map.contains) { + System.out.println("\t|> " + b.getClass().getSimpleName() + " lvl: " + b.getLevel() + " health: " + b.getHealth()); + } + System.out.println("\n\t~ Current Village Inhabitants ~\n\n"); + for (Inhabitant i : map.inhabitants) { + System.out.println("\t|> " + i.getClass().getSimpleName() + " lvl: " + i.getLevel()); + } } - } - public void attackVillage(Map map) { - } + public void attackVillage(Map map) { + } - public Map generateMap() { - return null; - } + public Map generateMap() { + return null; + } - public void getScore(Map map) { - } + public void getScore(Map map) { + } - @Override - public void run() { + @Override + public void run() { - } + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/game/Map.java b/Assignment 2/src/ca/cosc3p91/a2/game/Map.java index bd7cc4b..fbacf13 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/game/Map.java +++ b/Assignment 2/src/ca/cosc3p91/a2/game/Map.java @@ -7,42 +7,42 @@ import java.util.List; public class Map { - static int MAXSIZE = 400; + static int MAXSIZE = 400; - private Village_Hall townHall; + private Village_Hall townHall; - private int guardTime; + private int guardTime; - public List contains; + public List contains; - public List inhabitants; + public List inhabitants; - public Map (Village_Hall villageHall, int gTime) { - contains = new ArrayList<>(); - inhabitants = new ArrayList<>(); - this.townHall = villageHall; - this.contains.add(villageHall); - this.guardTime = gTime; - } + public Map(Village_Hall villageHall, int gTime) { + contains = new ArrayList<>(); + inhabitants = new ArrayList<>(); + this.townHall = villageHall; + this.contains.add(villageHall); + this.guardTime = gTime; + } - public void move(Infantry i, Tile t) { + public void move(Infantry i, Tile t) { - } + } - public void inRange(Infantry i, Building b) { + public void inRange(Infantry i, Building b) { - } + } - public void build(Tile t, Building b) { - contains.add(b); - } + public void build(Tile t, Building b) { + contains.add(b); + } - public int getGuardTime() { - return guardTime; - } + public int getGuardTime() { + return guardTime; + } - public void setGuardTime(int gTime) { - this.guardTime = gTime; - } + public void setGuardTime(int gTime) { + this.guardTime = gTime; + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Building.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Building.java index 91f5a03..eb7efdc 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Building.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Building.java @@ -4,66 +4,68 @@ import java.util.ArrayList; public abstract class Building { - // members - private int level; - private int health; + // members + private int level; + private int health; - private Stage stage; + private Stage stage; - private int goldCost; - private int ironCost; - private int woodCost; + private int goldCost; + private int ironCost; + private int woodCost; - private int buildTime; + private int buildTime; - public ArrayList tiles = new ArrayList<>(); - public ArrayList inhabitants = new ArrayList<>(); + public ArrayList tiles = new ArrayList<>(); + public ArrayList inhabitants = new ArrayList<>(); - // functions + // functions - public int getLevel() { - return level; - } + public int getLevel() { + return level; + } - public int getHealth() { - return health; - } + public int getHealth() { + return health; + } - public int getCost(String type) { - return (type.equals("gold"))?(goldCost): - (type.equals("iron"))?(ironCost):woodCost; - } + public int getCost(String type) { + return (type.equals("gold")) ? (goldCost) : + (type.equals("iron")) ? (ironCost) : woodCost; + } - public Stage getStage() { - return stage; - } + public Stage getStage() { + return stage; + } - public int getUpgradeCost() { - return 0; - } + public int getUpgradeCost() { + return 0; + } - public void setLevel(int level) { - this.level = level; - } + public void setLevel(int level) { + this.level = level; + } - public void setHealth(int health) { - this.health = health; - } + public void setHealth(int health) { + this.health = health; + } - public void setStage(Stage stage) {this.stage = stage; } + public void setStage(Stage stage) { + this.stage = stage; + } - public void addInhabitant(Inhabitant newMember) { - inhabitants.add(newMember); - // newMember.setBuilding(this); - } + public void addInhabitant(Inhabitant newMember) { + inhabitants.add(newMember); + // newMember.setBuilding(this); + } - public void upgrade(Stage stage) { - this.stage = stage; - this.health += stage.dHealth; - // interact with the timer regarding Upgrade time - } + public void upgrade(Stage stage) { + this.stage = stage; + this.health += stage.dHealth; + // interact with the timer regarding Upgrade time + } - public int getBuildTime() { - return buildTime; - } + public int getBuildTime() { + return buildTime; + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseBuilding.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseBuilding.java index 30b3692..89ae5c2 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseBuilding.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseBuilding.java @@ -2,17 +2,17 @@ package ca.cosc3p91.a2.gameobjects; public class DefenseBuilding extends Building { - private int damage; - private int range; + private int damage; + private int range; - public void upgrade(DefenseStage stage) { - super.upgrade(stage); - this.damage += stage.getDamageChange(); - this.range += stage.getRangeChange(); - } + public void upgrade(DefenseStage stage) { + super.upgrade(stage); + this.damage += stage.getDamageChange(); + this.range += stage.getRangeChange(); + } - public void attack(Infantry attacker) { + public void attack(Infantry attacker) { - } + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStage.java index bc0320c..7686dd7 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/DefenseStage.java @@ -2,23 +2,23 @@ package ca.cosc3p91.a2.gameobjects; class DefenseStage extends Stage { - protected int dDamage; + protected int dDamage; - protected int dRange; + protected int dRange; - public DefenseStage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost, - int damageIncrease, int rangeIncrease) { - super(dHealth,goldCost,requiredVillageLevel,upgradeTime,ironCost,woodCost); - this.dDamage = damageIncrease; - this.dRange = rangeIncrease; - } + public DefenseStage(int dHealth, int goldCost, int requiredVillageLevel, int 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 getDamageChange() { + return dDamage; + } - public int getRangeChange() { - return dRange; - } + public int getRangeChange() { + return dRange; + } } \ No newline at end of file diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java index 66ba7a6..03657fd 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Farm.java @@ -2,10 +2,10 @@ package ca.cosc3p91.a2.gameobjects; public class Farm extends ResourceBuilding { - public Farm (int lvl, ResourceStage baseStage) { - setLevel(lvl); - upgrade(baseStage); - } + public Farm(int lvl, ResourceStage baseStage) { + setLevel(lvl); + upgrade(baseStage); + } public int getPopulationContribution() { return 0; diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Inhabitant.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Inhabitant.java index a4053c1..9818dd2 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Inhabitant.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Inhabitant.java @@ -1,4 +1,5 @@ package ca.cosc3p91.a2.gameobjects; + import ca.cosc3p91.a2.game.Map; public interface Inhabitant { @@ -8,10 +9,13 @@ public interface Inhabitant { int lvl = 1; void move(Tile t); + void getPosition(); + default int getLevel() { return lvl; } + default int setLevel(int level) { return lvl; } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java index ec38c21..f5ffcb7 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/IronMine.java @@ -2,15 +2,15 @@ package ca.cosc3p91.a2.gameobjects; public class IronMine extends ResourceBuilding { - public static String resource = "iron"; + public static String resource = "iron"; - public IronMine (int lvl, ResourceStage baseStage) { - setLevel(lvl); - upgrade(baseStage); - } + public IronMine(int lvl, ResourceStage baseStage) { + setLevel(lvl); + upgrade(baseStage); + } - @Override - public void harvest(Village_Hall hall) { + @Override + public void harvest(Village_Hall hall) { - } + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java index f4bcf10..5f56f77 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/LumberMine.java @@ -2,15 +2,15 @@ package ca.cosc3p91.a2.gameobjects; public class LumberMine extends ResourceBuilding { - public static String resource = "wood"; + public static String resource = "wood"; - public LumberMine (int lvl, ResourceStage baseStage) { - setLevel(lvl); - upgrade(baseStage); - } + public LumberMine(int lvl, ResourceStage baseStage) { + setLevel(lvl); + upgrade(baseStage); + } - public void harvest(Village_Hall hall) { + public void harvest(Village_Hall hall) { - } + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java index 546e841..e68f02e 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceBuilding.java @@ -2,14 +2,14 @@ package ca.cosc3p91.a2.gameobjects; public abstract class ResourceBuilding extends Building { - public static String resource; - private int harvest_rate; + public static String resource; + private int harvest_rate; - public void upgrade(ResourceStage stage) { - super.upgrade(stage); - this.harvest_rate += stage.getHarvestRateIncrease(); - } + public void upgrade(ResourceStage stage) { + super.upgrade(stage); + this.harvest_rate += stage.getHarvestRateIncrease(); + } - public abstract void harvest(Village_Hall hall); + public abstract void harvest(Village_Hall hall); } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java index a2092b0..e953c1d 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/ResourceStage.java @@ -2,16 +2,16 @@ package ca.cosc3p91.a2.gameobjects; public class ResourceStage extends Stage { - protected int harvestRateIncrease; + protected int harvestRateIncrease; - public ResourceStage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost, - int harvestRateIncr) { - super(dHealth,goldCost,requiredVillageLevel,upgradeTime,ironCost,woodCost); - this.harvestRateIncrease = harvestRateIncr; - } + public ResourceStage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost, + int harvestRateIncr) { + super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost); + this.harvestRateIncrease = harvestRateIncr; + } - public int getHarvestRateIncrease() { - return harvestRateIncrease; - } + public int getHarvestRateIncrease() { + return harvestRateIncrease; + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java index b0d0fee..d6663a5 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/SaulGoodMine.java @@ -2,15 +2,15 @@ package ca.cosc3p91.a2.gameobjects; public class SaulGoodMine extends ResourceBuilding { - public static String resource = "gold"; + public static String resource = "gold"; - public SaulGoodMine(int lvl, ResourceStage baseStage) { - setLevel(lvl); - upgrade(baseStage); - } + public SaulGoodMine(int lvl, ResourceStage baseStage) { + setLevel(lvl); + upgrade(baseStage); + } - @Override - public void harvest(Village_Hall hall) { + @Override + public void harvest(Village_Hall hall) { - } + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java index 71e10a1..2e148cb 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Stage.java @@ -2,42 +2,42 @@ package ca.cosc3p91.a2.gameobjects; abstract class Stage { - protected int dHealth; + protected int dHealth; - protected int goldCost; + protected int goldCost; - protected int requiredVillageLevel; + protected int requiredVillageLevel; - protected int upgradeTime; + protected int upgradeTime; - protected int ironCost; + protected int ironCost; - protected int woodCost; + protected int woodCost; - public Stage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost) { - this.dHealth = dHealth; - this.goldCost = goldCost; - this.requiredVillageLevel = requiredVillageLevel; - this.upgradeTime = upgradeTime; - this.ironCost = ironCost; - this.woodCost = woodCost; - } + public Stage(int dHealth, int goldCost, int requiredVillageLevel, int 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 getHealthChange() { + return dHealth; + } - public int getCost(String type) { - return (type.equals("gold"))?(goldCost): - (type.equals("iron"))?(ironCost):woodCost; - } + public int getCost(String type) { + return (type.equals("gold")) ? (goldCost) : + (type.equals("iron")) ? (ironCost) : woodCost; + } - public int getRequiredVillageLevel() { - return requiredVillageLevel; - } + public int getRequiredVillageLevel() { + return requiredVillageLevel; + } - public int getUpgradeTime() { - return upgradeTime; - } + public int getUpgradeTime() { + return upgradeTime; + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Tile.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Tile.java index bbc6f6f..d6b3dae 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Tile.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Tile.java @@ -4,8 +4,8 @@ import java.util.List; public class Tile { - public int x; + public int x; - public int y; + public int y; } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java index 71c7019..afd0a5f 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/VillageStage.java @@ -2,30 +2,30 @@ package ca.cosc3p91.a2.gameobjects; public class VillageStage extends Stage { - protected int goldCapacityIncrease; + protected int goldCapacityIncrease; - protected int ironCapacityIncrease; + protected int ironCapacityIncrease; - protected int woodCapacityIncrease; + protected int woodCapacityIncrease; - public VillageStage(int dHealth, int goldCost, int requiredVillageLevel, int 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 VillageStage(int dHealth, int goldCost, int requiredVillageLevel, int 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 getGoldCapacityIncrease() { + return goldCapacityIncrease; + } - public int getIronCapacityIncrease() { - return ironCapacityIncrease; - } + public int getIronCapacityIncrease() { + return ironCapacityIncrease; + } - public int getWoodCapacityIncrease() { - return woodCapacityIncrease; - } + public int getWoodCapacityIncrease() { + return woodCapacityIncrease; + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Village_Hall.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Village_Hall.java index b73a489..13515ac 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Village_Hall.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Village_Hall.java @@ -4,60 +4,60 @@ import java.util.ArrayList; public class Village_Hall extends Building { - private int goldCapacity = 0; - private int ironCapacity = 0; - private int woodCapacity = 0; + private int goldCapacity = 0; + private int ironCapacity = 0; + private int woodCapacity = 0; - private int currentGold; - private int currentIron; - private int currentWood; + private int currentGold; + private int currentIron; + private int currentWood; - public Village_Hall (int lvl, VillageStage baseStage) { - setLevel(lvl); - upgrade(baseStage); - } + public Village_Hall(int lvl, VillageStage baseStage) { + setLevel(lvl); + upgrade(baseStage); + } - public void upgrade(VillageStage stage) { - super.upgrade(stage); - this.goldCapacity += stage.getGoldCapacityIncrease(); - this.ironCapacity += stage.getIronCapacityIncrease(); - this.woodCapacity += stage.getWoodCapacityIncrease(); - } + 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 getGoldCapacity() { + return goldCapacity; + } - public int getIronCapacity() { - return ironCapacity; - } + public int getIronCapacity() { + return ironCapacity; + } - public int getWoodCapacity() { - return woodCapacity; - } + public int getWoodCapacity() { + return woodCapacity; + } - public int getCurrentGold() { - return currentGold; - } + public int getCurrentGold() { + return currentGold; + } - public void addCurrentGold(int currentGold) { - this.currentGold += currentGold; - } + public void addCurrentGold(int currentGold) { + this.currentGold += currentGold; + } - public int getCurrentIron() { - return currentIron; - } + public int getCurrentIron() { + return currentIron; + } - public void addCurrentIron(int currentIron) { - this.currentIron += currentIron; - } + public void addCurrentIron(int currentIron) { + this.currentIron += currentIron; + } - public int getCurrentWood() { - return currentWood; - } + public int getCurrentWood() { + return currentWood; + } - public void addCurrentWood(int currentWood) { - this.currentWood += currentWood; - } + public void addCurrentWood(int currentWood) { + this.currentWood += currentWood; + } } diff --git a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Worker.java b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Worker.java index c0ac8a0..7ef950a 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Worker.java +++ b/Assignment 2/src/ca/cosc3p91/a2/gameobjects/Worker.java @@ -7,6 +7,7 @@ public class Worker implements Inhabitant { public void set_IsBuilding(boolean state) { currentlyBuilding = state; } + public boolean isCurrentlyBuilding() { return currentlyBuilding; } diff --git a/Assignment 2/src/ca/cosc3p91/a2/player/Player.java b/Assignment 2/src/ca/cosc3p91/a2/player/Player.java index a45991c..817cfd2 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/player/Player.java +++ b/Assignment 2/src/ca/cosc3p91/a2/player/Player.java @@ -3,5 +3,4 @@ package ca.cosc3p91.a2.player; public class Player { - } \ 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 2d8ef59..cae2953 100644 --- a/Assignment 2/src/ca/cosc3p91/a2/util/Print.java +++ b/Assignment 2/src/ca/cosc3p91/a2/util/Print.java @@ -15,11 +15,11 @@ public class Print { this.values = row; } - public Row(){ + public Row() { this.values = new ArrayList<>(); } - public void add(String value){ + public void add(String value) { values.add(value); } } @@ -28,7 +28,7 @@ public class Print { private final String columnName; private long maxColumnLength = 0; - public Column(String columnName){ + public Column(String columnName) { this.columnName = columnName; } } @@ -40,18 +40,18 @@ public class Print { private final int columnPadding; private int maxColumnWidth; - public Print(String tableName, int columnPadding){ + public Print(String tableName, int columnPadding) { this.tableName = tableName; this.columnPadding = columnPadding; } - public Print(){ + public Print() { this("", 2); } private String createPadding(int amount) { StringBuilder builder = new StringBuilder(); - for (int i = 0; i < amount; i++){ + for (int i = 0; i < amount; i++) { builder.append(' '); } return builder.toString(); @@ -64,8 +64,8 @@ public class Print { 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); + long sizeNameFloor = (long) Math.floor((double) sizeNameRemoved / 2.0); + long sizeNameCeil = (long) Math.ceil((double) sizeNameRemoved / 2.0); halfWidthLeftSeparator.append('+'); @@ -78,7 +78,7 @@ public class Print { StringBuilder separator = new StringBuilder(); separator.append(halfWidthLeftSeparator.toString()); - if (sizeOfName != 0){ + if (sizeOfName != 0) { separator.append("{ "); separator.append(tableName); separator.append(" }"); @@ -87,20 +87,20 @@ public class Print { return separator.toString(); } - private String generateColumnHeader(){ + private String generateColumnHeader() { updateColumnLengths(); StringBuilder header = new StringBuilder(); header.append('|'); - for (int i = 0; i < columns.size(); i++){ + 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)))); + 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(createPadding((int) (columnPadding + (int) Math.ceil(columnPaddingLength)))); + if (i < columns.size() - 1) header.append('|'); } header.append('|'); @@ -115,7 +115,7 @@ public class Print { 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); + int currentColumnSize = (int) (columns.get(currentColumnIndex++).maxColumnLength + columnPadding * 2); nextIndex += currentColumnSize + 1; wholeWidthSeparator.append('+'); } else @@ -139,7 +139,7 @@ public class Print { return column.columnName.length() + columnPadding * 2L; } - public Print addColumn(Column column){ + public Print addColumn(Column column) { columns.add(column); return this; } @@ -154,11 +154,11 @@ public class Print { return this; } - public Print addRow(ArrayList row){ + public Print addRow(ArrayList row) { return addRow(new Row(row)); } - public ArrayList createTable(boolean top, boolean bottom, boolean separators){ + public ArrayList createTable(boolean top, boolean bottom, boolean separators) { ArrayList lines = new ArrayList<>(); String header = generateColumnHeader(); @@ -174,13 +174,13 @@ public class Print { for (Row row : rows) { StringBuilder rowLine = new StringBuilder(); rowLine.append('|'); - for (int i = 0; i < row.values.size(); i++){ + 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)); + 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(createPadding((int) Math.ceil(spaceLeft / 2.0) + columnPadding)); rowLine.append('|'); } lines.add(rowLine.toString()); @@ -192,7 +192,7 @@ public class Print { return lines; } - public ArrayList createBox(){ + public ArrayList createBox() { return new ArrayList<>(); } @@ -200,7 +200,7 @@ public class Print { return createTable(true, true, true); } - public static void print(ArrayList lines){ + public static void print(ArrayList lines) { for (String line : lines) System.out.println(line); }