Compare commits

..

No commits in common. "349d9084860afe1f705fc4235e3365978a4f7687" and "21917eb82ea56da2542e442ed2a5264479e68274" have entirely different histories.

13 changed files with 58 additions and 189 deletions

View File

@ -12,7 +12,7 @@ import java.io.InputStreamReader;
import java.util.Random; import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
public class GameEngine<T> implements Runnable { public class GameEngine implements Runnable {
public static final double GOLD_FACTOR = 5; public static final double GOLD_FACTOR = 5;
public static final double IRON_FACTOR = 1; public static final double IRON_FACTOR = 1;
@ -34,8 +34,8 @@ public class GameEngine<T> implements Runnable {
map = generateInitialMap(); map = generateInitialMap();
} }
private void printState(Map map, String displayName) { private void printState() {
Print resourcesPrinter = new Print(displayName, 2); Print resourcesPrinter = new Print("Current Village Resources", 2);
resourcesPrinter.addColumn(new Print.Column("Resource Type")); resourcesPrinter.addColumn(new Print.Column("Resource Type"));
resourcesPrinter.addColumn(new Print.Column("Max")); resourcesPrinter.addColumn(new Print.Column("Max"));
@ -80,16 +80,6 @@ public class GameEngine<T> implements Runnable {
Print.print(inhabs.createTable(true, true, true)); Print.print(inhabs.createTable(true, true, true));
} }
private void printMenuOptions() {
System.out.println("~ Player Options:\n" +
"1. Build {command: '1 <building name>'}\n" +
"2. Train inhabitants {command: '2 <unit name>'}\n"+
"3. Upgrade Building\n"+
"4. Explore\n"+
"5. Check Village Stats\n"+
"6. Quit");
}
public void attackVillage(Map map) { public void attackVillage(Map map) {
} }
@ -179,15 +169,15 @@ public class GameEngine<T> implements Runnable {
public void run() { public void run() {
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in)); BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(rd); Scanner sc = new Scanner(rd);
printState(this.map,"Current Village State"); printState();
printMenuOptions();
System.out.println(); System.out.println();
while (running) { while (running) {
for (Building b : this.map.contains){ for (Building b : map.contains){
if ((b instanceof ResourceBuilding)) { if ((b instanceof ResourceBuilding)) {
((ResourceBuilding) b).update(this.map.getTownHall()); ((ResourceBuilding) b).update(map.getTownHall());
} }
} }
//System.out.println("Updating");
try { try {
if (rd.ready()) { if (rd.ready()) {
String in = sc.nextLine(); String in = sc.nextLine();
@ -195,40 +185,26 @@ public class GameEngine<T> implements Runnable {
System.out.println("Your Input: "); System.out.println("Your Input: ");
System.out.println("\t->" + in); System.out.println("\t->" + in);
switch (in.charAt(0)) { switch (in.charAt(0)) {
case '1': case 'p':
printState();
break;
case 'q':
System.exit(0);
break;
case 'b':
if (args.length < 2) { if (args.length < 2) {
System.err.println("Args must include type!"); System.err.println("Args must include type!");
} else { } else {
Building type = (Building)determineType(args[1],new Cannon()); Building type = determineType(args[1]);
if (type == null) if (type == null)
System.err.println("Args are not a valid building!"); System.err.println("Args are not a valid building!");
else if (this.map.build(new Tile(), type) ) { else
System.out.println(type.getClass().getSimpleName()+" successfully built\n"); map.build(new Tile(), type);
} else System.out.println("Missing resources to build "+type.getClass().getSimpleName());
} }
break; break;
case '2':
if (args.length < 2) {
System.err.println("Args must include type!");
} else {
Inhabitant type = (Inhabitant)determineType(args[1],new Worker());
if (type == null)
System.err.println("Args are not a valid inhabitant!");
else if (this.map.train(type) ) {
System.out.println("successfully trained a(n) "+type.getClass().getSimpleName());
} else System.out.println("Missing gold to train "+type.getClass().getSimpleName());
}
break;
case '5':
printState(this.map,"Current Village State");
break;
case '6':
System.exit(0);
break;
default: default:
break; break;
} }
printMenuOptions();
} }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -236,40 +212,22 @@ public class GameEngine<T> implements Runnable {
} }
} }
private static <T> Object determineType(String argument, T type){ private static Building determineType(String building){
argument = argument.toLowerCase(); building = building.toLowerCase();
char c = ' '; char c = ' ';
if (argument.trim().length() == 1) if (building.trim().length() == 1)
c = argument.charAt(0); c = building.charAt(0);
if (building.contains("gold") || building.contains("good") || c == 'g') {
if (type instanceof Building) {
if (argument.contains("gold") || argument.contains("good") || c == 'g') {
return new SaulGoodMine(ResourceStages.goldStages[0]); return new SaulGoodMine(ResourceStages.goldStages[0]);
} else if (argument.contains("iron") || c == 'i') { } else if (building.contains("iron") || c == 'i') {
return new IronMine(ResourceStages.ironStages[0]); return new IronMine(ResourceStages.ironStages[0]);
} else if (argument.contains("wood") || argument.contains("lumber") || c == 'w' || c == 'l') { } else if (building.contains("wood") || building.contains("lumber") || c == 'w' || c == 'l') {
return new LumberMine(ResourceStages.woodStages[0]); return new LumberMine(ResourceStages.woodStages[0]);
} else if (argument.contains("archer") || c == 'a') { } else if (building.contains("archer") || c == 'a') {
return new ArcherTower(); return new ArcherTower();
} else if (argument.contains("can") || c == 'c') { } else if (building.contains("can") || c == 'c'){
return new Cannon(); return new Cannon();
} }
} else if (type instanceof Inhabitant) {
if (argument.contains("soldier") || argument.contains("sold") || c == 's') {
return new Soldier();
} else if (argument.contains("knight") || c == 'k') {
return new Knight();
} else if (argument.contains("work") || c == 'w') {
return new Worker();
} else if (argument.contains("collect") || c == 'c') {
return new Collector();
} else if (argument.contains("cat")) {
return new Catapult();
} else if (argument.contains("arch") || c == 'a') {
return new Archer();
}
}
return null; return null;
} }
} }

View File

@ -7,7 +7,7 @@ import java.util.List;
public class Map { public class Map {
static int MAXSIZE = 50; static int MAXSIZE = 400;
private CasaDeNarino townHall; private CasaDeNarino townHall;
@ -22,8 +22,6 @@ public class Map {
inhabitants = new ArrayList<>(); inhabitants = new ArrayList<>();
this.townHall = casaDeNarino; this.townHall = casaDeNarino;
this.contains.add(casaDeNarino); this.contains.add(casaDeNarino);
this.inhabitants.add(new Worker()); this.inhabitants.add(new Worker());
this.inhabitants.add(new Collector());
this.guardTime = gTime; this.guardTime = gTime;
} }
@ -35,10 +33,10 @@ public class Map {
} }
public boolean build(Tile t, Building b) { public void build(Tile t, Building b) {
int goldCost = b.getStage().getCost(SaulGoodMine.resource); int goldCost = b.getStage().getCost(SaulGoodMine.resource);
int ironCost = b.getStage().getCost(IronMine.resource); int ironCost = b.getStage().getCost(SaulGoodMine.resource);
int woodCost = b.getStage().getCost(LumberMine.resource); int woodCost = b.getStage().getCost(SaulGoodMine.resource);
CasaDeNarino hall = getTownHall(); CasaDeNarino hall = getTownHall();
if (hall.getCurrentGold() >= goldCost && hall.getCurrentIron() >= ironCost && hall.getCurrentWood() >= woodCost) { if (hall.getCurrentGold() >= goldCost && hall.getCurrentIron() >= ironCost && hall.getCurrentWood() >= woodCost) {
if(!hall.addGold(-goldCost)) if(!hall.addGold(-goldCost))
@ -48,20 +46,7 @@ public class Map {
if(!hall.addWood(-woodCost)) if(!hall.addWood(-woodCost))
throw new RuntimeException("Unable to subtract wood despite valid check!"); throw new RuntimeException("Unable to subtract wood despite valid check!");
contains.add(b); contains.add(b);
return true;
} else return false;
} }
public boolean train(Inhabitant i) {
CasaDeNarino hall = getTownHall();
int goldCost = i.getCost();
if (hall.getCurrentGold() >= goldCost) {
if(!hall.addGold(-goldCost))
throw new RuntimeException("Unable to subtract gold despite valid check!");
inhabitants.add(i);
return true;
} else return false;
} }
public int getGuardTime() { public int getGuardTime() {

View File

@ -2,8 +2,6 @@ package ca.cosc3p91.a2.gameobjects;
public class Archer extends Infantry { public class Archer extends Infantry {
static int cost = 4;
public Archer() { public Archer() {
super(90, 2, 10); super(90, 2, 10);
} }
@ -24,13 +22,7 @@ public class Archer extends Infantry {
} }
@Override @Override
public int getCost() { public int setLevel(int level) {
return cost; return super.setLevel(level);
} }
@Override
public void setLevel(int level) {
}
} }

View File

@ -1,9 +1,4 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
public class ArcherTower extends DefenseBuilding { public class ArcherTower extends DefenseBuilding {
public ArcherTower() {
setLevel(1);
upgrade(DefenseStages.archerTowerStages[0]);
}
} }

View File

@ -1,9 +1,4 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
public class Cannon extends DefenseBuilding { public class Cannon extends DefenseBuilding {
public Cannon() {
setLevel(1);
upgrade(DefenseStages.cannonStages[0]);
}
} }

View File

@ -2,8 +2,6 @@ package ca.cosc3p91.a2.gameobjects;
public class Catapult extends Infantry { public class Catapult extends Infantry {
static int cost = 6;
public Catapult() { public Catapult() {
super(80, 12, 12); super(80, 12, 12);
} }
@ -24,12 +22,7 @@ public class Catapult extends Infantry {
} }
@Override @Override
public int getCost() { public int setLevel(int level) {
return cost; return super.setLevel(level);
}
@Override
public void setLevel(int level) {
} }
} }

View File

@ -1,37 +1,11 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
public class Collector implements Inhabitant { public class Collector {
private int averageCollectionRate; private int averageCollectionRate;
static int cost = 2;
public int getCollectionRate() { public int getCollectionRate() {
return averageCollectionRate; return averageCollectionRate;
} }
@Override
public void move(Tile t) {
}
@Override
public void getPosition() {
}
@Override
public int getLevel() {
return Inhabitant.super.getLevel();
}
@Override
public int getCost() {
return cost;
}
@Override
public void setLevel(int level) {
}
} }

View File

@ -2,8 +2,8 @@ package ca.cosc3p91.a2.gameobjects;
public class DefenseBuilding extends Building { public class DefenseBuilding extends Building {
private int damage = 0; private int damage;
private int range = 0; private int range;
public void upgrade(DefenseStage stage) { public void upgrade(DefenseStage stage) {
super.upgrade(stage); super.upgrade(stage);

View File

@ -4,42 +4,39 @@ import ca.cosc3p91.a2.util.Time;
public class DefenseStages { public class DefenseStages {
// !! need to adjust these values | |
// v v
public static class ArcherTowerStage1 extends DefenseStage { public static class ArcherTowerStage1 extends DefenseStage {
public ArcherTowerStage1() { public ArcherTowerStage1() {
super(100, 0, 0, new Time().offsetMinutes(1), 25, 75, 4,6); super(100, 0, 0, new Time().offsetMinutes(1), 25, 250, 4,6);
} }
} }
public static class ArcherTowerStage2 extends DefenseStage { public static class ArcherTowerStage2 extends DefenseStage {
public ArcherTowerStage2() { public ArcherTowerStage2() {
super(150, 50, 1, new Time().offsetMinutes(15), 25, 200, 8,8); super(150, 0, 1, new Time().offsetMinutes(15), 25, 250, 8,8);
} }
} }
public static class ArcherTowerStage3 extends DefenseStage { public static class ArcherTowerStage3 extends DefenseStage {
public ArcherTowerStage3() { public ArcherTowerStage3() {
super(200, 100, 2, new Time().offsetHours(1), 50, 300, 12,12); super(200, 0, 2, new Time().offsetHours(1), 25, 250, 12,12);
} }
} }
public static class CannonStage1 extends DefenseStage { public static class CannonStage1 extends DefenseStage {
public CannonStage1() { public CannonStage1() {
super(125, 0, 0, new Time().offsetMinutes(2), 100, 25, 8,4); super(125, 0, 0, new Time().offsetMinutes(2), 25, 250, 8,4);
} }
} }
public static class CannonStage2 extends DefenseStage { public static class CannonStage2 extends DefenseStage {
public CannonStage2() { public CannonStage2() {
super(175, 50, 1, new Time().offsetMinutes(20), 125, 25, 12,6); super(175, 0, 1, new Time().offsetMinutes(20), 25, 250, 12,6);
} }
} }
public static class CannonStage3 extends DefenseStage { public static class CannonStage3 extends DefenseStage {
public CannonStage3() { public CannonStage3() {
super(225, 100, 2, new Time().offsetHours(1), 200, 50, 14,8); super(225, 0, 2, new Time().offsetHours(1), 25, 250, 14,8);
} }
} }

View File

@ -15,8 +15,9 @@ public interface Inhabitant {
default int getLevel() { default int getLevel() {
return lvl; return lvl;
} }
int getCost();
void setLevel(int level); default int setLevel(int level) {
return lvl;
}
} }

View File

@ -2,8 +2,6 @@ package ca.cosc3p91.a2.gameobjects;
public class Knight extends Infantry { public class Knight extends Infantry {
static int cost = 6;
public Knight() { public Knight() {
super(150, 6, 6); super(150, 6, 6);
} }
@ -24,12 +22,7 @@ public class Knight extends Infantry {
} }
@Override @Override
public int getCost() { public int setLevel(int level) {
return cost; return super.setLevel(level);
}
@Override
public void setLevel(int level) {
} }
} }

View File

@ -2,8 +2,6 @@ package ca.cosc3p91.a2.gameobjects;
public class Soldier extends Infantry { public class Soldier extends Infantry {
static int cost = 4;
public Soldier() { public Soldier() {
super(100, 4, 4); super(100, 4, 4);
} }
@ -24,12 +22,7 @@ public class Soldier extends Infantry {
} }
@Override @Override
public int getCost() { public int setLevel(int level) {
return cost; return super.setLevel(level);
}
@Override
public void setLevel(int level) {
} }
} }

View File

@ -4,8 +4,6 @@ public class Worker implements Inhabitant {
private boolean currentlyBuilding; private boolean currentlyBuilding;
static int cost = 2;
public void set_IsBuilding(boolean state) { public void set_IsBuilding(boolean state) {
currentlyBuilding = state; currentlyBuilding = state;
} }
@ -30,12 +28,7 @@ public class Worker implements Inhabitant {
} }
@Override @Override
public int getCost() { public int setLevel(int level) {
return cost; return Inhabitant.super.setLevel(level);
}
@Override
public void setLevel(int level) {
} }
} }