Saul Goodmine

main
mike 2023-03-01 16:17:21 -05:00
commit f0844a6564
25 changed files with 556 additions and 92 deletions

2
.gitignore vendored
View File

@ -0,0 +1,2 @@
Assignment 2/out/
out/

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -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();
}

View File

@ -7,14 +7,15 @@ import ca.cosc3p91.a2.player.Player;
public class GameEngine implements Runnable {
private Player player;
private final boolean running = true;
private int pillageFactor;
private Player player;
private int currentTime;
private int pillageFactor;
public Map map;
private int currentTime;
<<<<<<< HEAD
public GameEngine () {
player = new Player();
VillageStage vInitialStage = new VillageStage(100,0,2,30,0,
@ -32,16 +33,24 @@ public class GameEngine implements Runnable {
public void attackVillage(Map map) {
}
=======
public Map map;
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
public Map generateMap() {
return null;
}
public void attackVIllage(Map map) {
}
public void getScore(Map map) {
}
public Map generateMap() {
return null;
}
@Override
public void run() {
public void getScore(Map map) {
}
}
@Override
public void run() {
while (running) {
}
}
}

View File

@ -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;
=======
private int guardTime;
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;
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 int getGuardTime() {
return guardTime;
}
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
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
public abstract class Building {
<<<<<<< HEAD
// members
private int level;
private int health;
@ -13,22 +14,43 @@ public abstract class Building {
private int goldCost;
private int ironCost;
private int woodCost;
=======
private static int level;
private int buildTime;
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 int getLevel() {
return level;
}
public List<Inhabitant> inhabitant;
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
public int getHealth() {
return health;
}
public int getLevel() {
return level;
}
public int getHealth() {
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;
}
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
}

View File

@ -2,10 +2,10 @@ package ca.cosc3p91.a2.gameobjects;
public class Collector {
private int averageCollectionRate;
private int averageCollectionRate;
public int getCollectionRate() {
return averageCollectionRate;
}
public int getCollectionRate() {
return averageCollectionRate;
}
}

View File

@ -2,6 +2,7 @@ package ca.cosc3p91.a2.gameobjects;
public class DefenseBuilding extends Building {
<<<<<<< HEAD
private int damage;
private int range;
@ -10,9 +11,14 @@ public class DefenseBuilding extends Building {
this.damage += stage.getDamageChange();
this.range += stage.getRangeChange();
}
=======
public int damage;
public void attack(Infantry attacker) {
public int range;
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
}
public void attack(Infantry attacker) {
}
}

View File

@ -2,10 +2,15 @@ package ca.cosc3p91.a2.gameobjects;
class DefenseStage extends Stage {
<<<<<<< HEAD
protected int dDamage;
=======
protected int dDamge;
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
protected int dRange;
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
}

View File

@ -7,12 +7,12 @@ public class Farm extends ResourceBuilding {
upgrade(baseStage);
}
public int getPopulationContribution() {
return 0;
}
public int getPopulationContribution() {
return 0;
}
@Override
public void harvest(Village_Hall hall) {
@Override
public void harvest(Village_Hall hall) {
}
}
}

View File

@ -2,15 +2,19 @@ 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) {
@Override
public void harvest(Village_Hall hall) {
}
}
}

View File

@ -2,22 +2,22 @@ package ca.cosc3p91.a2.gameobjects;
public abstract class Infantry {
private int health;
private int health;
private int damage;
private int damage;
private int range;
private int range;
public void attack(Building b) {
}
public void attack(Building b) {
}
public void getHealth() {
}
public void getHealth() {
}
public void getDamage() {
}
public void getDamage() {
}
public void getRange() {
}
public void getRange() {
}
}

View File

@ -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();
}

View File

@ -2,8 +2,9 @@ package ca.cosc3p91.a2.gameobjects;
public class IronMine extends ResourceBuilding {
public static String resource = "iron";
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
}
}
}

View File

@ -2,15 +2,19 @@ package ca.cosc3p91.a2.gameobjects;
public class LumberMine extends ResourceBuilding {
public static String resource = "wood";
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
}

View File

@ -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);
}

View File

@ -2,8 +2,9 @@ package ca.cosc3p91.a2.gameobjects;
public class ResourceStage extends Stage {
protected int harvestRateIncrease;
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
}

View File

@ -2,18 +2,19 @@ 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;
<<<<<<< HEAD
public Stage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost) {
this.dHealth = dHealth;
this.goldCost = goldCost;
@ -31,13 +32,23 @@ abstract class Stage {
return (type.equals("gold"))?(goldCost):
(type.equals("iron"))?(ironCost):woodCost;
}
=======
public Building building;
public int getRequiredVillageLevel() {
return requiredVillageLevel;
}
public void getHealthChange() {
}
public int getUpgradeTime() {
return upgradeTime;
}
public int getCost(String type) {
return 0;
}
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
public int getRequiredVillageLevel() {
return requiredVillageLevel;
}
public int getUpgradeTime() {
return upgradeTime;
}
}

View File

@ -4,8 +4,13 @@ import java.util.List;
public class Tile {
public int x;
public int x;
public int y;
public int y;
<<<<<<< HEAD
=======
public List<Building> building;
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
}

View File

@ -2,12 +2,13 @@ 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;
<<<<<<< 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,13 +20,18 @@ public class VillageStage extends Stage {
public int getGoldCapacityIncrease() {
return goldCapacityIncrease;
}
=======
public int getGoldCapacityIncrease() {
return goldCapacityIncrease;
}
>>>>>>> abf784868daa920a9ca8b3b9d291a7cf521aa9c7
public int getIronCapacityIncrease() {
return ironCapacityIncrease;
}
public int getIronCapacityIncrease() {
return ironCapacityIncrease;
}
public int getWoodCapacityIncrease() {
return woodCapacityIncrease;
}
public int getWoodCapacityIncrease() {
return woodCapacityIncrease;
}
}

View File

@ -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
}

View File

@ -2,10 +2,10 @@ package ca.cosc3p91.a2.gameobjects;
public class Worker {
private boolean currentlyBuilding;
private boolean currentlyBuilding;
public boolean isCurrentlyBuilding() {
return currentlyBuilding;
}
public boolean isCurrentlyBuilding() {
return currentlyBuilding;
}
}

View File

@ -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
}

View File

@ -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);
}
}

View File

@ -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);
}
}