Compare commits

...

7 Commits

Author SHA1 Message Date
mike e6a9b410c9 Instant upgrade working 2023-03-06 20:48:04 -05:00
mike ba7821dfd9 Added basic upgrading functionality 2023-03-06 18:55:03 -05:00
Brett 1ebfdca6c9 Merge remote-tracking branch 'refs/remotes/origin/main' 2023-03-06 18:01:58 -05:00
Brett aba8b47045 bit of sexual calculations based on michaels cum 2023-03-06 18:01:38 -05:00
mike 31a9f97618 minor menu changes 2023-03-06 17:17:28 -05:00
Brett c8e301f9cc Break my heart 2023-03-06 17:12:30 -05:00
Brett 33feedc3b1 fix weird generic function 2023-03-06 16:45:35 -05:00
18 changed files with 253 additions and 67 deletions

View File

@ -21,7 +21,7 @@ public class GameEngine<T> implements Runnable {
private Player player; private Player player;
boolean running = true; boolean running = true;
private int pillageFactor; private float pillageFactor = 0.5f;
private int currentTime; private int currentTime;
@ -65,7 +65,7 @@ public class GameEngine<T> implements Runnable {
for (Building b : map.contains) for (Building b : map.contains)
buildingPrinter.addRow(new Print.Row(b.getClass().getSimpleName(), buildingPrinter.addRow(new Print.Row(b.getClass().getSimpleName(),
Integer.toString(b.getLevel()), Integer.toString(b.getLevel() + 1),
Integer.toString(b.getHealth()))); Integer.toString(b.getHealth())));
Print.print(buildingPrinter.createTable(true, false, true)); Print.print(buildingPrinter.createTable(true, false, true));
@ -75,23 +75,40 @@ public class GameEngine<T> implements Runnable {
inhabs.addColumn(new Print.Column("Level")); inhabs.addColumn(new Print.Column("Level"));
for (Inhabitant i : map.inhabitants) for (Inhabitant i : map.inhabitants)
inhabs.addRow(new Print.Row(i.getClass().getSimpleName(), Integer.toString(i.getLevel()))); inhabs.addRow(new Print.Row(i.getClass().getSimpleName(), Integer.toString(i.getLevel() + 1)));
Print.print(inhabs.createTable(true, true, true)); Print.print(inhabs.createTable(true, true, true));
} }
private void printMenuOptions() { private void printMenuOptions() {
System.out.println("~ Player Options:\n" + System.out.println("\n~ Player Options:\n" +
"1. Build {command: '1 <building name>'}\n" + "1. Build {command: '1 <building name>'}\n" +
"2. Train inhabitants {command: '2 <unit name>'}\n"+ "2. Train inhabitants {command: '2 <unit name>'}\n"+
"3. Upgrade Building\n"+ "3. Upgrade Building {command: '3 i<index>'} / {command: '3 b<index>'}\n"+
"4. Explore\n"+ "4. Explore\n"+
"5. Check Village Stats\n"+ "5. Attack\n"+
"6. Quit"); "5. Print Village Stats\n"+
"6. Quit\n" +
"7. Attack last explored\n");
} }
public void attackVillage(Map map) { public void attackVillage(Map map) {
int defenseiveCounter = 1;
int inhabCounter = 0;
for (Building b : map.contains)
if (b instanceof DefenseBuilding)
defenseiveCounter++;
for (Inhabitant i : map.inhabitants)
if (i instanceof Infantry)
inhabCounter++;
pillageFactor = (float) inhabCounter / (float) defenseiveCounter;
if (pillageFactor < 0)
pillageFactor = 0;
if (pillageFactor > 1)
pillageFactor = 1;
this.map.getTownHall().addWood((int) (map.getTownHall().getCurrentWood() * pillageFactor));
this.map.getTownHall().addIron((int) (map.getTownHall().getCurrentIron() * pillageFactor));
this.map.getTownHall().addGold((int) (map.getTownHall().getCurrentGold() * pillageFactor));
} }
private Map generateInitialMap(){ private Map generateInitialMap(){
@ -100,12 +117,19 @@ public class GameEngine<T> implements Runnable {
public Map generateMap() { public Map generateMap() {
Map initialMap = generateInitialMap(); Map initialMap = generateInitialMap();
CasaDeNarino hall = initialMap.getTownHall();
// generate a similar town hall // generate a similar town hall
int levelChange = random.nextInt(2) - 1; int levelChange = random.nextInt(2) - 1;
int nextLevel = this.map.getTownHall().getLevel() + levelChange; int nextLevel = this.map.getTownHall().getLevel() + levelChange;
// only need to change if the new village level is higher than initial // only need to change if the new village level is higher than initial
if (nextLevel > 0) if (nextLevel > 0)
initialMap.getTownHall().upgrade(VillageHallStages.villageStages[nextLevel]); hall.upgrade(VillageHallStages.villageStages[nextLevel]);
hall.addWood(this.map.getTownHall().getCurrentWood() + random.nextInt(500) - 150);
hall.addIron(this.map.getTownHall().getCurrentIron() + random.nextInt(500) - 150);
hall.addGold(this.map.getTownHall().getCurrentGold() + random.nextInt(500) - 150);
int buildingCount = this.map.contains.size(); int buildingCount = this.map.contains.size();
@ -182,6 +206,8 @@ public class GameEngine<T> implements Runnable {
printState(this.map,"Current Village State"); printState(this.map,"Current Village State");
printMenuOptions(); printMenuOptions();
System.out.println(); System.out.println();
Map exploringMap = null;
boolean deleteMyHeart = true;
while (running) { while (running) {
for (Building b : this.map.contains){ for (Building b : this.map.contains){
if ((b instanceof ResourceBuilding)) { if ((b instanceof ResourceBuilding)) {
@ -193,25 +219,29 @@ public class GameEngine<T> implements Runnable {
String in = sc.nextLine(); String in = sc.nextLine();
String[] args = in.split(" "); String[] args = in.split(" ");
System.out.println("Your Input: "); System.out.println("Your Input: ");
System.out.println("\t->" + in); System.out.println("\t->" + in + '\n');
// reset the map if they aren't exploring
if (in.charAt(0) != '4')
deleteMyHeart = true;
switch (in.charAt(0)) { switch (in.charAt(0)) {
case '1': case '1':
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 = determineBuildingType(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 if (this.map.build(new Tile(), type) ) {
System.out.println(type.getClass().getSimpleName()+" successfully built\n"); System.out.println(type.getClass().getSimpleName()+" successfully built\n");
} else System.out.println("Missing resources to build "+type.getClass().getSimpleName()); } else
System.out.println("Missing resources to build "+type.getClass().getSimpleName());
} }
break; break;
case '2': case '2':
if (args.length < 2) { if (args.length < 2) {
System.err.println("Args must include type!"); System.err.println("Args must include type!");
} else { } else {
Inhabitant type = (Inhabitant)determineType(args[1],new Worker()); Inhabitant type = determineInhabitantType(args[1]);
if (type == null) if (type == null)
System.err.println("Args are not a valid inhabitant!"); System.err.println("Args are not a valid inhabitant!");
else if (this.map.train(type) ) { else if (this.map.train(type) ) {
@ -219,8 +249,43 @@ public class GameEngine<T> implements Runnable {
} else System.out.println("Missing gold to train "+type.getClass().getSimpleName()); } else System.out.println("Missing gold to train "+type.getClass().getSimpleName());
} }
break; break;
case '3':
if (args.length < 2) {
System.err.println("Args must include type!");
} else {
int unitIndex = Integer.parseInt(args[1].substring(1));
if (unitIndex < 0) {
System.err.println("Invalid Index");
break;
}
if (args[1].contains("i") && (unitIndex < map.inhabitants.size()) ) {
if ( map.upgradeInhabitant(unitIndex) ) {
System.out.println("successfully upgraded a(n) "+map.inhabitants.get(unitIndex).getClass().getSimpleName());
} else System.out.println("Missing Resources to upgrade "+map.inhabitants.get(unitIndex).getClass().getSimpleName());
} else if (args[1].contains("b") && (unitIndex < map.contains.size()) ) {
if ( map.upgradeBuilding(unitIndex) ) {
System.out.println("successfully upgraded a(n) "+map.contains.get(unitIndex).getClass().getSimpleName());
} else System.out.println("Missing Resources to upgrade "+map.contains.get(unitIndex).getClass().getSimpleName());
} else {
System.err.println("Args are not a valid unit!");
}
}
break;
case '4':
deleteMyHeart = false;
exploringMap = generateMap();
printState(exploringMap, "Other Village");
break;
case '7':
if (exploringMap != null)
attackVillage(exploringMap);
else
System.out.println("Error: Explored map is null. Have you explored last command?");
break;
case '5': case '5':
printState(this.map,"Current Village State"); printState(this.map,"Home Village");
break; break;
case '6': case '6':
System.exit(0); System.exit(0);
@ -230,45 +295,58 @@ public class GameEngine<T> implements Runnable {
} }
printMenuOptions(); printMenuOptions();
} }
} catch (IOException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if (deleteMyHeart)
exploringMap = null;
} }
} }
private static <T> Object determineType(String argument, T type){ private static char determineChar(String str){
argument = argument.toLowerCase();
char c = ' '; char c = ' ';
if (argument.trim().length() == 1) if (str.trim().length() == 1)
c = argument.charAt(0); c = str.charAt(0);
return c;
}
if (type instanceof Building) { private static Building determineBuildingType(String argument){
if (argument.contains("gold") || argument.contains("good") || c == 'g') { argument = argument.toLowerCase();
return new SaulGoodMine(ResourceStages.goldStages[0]); char c = determineChar(argument);
} else if (argument.contains("iron") || c == 'i') {
return new IronMine(ResourceStages.ironStages[0]); if (argument.contains("gold") || argument.contains("good") || c == 'g') {
} else if (argument.contains("wood") || argument.contains("lumber") || c == 'w' || c == 'l') { return new SaulGoodMine(ResourceStages.goldStages[0]);
return new LumberMine(ResourceStages.woodStages[0]); } else if (argument.contains("iron") || c == 'i') {
} else if (argument.contains("archer") || c == 'a') { return new IronMine(ResourceStages.ironStages[0]);
return new ArcherTower(); } else if (argument.contains("wood") || argument.contains("lumber") || c == 'w' || c == 'l') {
} else if (argument.contains("can") || c == 'c') { return new LumberMine(ResourceStages.woodStages[0]);
return new Cannon(); } else if (argument.contains("archer") || c == 'a') {
} return new ArcherTower();
} else if (type instanceof Inhabitant) { } else if (argument.contains("can") || c == 'c') {
if (argument.contains("soldier") || argument.contains("sold") || c == 's') { return new Cannon();
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;
}
private static Inhabitant determineInhabitantType(String argument) {
argument = argument.toLowerCase();
char c = determineChar(argument);
if (argument.contains("soldier") || 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

@ -49,7 +49,70 @@ public class Map {
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; return true;
} else
return false;
}
public boolean upgradeBuilding(int buildingIndex) {
if (buildingIndex >= contains.size()) return false;
Building b = contains.get(buildingIndex);
int currentLevel = b.getLevel();
CasaDeNarino hall = getTownHall();
if (currentLevel >= 2) return false;
else if (b instanceof Farm) return true;
int goldCost = b.getUpgradeStage().getCost(SaulGoodMine.resource);
int ironCost = b.getUpgradeStage().getCost(IronMine.resource);
int woodCost = b.getUpgradeStage().getCost(LumberMine.resource);
if (hall.getCurrentGold() >= goldCost && hall.getCurrentIron() >= ironCost && hall.getCurrentWood() >= woodCost) {
if (b instanceof DefenseBuilding) {
((DefenseBuilding) b).upgrade(
(b instanceof ArcherTower) ? (DefenseStages.archerTowerStages[currentLevel + 1]) :
(DefenseStages.cannonStages[currentLevel + 1])
);
} else if (b instanceof ResourceBuilding) {
((ResourceBuilding) b).upgrade(
(b instanceof IronMine) ? (ResourceStages.ironStages[currentLevel + 1]) :
(b instanceof SaulGoodMine) ? (ResourceStages.goldStages[currentLevel + 1]) :
(ResourceStages.woodStages[currentLevel + 1])
);
} else {
b.upgrade(VillageHallStages.villageStages[currentLevel + 1]);
}
} else return false; } else return false;
return true;
}
public boolean upgradeInhabitant(int inhabitantIndex) {
if (inhabitantIndex >= inhabitants.size()) return false;
Inhabitant i = inhabitants.get(inhabitantIndex);
int currentLevel = i.getLevel();
CasaDeNarino hall = getTownHall();
if (currentLevel >= 2 || hall.getCurrentGold() < 5) return false;
i.setLevel(++currentLevel);
hall.addGold(-5);
if (i instanceof Infantry) {
((Infantry) i).setHealth(((Infantry) i).getHealth() + 1);
((Infantry) i).setDamage(((Infantry) i).getDamage() + 1);
((Infantry) i).setRange(((Infantry) i).getRange() + 1);
} else if (i instanceof Collector) {
((Collector) i).setCollectionRate(((Collector) i).getCollectionRate() + 1);
}
return true;
} }
public boolean train(Inhabitant i) { public boolean train(Inhabitant i) {

View File

@ -4,6 +4,8 @@ public class Archer extends Infantry {
static int cost = 4; static int cost = 4;
private int lvl = 0;
public Archer() { public Archer() {
super(90, 2, 10); super(90, 2, 10);
} }
@ -20,7 +22,7 @@ public class Archer extends Infantry {
@Override @Override
public int getLevel() { public int getLevel() {
return super.getLevel(); return lvl;
} }
@Override @Override
@ -30,7 +32,7 @@ public class Archer extends Infantry {
@Override @Override
public void setLevel(int level) { public void setLevel(int level) {
lvl = level;
} }
} }

View File

@ -6,4 +6,9 @@ public class ArcherTower extends DefenseBuilding {
setLevel(1); setLevel(1);
upgrade(DefenseStages.archerTowerStages[0]); upgrade(DefenseStages.archerTowerStages[0]);
} }
@Override
public Stage getUpgradeStage() {
return DefenseStages.archerTowerStages[getLevel()+1];
}
} }

View File

@ -38,9 +38,7 @@ public abstract class Building {
return stage; return stage;
} }
public int getUpgradeCost() { public abstract Stage getUpgradeStage();
return 0;
}
public void setLevel(int level) { public void setLevel(int level) {
this.level = level; this.level = level;

View File

@ -6,4 +6,9 @@ public class Cannon extends DefenseBuilding {
setLevel(1); setLevel(1);
upgrade(DefenseStages.cannonStages[0]); upgrade(DefenseStages.cannonStages[0]);
} }
@Override
public Stage getUpgradeStage() {
return DefenseStages.cannonStages[getLevel()+1];
}
} }

View File

@ -15,6 +15,11 @@ public class CasaDeNarino extends Building {
upgrade(baseStage); upgrade(baseStage);
} }
@Override
public Stage getUpgradeStage() {
return VillageHallStages.villageStages[getLevel()+1];
}
public void upgrade(VillageStage stage) { public void upgrade(VillageStage stage) {
super.upgrade(stage); super.upgrade(stage);
this.goldCapacity += stage.getGoldCapacityIncrease(); this.goldCapacity += stage.getGoldCapacityIncrease();

View File

@ -4,6 +4,8 @@ public class Catapult extends Infantry {
static int cost = 6; static int cost = 6;
private int lvl = 0;
public Catapult() { public Catapult() {
super(80, 12, 12); super(80, 12, 12);
} }
@ -20,7 +22,7 @@ public class Catapult extends Infantry {
@Override @Override
public int getLevel() { public int getLevel() {
return super.getLevel(); return lvl;
} }
@Override @Override
@ -30,6 +32,6 @@ public class Catapult extends Infantry {
@Override @Override
public void setLevel(int level) { public void setLevel(int level) {
lvl = level;
} }
} }

View File

@ -6,10 +6,16 @@ public class Collector implements Inhabitant {
static int cost = 2; static int cost = 2;
private int lvl = 0;
public int getCollectionRate() { public int getCollectionRate() {
return averageCollectionRate; return averageCollectionRate;
} }
public void setCollectionRate(int rate) {
averageCollectionRate = rate;
}
@Override @Override
public void move(Tile t) { public void move(Tile t) {
@ -22,7 +28,7 @@ public class Collector implements Inhabitant {
@Override @Override
public int getLevel() { public int getLevel() {
return Inhabitant.super.getLevel(); return lvl;
} }
@Override @Override
@ -32,6 +38,6 @@ public class Collector implements Inhabitant {
@Override @Override
public void setLevel(int level) { public void setLevel(int level) {
lvl = level;
} }
} }

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects; package ca.cosc3p91.a2.gameobjects;
public class DefenseBuilding extends Building { public abstract class DefenseBuilding extends Building {
private int damage = 0; private int damage = 0;
private int range = 0; private int range = 0;

View File

@ -15,4 +15,9 @@ public class Farm extends ResourceBuilding {
protected ResourceHarvestHandler getHarvestHandler() { protected ResourceHarvestHandler getHarvestHandler() {
return hall -> {}; return hall -> {};
} }
@Override
public Stage getUpgradeStage() {
return ResourceStages.goldStages[getLevel()+1];
}
} }

View File

@ -6,17 +6,14 @@ public interface Inhabitant {
Map map = null; Map map = null;
Building building = null; Building building = null;
int lvl = 1; int lvl = 0;
void move(Tile t); void move(Tile t);
void getPosition(); void getPosition();
default int getLevel() { int getLevel();
return lvl; void setLevel(int level);
}
int getCost(); int getCost();
void setLevel(int level);
} }

View File

@ -12,4 +12,9 @@ public class IronMine extends ResourceBuilding {
protected ResourceHarvestHandler getHarvestHandler() { protected ResourceHarvestHandler getHarvestHandler() {
return hall -> hall.addIron(getHarvestRate()); return hall -> hall.addIron(getHarvestRate());
} }
@Override
public Stage getUpgradeStage() {
return ResourceStages.ironStages[getLevel()+1];
}
} }

View File

@ -4,6 +4,8 @@ public class Knight extends Infantry {
static int cost = 6; static int cost = 6;
private int lvl = 0;
public Knight() { public Knight() {
super(150, 6, 6); super(150, 6, 6);
} }
@ -20,7 +22,7 @@ public class Knight extends Infantry {
@Override @Override
public int getLevel() { public int getLevel() {
return super.getLevel(); return lvl;
} }
@Override @Override
@ -30,6 +32,6 @@ public class Knight extends Infantry {
@Override @Override
public void setLevel(int level) { public void setLevel(int level) {
lvl = level;
} }
} }

View File

@ -13,4 +13,8 @@ public class LumberMine extends ResourceBuilding {
return hall -> hall.addWood(getHarvestRate()); return hall -> hall.addWood(getHarvestRate());
} }
@Override
public Stage getUpgradeStage() {
return ResourceStages.woodStages[getLevel()+1];
}
} }

View File

@ -12,4 +12,9 @@ public class SaulGoodMine extends ResourceBuilding {
protected ResourceHarvestHandler getHarvestHandler() { protected ResourceHarvestHandler getHarvestHandler() {
return hall -> hall.addGold(getHarvestRate()); return hall -> hall.addGold(getHarvestRate());
} }
@Override
public Stage getUpgradeStage() {
return ResourceStages.goldStages[getLevel()+1];
}
} }

View File

@ -4,6 +4,8 @@ public class Soldier extends Infantry {
static int cost = 4; static int cost = 4;
int lvl = 0;
public Soldier() { public Soldier() {
super(100, 4, 4); super(100, 4, 4);
} }
@ -20,7 +22,7 @@ public class Soldier extends Infantry {
@Override @Override
public int getLevel() { public int getLevel() {
return super.getLevel(); return lvl;
} }
@Override @Override
@ -30,6 +32,6 @@ public class Soldier extends Infantry {
@Override @Override
public void setLevel(int level) { public void setLevel(int level) {
lvl = level;
} }
} }

View File

@ -6,6 +6,8 @@ public class Worker implements Inhabitant {
static int cost = 2; static int cost = 2;
private int lvl = 0;
public void set_IsBuilding(boolean state) { public void set_IsBuilding(boolean state) {
currentlyBuilding = state; currentlyBuilding = state;
} }
@ -26,7 +28,7 @@ public class Worker implements Inhabitant {
@Override @Override
public int getLevel() { public int getLevel() {
return Inhabitant.super.getLevel(); return lvl;
} }
@Override @Override
@ -36,6 +38,6 @@ public class Worker implements Inhabitant {
@Override @Override
public void setLevel(int level) { public void setLevel(int level) {
lvl = level;
} }
} }