Added basic upgrading functionality
parent
1ebfdca6c9
commit
ba7821dfd9
|
@ -99,7 +99,7 @@ public class GameEngine<T> implements Runnable {
|
||||||
if (b instanceof DefenseBuilding)
|
if (b instanceof DefenseBuilding)
|
||||||
defenseiveCounter++;
|
defenseiveCounter++;
|
||||||
for (Inhabitant i : map.inhabitants)
|
for (Inhabitant i : map.inhabitants)
|
||||||
if (b instanceof Infantry)
|
if (i instanceof Infantry)
|
||||||
inhabCounter++;
|
inhabCounter++;
|
||||||
pillageFactor = (float) inhabCounter / (float) defenseiveCounter;
|
pillageFactor = (float) inhabCounter / (float) defenseiveCounter;
|
||||||
if (pillageFactor < 0)
|
if (pillageFactor < 0)
|
||||||
|
@ -250,6 +250,23 @@ public class GameEngine<T> implements Runnable {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
|
if (args.length < 2) {
|
||||||
|
System.err.println("Args must include type!");
|
||||||
|
} else {
|
||||||
|
if (args[1].contains("i")) {
|
||||||
|
Inhabitant unit = map.inhabitants.get(Integer.parseInt(args[1].substring(1)));
|
||||||
|
if (map.upgradeInhabitant(unit) ){
|
||||||
|
System.out.println("successfully trained a(n)"+unit.getClass().getSimpleName());
|
||||||
|
} else System.out.println("Missing Resources to train "+unit.getClass().getSimpleName());
|
||||||
|
} else if (args[1].contains("b")) {
|
||||||
|
Building bUnit = map.contains.get(Integer.parseInt(args[1].substring(1)));
|
||||||
|
if (map.upgradeBuilding(bUnit) ){
|
||||||
|
System.out.println("successfully trained a(n)"+bUnit.getClass().getSimpleName());
|
||||||
|
} else System.out.println("Missing Resources to train "+bUnit.getClass().getSimpleName());
|
||||||
|
} else {
|
||||||
|
System.err.println("Args are not a valid unit!");
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '4':
|
case '4':
|
||||||
deleteMyHeart = false;
|
deleteMyHeart = false;
|
||||||
|
|
|
@ -53,6 +53,58 @@ public class Map {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean upgradeBuilding(Building b) {
|
||||||
|
int currentLevel = b.getLevel();
|
||||||
|
CasaDeNarino hall = getTownHall();
|
||||||
|
|
||||||
|
if (currentLevel >= 2) return false;
|
||||||
|
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;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean upgradeInhabitant(Inhabitant i) {
|
||||||
|
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) {
|
||||||
CasaDeNarino hall = getTownHall();
|
CasaDeNarino hall = getTownHall();
|
||||||
int goldCost = i.getCost();
|
int goldCost = i.getCost();
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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];
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
|
|
@ -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];
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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();
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue