Created single merged determineType for building args & balanced defense stage costs

main
mike 2023-03-05 20:58:35 -05:00
parent 781807ea70
commit 349d908486
2 changed files with 40 additions and 44 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 implements Runnable { public class GameEngine<T> 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;
@ -188,7 +188,6 @@ public class GameEngine implements Runnable {
((ResourceBuilding) b).update(this.map.getTownHall()); ((ResourceBuilding) b).update(this.map.getTownHall());
} }
} }
//System.out.println("Updating");
try { try {
if (rd.ready()) { if (rd.ready()) {
String in = sc.nextLine(); String in = sc.nextLine();
@ -200,7 +199,7 @@ public class GameEngine 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 {
Building type = determineType(args[1]); Building type = (Building)determineType(args[1],new Cannon());
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) ) {
@ -212,7 +211,7 @@ public class GameEngine 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 {
Inhabitant type = determineInhabitantType(args[1]); Inhabitant type = (Inhabitant)determineType(args[1],new Worker());
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) ) {
@ -237,43 +236,40 @@ public class GameEngine implements Runnable {
} }
} }
private static Building determineType(String building){ private static <T> Object determineType(String argument, T type){
building = building.toLowerCase(); argument = argument.toLowerCase();
char c = ' '; char c = ' ';
if (building.trim().length() == 1) if (argument.trim().length() == 1)
c = building.charAt(0); c = argument.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 (building.contains("iron") || c == 'i') { } else if (argument.contains("iron") || c == 'i') {
return new IronMine(ResourceStages.ironStages[0]); return new IronMine(ResourceStages.ironStages[0]);
} else if (building.contains("wood") || building.contains("lumber") || c == 'w' || c == 'l') { } else if (argument.contains("wood") || argument.contains("lumber") || c == 'w' || c == 'l') {
return new LumberMine(ResourceStages.woodStages[0]); return new LumberMine(ResourceStages.woodStages[0]);
} else if (building.contains("archer") || c == 'a') { } else if (argument.contains("archer") || c == 'a') {
return new ArcherTower(); return new ArcherTower();
} else if (building.contains("can") || c == 'c'){ } else if (argument.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;
} }
private static Inhabitant determineInhabitantType(String inhabitant){
inhabitant = inhabitant.toLowerCase();
char c = ' ';
if (inhabitant.trim().length() == 1)
c = inhabitant.charAt(0);
if (inhabitant.contains("soldier") || inhabitant.contains("sold") || c == 's') {
return new Soldier();
} else if (inhabitant.contains("knight") || c == 'k') {
return new Knight();
} else if (inhabitant.contains("work")|| c == 'w') {
return new Worker();
} else if (inhabitant.contains("collect") || c == 'c') {
return new Collector();
} else if (inhabitant.contains("cat")){
return new Catapult();
} else if (inhabitant.contains("archer") || c == 'a'){
return new Archer();
}
return null;
}
} }

View File

@ -9,37 +9,37 @@ public class DefenseStages {
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, 250, 4,6); super(100, 0, 0, new Time().offsetMinutes(1), 25, 75, 4,6);
} }
} }
public static class ArcherTowerStage2 extends DefenseStage { public static class ArcherTowerStage2 extends DefenseStage {
public ArcherTowerStage2() { public ArcherTowerStage2() {
super(150, 0, 1, new Time().offsetMinutes(15), 25, 250, 8,8); super(150, 50, 1, new Time().offsetMinutes(15), 25, 200, 8,8);
} }
} }
public static class ArcherTowerStage3 extends DefenseStage { public static class ArcherTowerStage3 extends DefenseStage {
public ArcherTowerStage3() { public ArcherTowerStage3() {
super(200, 0, 2, new Time().offsetHours(1), 25, 250, 12,12); super(200, 100, 2, new Time().offsetHours(1), 50, 300, 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), 25, 250, 8,4); super(125, 0, 0, new Time().offsetMinutes(2), 100, 25, 8,4);
} }
} }
public static class CannonStage2 extends DefenseStage { public static class CannonStage2 extends DefenseStage {
public CannonStage2() { public CannonStage2() {
super(175, 0, 1, new Time().offsetMinutes(20), 25, 250, 12,6); super(175, 50, 1, new Time().offsetMinutes(20), 125, 25, 12,6);
} }
} }
public static class CannonStage3 extends DefenseStage { public static class CannonStage3 extends DefenseStage {
public CannonStage3() { public CannonStage3() {
super(225, 0, 2, new Time().offsetHours(1), 25, 250, 14,8); super(225, 100, 2, new Time().offsetHours(1), 200, 50, 14,8);
} }
} }