Instant upgrade working

main
mike 2023-03-06 20:48:04 -05:00
parent ba7821dfd9
commit e6a9b410c9
2 changed files with 30 additions and 15 deletions

View File

@ -81,7 +81,7 @@ public class GameEngine<T> implements Runnable {
} }
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 {command: '3 i<index>'} / {command: '3 b<index>'}\n"+ "3. Upgrade Building {command: '3 i<index>'} / {command: '3 b<index>'}\n"+
@ -219,7 +219,7 @@ 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 // reset the map if they aren't exploring
if (in.charAt(0) != '4') if (in.charAt(0) != '4')
deleteMyHeart = true; deleteMyHeart = true;
@ -253,16 +253,21 @@ public class GameEngine<T> implements Runnable {
if (args.length < 2) { if (args.length < 2) {
System.err.println("Args must include type!"); System.err.println("Args must include type!");
} else { } else {
if (args[1].contains("i")) { int unitIndex = Integer.parseInt(args[1].substring(1));
Inhabitant unit = map.inhabitants.get(Integer.parseInt(args[1].substring(1)));
if (map.upgradeInhabitant(unit) ){ if (unitIndex < 0) {
System.out.println("successfully trained a(n)"+unit.getClass().getSimpleName()); System.err.println("Invalid Index");
} else System.out.println("Missing Resources to train "+unit.getClass().getSimpleName()); break;
} else if (args[1].contains("b")) { }
Building bUnit = map.contains.get(Integer.parseInt(args[1].substring(1)));
if (map.upgradeBuilding(bUnit) ){ if (args[1].contains("i") && (unitIndex < map.inhabitants.size()) ) {
System.out.println("successfully trained a(n)"+bUnit.getClass().getSimpleName()); if ( map.upgradeInhabitant(unitIndex) ) {
} else System.out.println("Missing Resources to train "+bUnit.getClass().getSimpleName()); 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 { } else {
System.err.println("Args are not a valid unit!"); System.err.println("Args are not a valid unit!");
} }

View File

@ -53,12 +53,17 @@ public class Map {
return false; return false;
} }
public boolean upgradeBuilding(Building b) { public boolean upgradeBuilding(int buildingIndex) {
if (buildingIndex >= contains.size()) return false;
Building b = contains.get(buildingIndex);
int currentLevel = b.getLevel(); int currentLevel = b.getLevel();
CasaDeNarino hall = getTownHall(); CasaDeNarino hall = getTownHall();
if (currentLevel >= 2) return false; if (currentLevel >= 2) return false;
if (b instanceof Farm) return true; else if (b instanceof Farm) return true;
int goldCost = b.getUpgradeStage().getCost(SaulGoodMine.resource); int goldCost = b.getUpgradeStage().getCost(SaulGoodMine.resource);
int ironCost = b.getUpgradeStage().getCost(IronMine.resource); int ironCost = b.getUpgradeStage().getCost(IronMine.resource);
@ -85,7 +90,12 @@ public class Map {
return true; return true;
} }
public boolean upgradeInhabitant(Inhabitant i) { public boolean upgradeInhabitant(int inhabitantIndex) {
if (inhabitantIndex >= inhabitants.size()) return false;
Inhabitant i = inhabitants.get(inhabitantIndex);
int currentLevel = i.getLevel(); int currentLevel = i.getLevel();
CasaDeNarino hall = getTownHall(); CasaDeNarino hall = getTownHall();