Saul Goodmine
commit
f0844a6564
|
@ -0,0 +1,2 @@
|
|||
Assignment 2/out/
|
||||
out/
|
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
|
@ -1,13 +1,34 @@
|
|||
package ca.cosc3p91.a2;
|
||||
|
||||
import ca.cosc3p91.a2.game.GameEngine;
|
||||
import ca.cosc3p91.a2.util.Print;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
GameEngine engine = new GameEngine();
|
||||
|
||||
<<<<<<< HEAD
|
||||
engine.printMap();
|
||||
=======
|
||||
Print test = new Print("Hello There", 2);
|
||||
|
||||
test.addColumn(new Print.Column("I am value 1"));
|
||||
test.addColumn(new Print.Column("Super Value"));
|
||||
test.addColumn(new Print.Column("SOLD!"));
|
||||
|
||||
Print.Row row = new Print.Row();
|
||||
row.add("HelloThere");
|
||||
row.add("Goodbye");
|
||||
row.add("3");
|
||||
|
||||
test.addRow(row);
|
||||
test.addRow(row);
|
||||
test.addRow(row);
|
||||
|
||||
Print.print(test.createTable());
|
||||
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
engine.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,14 +7,15 @@ import ca.cosc3p91.a2.player.Player;
|
|||
|
||||
public class GameEngine implements Runnable {
|
||||
|
||||
private final boolean running = true;
|
||||
|
||||
private Player player;
|
||||
|
||||
private int pillageFactor;
|
||||
|
||||
private int currentTime;
|
||||
|
||||
public Map map;
|
||||
|
||||
<<<<<<< HEAD
|
||||
public GameEngine () {
|
||||
player = new Player();
|
||||
VillageStage vInitialStage = new VillageStage(100,0,2,30,0,
|
||||
|
@ -32,6 +33,12 @@ public class GameEngine implements Runnable {
|
|||
|
||||
public void attackVillage(Map map) {
|
||||
}
|
||||
=======
|
||||
public Map map;
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
public void attackVIllage(Map map) {
|
||||
}
|
||||
|
||||
public Map generateMap() {
|
||||
return null;
|
||||
|
@ -42,6 +49,8 @@ public class GameEngine implements Runnable {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
while (running) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,18 +5,30 @@ import ca.cosc3p91.a2.gameobjects.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
<<<<<<< HEAD
|
||||
public class Map {
|
||||
|
||||
static int MAXSIZE = 400;
|
||||
|
||||
private Village_Hall townHall;
|
||||
=======
|
||||
|
||||
public class Map {
|
||||
|
||||
private Village_Hall townHall;
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
private int guardTime;
|
||||
|
||||
<<<<<<< HEAD
|
||||
public List<Building> contains;
|
||||
=======
|
||||
private List<Building> contains;
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
public List<Inhabitant> inhabitants;
|
||||
|
||||
<<<<<<< HEAD
|
||||
public Map (Village_Hall villageHall, int gTime) {
|
||||
contains = new ArrayList<>();
|
||||
inhabitants = new ArrayList<>();
|
||||
|
@ -36,13 +48,28 @@ public class Map {
|
|||
public void build(Village_Hall hall, Tile t, Building b) {
|
||||
contains.add(b);
|
||||
}
|
||||
=======
|
||||
public void move(Infantry i, Tile t) {
|
||||
}
|
||||
|
||||
public void inRange(Infantry i, Building b) {
|
||||
}
|
||||
|
||||
public void build(Village_Hall hall, Tile t, Building b) {
|
||||
}
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
public int getGuardTime() {
|
||||
return guardTime;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public void setGuardTime(int gTime) {
|
||||
this.guardTime = gTime;
|
||||
}
|
||||
=======
|
||||
public void setGuardTime() {
|
||||
}
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
|
||||
public abstract class Building {
|
||||
|
||||
<<<<<<< HEAD
|
||||
// members
|
||||
private int level;
|
||||
private int health;
|
||||
|
@ -13,13 +14,33 @@ public abstract class Building {
|
|||
private int goldCost;
|
||||
private int ironCost;
|
||||
private int woodCost;
|
||||
=======
|
||||
private static int level;
|
||||
|
||||
private int health;
|
||||
|
||||
private static Stage stages;
|
||||
|
||||
private int goldCost;
|
||||
|
||||
private int ironCost;
|
||||
|
||||
private int woodCost;
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
private int buildTime;
|
||||
|
||||
<<<<<<< HEAD
|
||||
public ArrayList<Tile> tiles = new ArrayList<>();
|
||||
public ArrayList<Inhabitant> inhabitants = new ArrayList<>();
|
||||
|
||||
// functions
|
||||
=======
|
||||
public List<Stage> stage;
|
||||
public Tile tile;
|
||||
|
||||
public List<Inhabitant> inhabitant;
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
|
@ -29,6 +50,7 @@ public abstract class Building {
|
|||
return health;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public int getCost(String type) {
|
||||
return (type.equals("gold"))?(goldCost):
|
||||
(type.equals("iron"))?(ironCost):woodCost;
|
||||
|
@ -37,11 +59,17 @@ public abstract class Building {
|
|||
public Stage getStage() {
|
||||
return stage;
|
||||
}
|
||||
=======
|
||||
public int getCost(String type) {
|
||||
return 0;
|
||||
}
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
public int getUpgradeCost() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
@ -66,4 +94,14 @@ public abstract class Building {
|
|||
public int getBuildTime() {
|
||||
return buildTime;
|
||||
}
|
||||
=======
|
||||
public void upgrade() {
|
||||
|
||||
}
|
||||
|
||||
public int getBuildTime() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package ca.cosc3p91.a2.gameobjects;
|
|||
|
||||
public class DefenseBuilding extends Building {
|
||||
|
||||
<<<<<<< HEAD
|
||||
private int damage;
|
||||
private int range;
|
||||
|
||||
|
@ -10,6 +11,11 @@ public class DefenseBuilding extends Building {
|
|||
this.damage += stage.getDamageChange();
|
||||
this.range += stage.getRangeChange();
|
||||
}
|
||||
=======
|
||||
public int damage;
|
||||
|
||||
public int range;
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
public void attack(Infantry attacker) {
|
||||
|
||||
|
|
|
@ -2,10 +2,15 @@ package ca.cosc3p91.a2.gameobjects;
|
|||
|
||||
class DefenseStage extends Stage {
|
||||
|
||||
<<<<<<< HEAD
|
||||
protected int dDamage;
|
||||
=======
|
||||
protected int dDamge;
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
protected int dRange;
|
||||
|
||||
<<<<<<< HEAD
|
||||
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);
|
||||
|
@ -20,5 +25,12 @@ class DefenseStage extends Stage {
|
|||
public int getRangeChange() {
|
||||
return dRange;
|
||||
}
|
||||
=======
|
||||
public void getDamageChange() {
|
||||
}
|
||||
|
||||
public void getRangeChange() {
|
||||
}
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
}
|
|
@ -2,12 +2,16 @@ package ca.cosc3p91.a2.gameobjects;
|
|||
|
||||
public class GoldMine extends ResourceBuilding {
|
||||
|
||||
<<<<<<< HEAD
|
||||
public static String resource = "gold";
|
||||
|
||||
public GoldMine (int lvl, ResourceStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
}
|
||||
=======
|
||||
public static String resource = "good";
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
@Override
|
||||
public void harvest(Village_Hall hall) {
|
||||
|
|
|
@ -4,11 +4,11 @@ import ca.cosc3p91.a2.game.Map;
|
|||
|
||||
public interface Inhabitant {
|
||||
|
||||
public Map map = null;
|
||||
public Building building = null;
|
||||
Map map = null;
|
||||
Building building = null;
|
||||
|
||||
public void move(Tile t);
|
||||
void move(Tile t);
|
||||
|
||||
public void getPosition();
|
||||
void getPosition();
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ public class IronMine extends ResourceBuilding {
|
|||
|
||||
public static String resource = "iron";
|
||||
|
||||
<<<<<<< HEAD
|
||||
public IronMine (int lvl, ResourceStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
|
@ -11,6 +12,10 @@ public class IronMine extends ResourceBuilding {
|
|||
|
||||
@Override
|
||||
public void harvest(Village_Hall hall) {
|
||||
=======
|
||||
@Override
|
||||
public void harvest(Village_Hall hall) {
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,17 @@ public class LumberMine extends ResourceBuilding {
|
|||
|
||||
public static String resource = "wood";
|
||||
|
||||
<<<<<<< HEAD
|
||||
public LumberMine (int lvl, ResourceStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
}
|
||||
|
||||
public void harvest(Village_Hall hall) {
|
||||
=======
|
||||
public void harvest(Village_Hall hall) {
|
||||
|
||||
}
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package ca.cosc3p91.a2.gameobjects;
|
||||
|
||||
public abstract class ResourceBuidling extends Building {
|
||||
|
||||
public static String resource;
|
||||
|
||||
private int harvest_rate;
|
||||
|
||||
public abstract void harvest(Village_Hall hall);
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@ public class ResourceStage extends Stage {
|
|||
|
||||
protected int harvestRateIncrease;
|
||||
|
||||
<<<<<<< HEAD
|
||||
public ResourceStage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost,
|
||||
int harvestRateIncr) {
|
||||
super(dHealth,goldCost,requiredVillageLevel,upgradeTime,ironCost,woodCost);
|
||||
|
@ -13,5 +14,10 @@ public class ResourceStage extends Stage {
|
|||
public int getHarvestRateIncrease() {
|
||||
return harvestRateIncrease;
|
||||
}
|
||||
=======
|
||||
public int getHarvestRateIncrease() {
|
||||
return harvestRateIncrease;
|
||||
}
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ abstract class Stage {
|
|||
|
||||
protected int woodCost;
|
||||
|
||||
<<<<<<< HEAD
|
||||
public Stage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost) {
|
||||
this.dHealth = dHealth;
|
||||
this.goldCost = goldCost;
|
||||
|
@ -31,6 +32,16 @@ abstract class Stage {
|
|||
return (type.equals("gold"))?(goldCost):
|
||||
(type.equals("iron"))?(ironCost):woodCost;
|
||||
}
|
||||
=======
|
||||
public Building building;
|
||||
|
||||
public void getHealthChange() {
|
||||
}
|
||||
|
||||
public int getCost(String type) {
|
||||
return 0;
|
||||
}
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
public int getRequiredVillageLevel() {
|
||||
return requiredVillageLevel;
|
||||
|
|
|
@ -8,4 +8,9 @@ public class Tile {
|
|||
|
||||
public int y;
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
public List<Building> building;
|
||||
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ public class VillageStage extends Stage {
|
|||
|
||||
protected int woodCapacityIncrease;
|
||||
|
||||
<<<<<<< HEAD
|
||||
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);
|
||||
|
@ -19,6 +20,11 @@ public class VillageStage extends Stage {
|
|||
public int getGoldCapacityIncrease() {
|
||||
return goldCapacityIncrease;
|
||||
}
|
||||
=======
|
||||
public int getGoldCapacityIncrease() {
|
||||
return goldCapacityIncrease;
|
||||
}
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
public int getIronCapacityIncrease() {
|
||||
return ironCapacityIncrease;
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
|
||||
public class Village_Hall extends Building {
|
||||
|
||||
<<<<<<< HEAD
|
||||
private int goldCapacity = 0;
|
||||
|
||||
private int ironCapacity = 0;
|
||||
|
@ -34,5 +35,24 @@ public class Village_Hall extends Building {
|
|||
public int getWoodCapacity() {
|
||||
return woodCapacity;
|
||||
}
|
||||
=======
|
||||
private int goldCapacity;
|
||||
|
||||
private int ironCapacity;
|
||||
|
||||
private int woodCapacity;
|
||||
|
||||
public int getGoldCapacity() {
|
||||
return goldCapacity;
|
||||
}
|
||||
|
||||
public int getIronCapacity() {
|
||||
return ironCapacity;
|
||||
}
|
||||
|
||||
public int getWoodCapacity() {
|
||||
return woodCapacity;
|
||||
}
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,16 @@ package ca.cosc3p91.a2.player;
|
|||
|
||||
public class Player {
|
||||
|
||||
<<<<<<< HEAD
|
||||
public int currentGold;
|
||||
public int currentIron;
|
||||
public int currentWood;
|
||||
=======
|
||||
public int currentGold;
|
||||
|
||||
public int currentIron;
|
||||
|
||||
public int currentWood;
|
||||
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
|
||||
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
package ca.cosc3p91.a2.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Ported from blt::TableFormatter (C++)
|
||||
* https://github.com/Tri11Paragon/BLT/
|
||||
*/
|
||||
public class Print {
|
||||
|
||||
public static class Row {
|
||||
private final ArrayList<String> values;
|
||||
|
||||
public Row(ArrayList<String> row) {
|
||||
this.values = row;
|
||||
}
|
||||
|
||||
public Row(){
|
||||
this.values = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void add(String value){
|
||||
values.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Column {
|
||||
private final String columnName;
|
||||
private long maxColumnLength = 0;
|
||||
|
||||
public Column(String columnName){
|
||||
this.columnName = columnName;
|
||||
}
|
||||
}
|
||||
|
||||
private final ArrayList<Row> rows = new ArrayList<>();
|
||||
private final ArrayList<Column> columns = new ArrayList<>();
|
||||
|
||||
private final String tableName;
|
||||
private final int columnPadding;
|
||||
private int maxColumnWidth;
|
||||
|
||||
public Print(String tableName, int columnPadding){
|
||||
this.tableName = tableName;
|
||||
this.columnPadding = columnPadding;
|
||||
}
|
||||
|
||||
public Print(){
|
||||
this("", 2);
|
||||
}
|
||||
|
||||
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() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<String> row){
|
||||
return addRow(new Row(row));
|
||||
}
|
||||
|
||||
public ArrayList<String> createTable(boolean top, boolean bottom, boolean separators){
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
|
||||
String header = generateColumnHeader();
|
||||
String topSeparator = generateTopSelector(header.length());
|
||||
String lineSeparator = generateSeparator(header.length() - 1);
|
||||
|
||||
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<String> createBox(){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public ArrayList<String> createTable() {
|
||||
return createTable(true, true, true);
|
||||
}
|
||||
|
||||
public static void print(ArrayList<String> lines){
|
||||
for (String line : lines)
|
||||
System.out.println(line);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package ca.cosc3p91.a2.util;
|
||||
|
||||
public class Time {
|
||||
|
||||
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 static class FutureTime {
|
||||
private final Time futureTime;
|
||||
|
||||
public FutureTime(Time futureTime) {
|
||||
this.futureTime = futureTime;
|
||||
}
|
||||
|
||||
public boolean occurred() {
|
||||
return getTime().timeSeconds >= futureTime.timeSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
public static Time getTime() {
|
||||
return new Time(System.currentTimeMillis() / 1000);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue