reformat
parent
5b516418ed
commit
9a7aa7c6b3
|
@ -13,11 +13,11 @@ public class GameEngine implements Runnable {
|
|||
|
||||
public Map map;
|
||||
|
||||
public GameEngine () {
|
||||
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);
|
||||
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() {
|
||||
|
@ -26,11 +26,11 @@ public class GameEngine implements Runnable {
|
|||
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("\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());
|
||||
System.out.println("\t|> " + i.getClass().getSimpleName() + " lvl: " + i.getLevel());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public class Map {
|
|||
|
||||
public List<Inhabitant> inhabitants;
|
||||
|
||||
public Map (Village_Hall villageHall, int gTime) {
|
||||
public Map(Village_Hall villageHall, int gTime) {
|
||||
contains = new ArrayList<>();
|
||||
inhabitants = new ArrayList<>();
|
||||
this.townHall = villageHall;
|
||||
|
|
|
@ -30,8 +30,8 @@ public abstract class Building {
|
|||
}
|
||||
|
||||
public int getCost(String type) {
|
||||
return (type.equals("gold"))?(goldCost):
|
||||
(type.equals("iron"))?(ironCost):woodCost;
|
||||
return (type.equals("gold")) ? (goldCost) :
|
||||
(type.equals("iron")) ? (ironCost) : woodCost;
|
||||
}
|
||||
|
||||
public Stage getStage() {
|
||||
|
@ -50,7 +50,9 @@ public abstract class Building {
|
|||
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);
|
||||
|
|
|
@ -8,7 +8,7 @@ class DefenseStage extends Stage {
|
|||
|
||||
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);
|
||||
super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost);
|
||||
this.dDamage = damageIncrease;
|
||||
this.dRange = rangeIncrease;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package ca.cosc3p91.a2.gameobjects;
|
|||
|
||||
public class Farm extends ResourceBuilding {
|
||||
|
||||
public Farm (int lvl, ResourceStage baseStage) {
|
||||
public Farm(int lvl, ResourceStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ public class IronMine extends ResourceBuilding {
|
|||
|
||||
public static String resource = "iron";
|
||||
|
||||
public IronMine (int lvl, ResourceStage baseStage) {
|
||||
public IronMine(int lvl, ResourceStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ public class LumberMine extends ResourceBuilding {
|
|||
|
||||
public static String resource = "wood";
|
||||
|
||||
public LumberMine (int lvl, ResourceStage baseStage) {
|
||||
public LumberMine(int lvl, ResourceStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ public class ResourceStage extends Stage {
|
|||
|
||||
public ResourceStage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost,
|
||||
int harvestRateIncr) {
|
||||
super(dHealth,goldCost,requiredVillageLevel,upgradeTime,ironCost,woodCost);
|
||||
super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost);
|
||||
this.harvestRateIncrease = harvestRateIncr;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ abstract class Stage {
|
|||
}
|
||||
|
||||
public int getCost(String type) {
|
||||
return (type.equals("gold"))?(goldCost):
|
||||
(type.equals("iron"))?(ironCost):woodCost;
|
||||
return (type.equals("gold")) ? (goldCost) :
|
||||
(type.equals("iron")) ? (ironCost) : woodCost;
|
||||
}
|
||||
|
||||
public int getRequiredVillageLevel() {
|
||||
|
|
|
@ -10,7 +10,7 @@ public class VillageStage extends Stage {
|
|||
|
||||
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);
|
||||
super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost);
|
||||
this.goldCapacityIncrease = goldCapIncrease;
|
||||
this.ironCapacityIncrease = ironCapIncrease;
|
||||
this.woodCapacityIncrease = woodCapIncrease;
|
||||
|
|
|
@ -12,7 +12,7 @@ public class Village_Hall extends Building {
|
|||
private int currentIron;
|
||||
private int currentWood;
|
||||
|
||||
public Village_Hall (int lvl, VillageStage baseStage) {
|
||||
public Village_Hall(int lvl, VillageStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ public class Worker implements Inhabitant {
|
|||
public void set_IsBuilding(boolean state) {
|
||||
currentlyBuilding = state;
|
||||
}
|
||||
|
||||
public boolean isCurrentlyBuilding() {
|
||||
return currentlyBuilding;
|
||||
}
|
||||
|
|
|
@ -3,5 +3,4 @@ package ca.cosc3p91.a2.player;
|
|||
public class Player {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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<String> row){
|
||||
public Print addRow(ArrayList<String> row) {
|
||||
return addRow(new Row(row));
|
||||
}
|
||||
|
||||
public ArrayList<String> createTable(boolean top, boolean bottom, boolean separators){
|
||||
public ArrayList<String> createTable(boolean top, boolean bottom, boolean separators) {
|
||||
ArrayList<String> 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<String> createBox(){
|
||||
public ArrayList<String> createBox() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ public class Print {
|
|||
return createTable(true, true, true);
|
||||
}
|
||||
|
||||
public static void print(ArrayList<String> lines){
|
||||
public static void print(ArrayList<String> lines) {
|
||||
for (String line : lines)
|
||||
System.out.println(line);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue