Compare commits
No commits in common. "f476bfc80f50a999b2c86b251201891469d03917" and "0495018430c8418f19ac5016dcd9f30ef755a793" have entirely different histories.
f476bfc80f
...
0495018430
|
@ -7,6 +7,7 @@ public class Main {
|
|||
public static void main(String[] args) {
|
||||
GameEngine engine = new GameEngine();
|
||||
|
||||
engine.printState();
|
||||
engine.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,10 @@ package ca.cosc3p91.a2.game;
|
|||
|
||||
import ca.cosc3p91.a2.gameobjects.*;
|
||||
import ca.cosc3p91.a2.player.*;
|
||||
import ca.cosc3p91.a2.util.Print;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GameEngine implements Runnable {
|
||||
|
||||
private Player player;
|
||||
boolean running = true;
|
||||
|
||||
private int pillageFactor;
|
||||
|
||||
|
@ -20,54 +16,22 @@ public class GameEngine implements Runnable {
|
|||
public GameEngine() {
|
||||
player = new Player();
|
||||
VillageStage vInitialStage = new VillageStage(100, 0, 2, 30, 0,
|
||||
0, 1000, 2500, 5000);
|
||||
map = new Map(new VillageHall(1, vInitialStage), 30);
|
||||
0, 12, 12, 12);
|
||||
map = new Map(new Village_Hall(1, vInitialStage), 30);
|
||||
}
|
||||
|
||||
private void printState() {
|
||||
Print resourcesPrinter = new Print("Current Village Resources", 2);
|
||||
public void printState() {
|
||||
// Print toPrint = new Print("~ Current Village Buildings ~",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()),
|
||||
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())));
|
||||
|
||||
Print.print(inhabs.createTable(true, true, true));
|
||||
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) {
|
||||
|
@ -82,10 +46,6 @@ public class GameEngine implements Runnable {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
while (running) {
|
||||
printState();
|
||||
int in = sc.nextInt();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public class Map {
|
|||
|
||||
static int MAXSIZE = 400;
|
||||
|
||||
private VillageHall townHall;
|
||||
private Village_Hall townHall;
|
||||
|
||||
private int guardTime;
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class Map {
|
|||
|
||||
public List<Inhabitant> inhabitants;
|
||||
|
||||
public Map(VillageHall villageHall, int gTime) {
|
||||
public Map(Village_Hall villageHall, int gTime) {
|
||||
contains = new ArrayList<>();
|
||||
inhabitants = new ArrayList<>();
|
||||
this.townHall = villageHall;
|
||||
|
@ -45,8 +45,4 @@ public class Map {
|
|||
this.guardTime = gTime;
|
||||
}
|
||||
|
||||
public VillageHall getTownHall(){
|
||||
return townHall;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,5 +12,5 @@ public class Farm extends ResourceBuilding {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void harvest(VillageHall hall) {}
|
||||
public void harvest(Village_Hall hall) {}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ public class IronMine extends ResourceBuilding {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void harvest(VillageHall hall) {
|
||||
public void harvest(Village_Hall hall) {
|
||||
hall.addCurrentIron(getHarvestRate());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public class LumberMine extends ResourceBuilding {
|
|||
upgrade(baseStage);
|
||||
}
|
||||
|
||||
public void harvest(VillageHall hall) {
|
||||
public void harvest(Village_Hall hall) {
|
||||
hall.addCurrentWood(getHarvestRate());
|
||||
}
|
||||
|
||||
|
|
|
@ -20,14 +20,14 @@ public abstract class ResourceBuilding extends Building {
|
|||
this.harvest_rate += stage.getHarvestRateIncrease();
|
||||
}
|
||||
|
||||
public void update(VillageHall hall){
|
||||
public void update(Village_Hall hall){
|
||||
if (nextHarvestTime.occurred()){
|
||||
harvest(hall);
|
||||
nextHarvestTime = Time.getTime().offsetTime(harvestMinTime);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void harvest(VillageHall hall);
|
||||
protected abstract void harvest(Village_Hall hall);
|
||||
|
||||
public int getHarvestRate(){
|
||||
return harvest_rate;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ca.cosc3p91.a2.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a2.util.Time;
|
||||
|
||||
public class SaulGoodMine extends ResourceBuilding {
|
||||
|
||||
public static String resource = "gold";
|
||||
|
@ -10,7 +12,7 @@ public class SaulGoodMine extends ResourceBuilding {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void harvest(VillageHall hall) {
|
||||
public void harvest(Village_Hall hall) {
|
||||
hall.addCurrentGold(getHarvestRate());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package ca.cosc3p91.a2.gameobjects;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class VillageHall extends Building {
|
||||
public class Village_Hall extends Building {
|
||||
|
||||
private int goldCapacity = 0;
|
||||
private int ironCapacity = 0;
|
||||
|
@ -12,7 +12,7 @@ public class VillageHall extends Building {
|
|||
private int currentIron;
|
||||
private int currentWood;
|
||||
|
||||
public VillageHall(int lvl, VillageStage baseStage) {
|
||||
public Village_Hall(int lvl, VillageStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package ca.cosc3p91.a2.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Ported from blt::TableFormatter (C++)
|
||||
|
@ -20,18 +19,13 @@ public class Print {
|
|||
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 final String columnName;
|
||||
private long maxColumnLength = 0;
|
||||
|
||||
public Column(String columnName) {
|
||||
|
@ -44,21 +38,15 @@ public class Print {
|
|||
|
||||
private final String tableName;
|
||||
private final int columnPadding;
|
||||
private int width;
|
||||
private final int targetWidth;
|
||||
private int maxColumnWidth;
|
||||
|
||||
public Print(String tableName, int columnPadding, int targetWidth) {
|
||||
public Print(String tableName, int columnPadding) {
|
||||
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("");
|
||||
this("", 2);
|
||||
}
|
||||
|
||||
private String createPadding(int amount) {
|
||||
|
@ -126,7 +114,7 @@ public class Print {
|
|||
StringBuilder wholeWidthSeparator = new StringBuilder();
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (i == nextIndex) {
|
||||
//System.out.println(currentColumnIndex + " " + nextIndex + " " + size);
|
||||
System.out.println(currentColumnIndex + " " + nextIndex + " " + size);
|
||||
int currentColumnSize = (int) (columns.get(currentColumnIndex++).maxColumnLength + columnPadding * 2);
|
||||
nextIndex += currentColumnSize + 1;
|
||||
wholeWidthSeparator.append('+');
|
||||
|
@ -142,7 +130,7 @@ public class Print {
|
|||
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());
|
||||
column.maxColumnLength = Math.max(column.maxColumnLength, row.values.get(i).length() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,37 +159,12 @@ public class Print {
|
|||
}
|
||||
|
||||
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 (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<String> lines = new ArrayList<>();
|
||||
|
||||
if (top)
|
||||
lines.add(topSeparator);
|
||||
|
||||
|
@ -237,10 +200,6 @@ public class Print {
|
|||
return createTable(true, true, true);
|
||||
}
|
||||
|
||||
public int getWidth(){
|
||||
return width;
|
||||
}
|
||||
|
||||
public static void print(ArrayList<String> lines) {
|
||||
for (String line : lines)
|
||||
System.out.println(line);
|
||||
|
|
Loading…
Reference in New Issue