Updating + stages
parent
f476bfc80f
commit
debb59bc39
|
@ -1,10 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RunConfigurationProducerService">
|
|
||||||
<option name="ignoredProducers">
|
|
||||||
<set>
|
|
||||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -5,9 +5,7 @@ import ca.cosc3p91.a2.game.GameEngine;
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
GameEngine engine = new GameEngine();
|
new GameEngine().run();
|
||||||
|
|
||||||
engine.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,11 @@ package ca.cosc3p91.a2.game;
|
||||||
import ca.cosc3p91.a2.gameobjects.*;
|
import ca.cosc3p91.a2.gameobjects.*;
|
||||||
import ca.cosc3p91.a2.player.*;
|
import ca.cosc3p91.a2.player.*;
|
||||||
import ca.cosc3p91.a2.util.Print;
|
import ca.cosc3p91.a2.util.Print;
|
||||||
|
import ca.cosc3p91.a2.util.Time;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class GameEngine implements Runnable {
|
public class GameEngine implements Runnable {
|
||||||
|
@ -19,9 +23,7 @@ public class GameEngine implements Runnable {
|
||||||
|
|
||||||
public GameEngine() {
|
public GameEngine() {
|
||||||
player = new Player();
|
player = new Player();
|
||||||
VillageStage vInitialStage = new VillageStage(100, 0, 2, 30, 0,
|
map = generateMap();
|
||||||
0, 1000, 2500, 5000);
|
|
||||||
map = new Map(new VillageHall(1, vInitialStage), 30);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printState() {
|
private void printState() {
|
||||||
|
@ -71,21 +73,52 @@ public class GameEngine implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attackVillage(Map map) {
|
public void attackVillage(Map map) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map generateInitialMap(){
|
||||||
|
VillageStage villageHallInitialStage = new VillageStage(100, 0, 2, new Time(), 0,
|
||||||
|
0, 1000, 2500, 5000);
|
||||||
|
return new Map(new CasaDeNarino(1, villageHallInitialStage), 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map generateMap() {
|
public Map generateMap() {
|
||||||
return null;
|
Map initialMap = generateInitialMap();
|
||||||
|
initialMap.build(new Tile(), new SaulGoodMine(1, new ResourceStage(50, 0, 0, new Time(), 0, 0, 25)));
|
||||||
|
return initialMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getScore(Map map) {
|
public void getScore(Map map) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Scanner sc = new Scanner(System.in);
|
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
|
||||||
while (running) {
|
Scanner sc = new Scanner(rd);
|
||||||
printState();
|
printState();
|
||||||
int in = sc.nextInt();
|
System.out.println();
|
||||||
|
while (running) {
|
||||||
|
for (Building b : map.contains){
|
||||||
|
if ((b instanceof ResourceBuilding)) {
|
||||||
|
((ResourceBuilding) b).update(map.getTownHall());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println("Updating");
|
||||||
|
try {
|
||||||
|
if (rd.ready()) {
|
||||||
|
char in = sc.next().charAt(0);
|
||||||
|
switch (in) {
|
||||||
|
case 'p':
|
||||||
|
printState();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class Map {
|
||||||
|
|
||||||
static int MAXSIZE = 400;
|
static int MAXSIZE = 400;
|
||||||
|
|
||||||
private VillageHall townHall;
|
private CasaDeNarino townHall;
|
||||||
|
|
||||||
private int guardTime;
|
private int guardTime;
|
||||||
|
|
||||||
|
@ -17,11 +17,11 @@ public class Map {
|
||||||
|
|
||||||
public List<Inhabitant> inhabitants;
|
public List<Inhabitant> inhabitants;
|
||||||
|
|
||||||
public Map(VillageHall villageHall, int gTime) {
|
public Map(CasaDeNarino casaDeNarino, int gTime) {
|
||||||
contains = new ArrayList<>();
|
contains = new ArrayList<>();
|
||||||
inhabitants = new ArrayList<>();
|
inhabitants = new ArrayList<>();
|
||||||
this.townHall = villageHall;
|
this.townHall = casaDeNarino;
|
||||||
this.contains.add(villageHall);
|
this.contains.add(casaDeNarino);
|
||||||
this.guardTime = gTime;
|
this.guardTime = gTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class Map {
|
||||||
this.guardTime = gTime;
|
this.guardTime = gTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VillageHall getTownHall(){
|
public CasaDeNarino getTownHall(){
|
||||||
return townHall;
|
return townHall;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package ca.cosc3p91.a2.gameobjects;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class VillageHall extends Building {
|
public class CasaDeNarino extends Building {
|
||||||
|
|
||||||
private int goldCapacity = 0;
|
private int goldCapacity = 0;
|
||||||
private int ironCapacity = 0;
|
private int ironCapacity = 0;
|
||||||
|
@ -12,7 +12,7 @@ public class VillageHall extends Building {
|
||||||
private int currentIron;
|
private int currentIron;
|
||||||
private int currentWood;
|
private int currentWood;
|
||||||
|
|
||||||
public VillageHall(int lvl, VillageStage baseStage) {
|
public CasaDeNarino(int lvl, VillageStage baseStage) {
|
||||||
setLevel(lvl);
|
setLevel(lvl);
|
||||||
upgrade(baseStage);
|
upgrade(baseStage);
|
||||||
}
|
}
|
|
@ -12,5 +12,7 @@ public class Farm extends ResourceBuilding {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void harvest(VillageHall hall) {}
|
protected ResourceHarvestHandler getHarvestHandler() {
|
||||||
|
return hall -> {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ public class IronMine extends ResourceBuilding {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void harvest(VillageHall hall) {
|
protected ResourceHarvestHandler getHarvestHandler() {
|
||||||
hall.addCurrentIron(getHarvestRate());
|
return hall -> hall.addCurrentIron(getHarvestRate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,9 @@ public class LumberMine extends ResourceBuilding {
|
||||||
upgrade(baseStage);
|
upgrade(baseStage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void harvest(VillageHall hall) {
|
@Override
|
||||||
hall.addCurrentWood(getHarvestRate());
|
protected ResourceHarvestHandler getHarvestHandler() {
|
||||||
|
return hall -> hall.addCurrentWood(getHarvestRate());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,10 @@ import ca.cosc3p91.a2.util.Time;
|
||||||
|
|
||||||
public abstract class ResourceBuilding extends Building {
|
public abstract class ResourceBuilding extends Building {
|
||||||
|
|
||||||
|
protected interface ResourceHarvestHandler {
|
||||||
|
void harvest(CasaDeNarino hall);
|
||||||
|
}
|
||||||
|
|
||||||
public static String resource;
|
public static String resource;
|
||||||
|
|
||||||
private final Time harvestMinTime = new Time().offsetSeconds(10);
|
private final Time harvestMinTime = new Time().offsetSeconds(10);
|
||||||
|
@ -20,14 +24,14 @@ public abstract class ResourceBuilding extends Building {
|
||||||
this.harvest_rate += stage.getHarvestRateIncrease();
|
this.harvest_rate += stage.getHarvestRateIncrease();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(VillageHall hall){
|
public void update(CasaDeNarino hall){
|
||||||
if (nextHarvestTime.occurred()){
|
if (nextHarvestTime.occurred()){
|
||||||
harvest(hall);
|
getHarvestHandler().harvest(hall);
|
||||||
nextHarvestTime = Time.getTime().offsetTime(harvestMinTime);
|
nextHarvestTime = Time.getTime().offsetTime(harvestMinTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void harvest(VillageHall hall);
|
protected abstract ResourceHarvestHandler getHarvestHandler();
|
||||||
|
|
||||||
public int getHarvestRate(){
|
public int getHarvestRate(){
|
||||||
return harvest_rate;
|
return harvest_rate;
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package ca.cosc3p91.a2.gameobjects;
|
package ca.cosc3p91.a2.gameobjects;
|
||||||
|
|
||||||
|
import ca.cosc3p91.a2.util.Time;
|
||||||
|
|
||||||
public class ResourceStage extends Stage {
|
public class ResourceStage extends Stage {
|
||||||
|
|
||||||
protected int harvestRateIncrease;
|
protected int harvestRateIncrease;
|
||||||
|
|
||||||
public ResourceStage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost,
|
public ResourceStage(int dHealth, int goldCost, int requiredVillageLevel, Time upgradeTime, int ironCost, int woodCost,
|
||||||
int harvestRateIncr) {
|
int harvestRateIncr) {
|
||||||
super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost);
|
super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost);
|
||||||
this.harvestRateIncrease = harvestRateIncr;
|
this.harvestRateIncrease = harvestRateIncr;
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package ca.cosc3p91.a2.gameobjects;
|
||||||
|
|
||||||
|
import ca.cosc3p91.a2.util.Time;
|
||||||
|
|
||||||
|
public class ResourceStages {
|
||||||
|
|
||||||
|
public static class GoldStage1 extends ResourceStage {
|
||||||
|
public GoldStage1() {
|
||||||
|
super(100, 0, 0, new Time().offsetMinutes(1), 25, 250, 25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GoldStage2 extends ResourceStage {
|
||||||
|
public GoldStage2() {
|
||||||
|
super(100, 100, 1, new Time().offsetMinutes(15), 25, 275, 35);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GoldStage3 extends ResourceStage {
|
||||||
|
public GoldStage3() {
|
||||||
|
super(100, 150, 2, new Time().offsetHours(1), 50, 325, 50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class IronStage1 extends ResourceStage {
|
||||||
|
public IronStage1() {
|
||||||
|
super(100, 0, 0, new Time().offsetMinutes(1), 0, 125, 25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class IronStage2 extends ResourceStage {
|
||||||
|
public IronStage2() {
|
||||||
|
super(100, 15, 1, new Time().offsetMinutes(15), 25, 155, 35);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class IronStage3 extends ResourceStage {
|
||||||
|
public IronStage3() {
|
||||||
|
super(100, 50, 2, new Time().offsetHours(1), 50, 250, 50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WoodStage1 extends ResourceStage {
|
||||||
|
public WoodStage1() {
|
||||||
|
super(100, 0, 0, new Time().offsetMinutes(1), 0, 50, 25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WoodStage2 extends ResourceStage {
|
||||||
|
public WoodStage2() {
|
||||||
|
super(100, 5, 1, new Time().offsetMinutes(15), 5, 75, 35);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WoodStage3 extends ResourceStage {
|
||||||
|
public WoodStage3() {
|
||||||
|
super(100, 10, 2, new Time().offsetHours(1), 25, 100, 50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ public class SaulGoodMine extends ResourceBuilding {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void harvest(VillageHall hall) {
|
protected ResourceHarvestHandler getHarvestHandler() {
|
||||||
hall.addCurrentGold(getHarvestRate());
|
return hall -> hall.addCurrentGold(getHarvestRate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package ca.cosc3p91.a2.gameobjects;
|
package ca.cosc3p91.a2.gameobjects;
|
||||||
|
|
||||||
|
import ca.cosc3p91.a2.util.Time;
|
||||||
|
|
||||||
abstract class Stage {
|
abstract class Stage {
|
||||||
|
|
||||||
protected int dHealth;
|
protected int dHealth;
|
||||||
|
@ -8,13 +10,13 @@ abstract class Stage {
|
||||||
|
|
||||||
protected int requiredVillageLevel;
|
protected int requiredVillageLevel;
|
||||||
|
|
||||||
protected int upgradeTime;
|
protected Time upgradeTime;
|
||||||
|
|
||||||
protected int ironCost;
|
protected int ironCost;
|
||||||
|
|
||||||
protected int woodCost;
|
protected int woodCost;
|
||||||
|
|
||||||
public Stage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost) {
|
public Stage(int dHealth, int goldCost, int requiredVillageLevel, Time upgradeTime, int ironCost, int woodCost) {
|
||||||
this.dHealth = dHealth;
|
this.dHealth = dHealth;
|
||||||
this.goldCost = goldCost;
|
this.goldCost = goldCost;
|
||||||
this.requiredVillageLevel = requiredVillageLevel;
|
this.requiredVillageLevel = requiredVillageLevel;
|
||||||
|
@ -36,7 +38,7 @@ abstract class Stage {
|
||||||
return requiredVillageLevel;
|
return requiredVillageLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUpgradeTime() {
|
public Time getUpgradeTime() {
|
||||||
return upgradeTime;
|
return upgradeTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package ca.cosc3p91.a2.gameobjects;
|
package ca.cosc3p91.a2.gameobjects;
|
||||||
|
|
||||||
|
import ca.cosc3p91.a2.util.Time;
|
||||||
|
|
||||||
public class VillageStage extends Stage {
|
public class VillageStage extends Stage {
|
||||||
|
|
||||||
protected int goldCapacityIncrease;
|
protected int goldCapacityIncrease;
|
||||||
|
@ -8,7 +10,7 @@ public class VillageStage extends Stage {
|
||||||
|
|
||||||
protected int woodCapacityIncrease;
|
protected int woodCapacityIncrease;
|
||||||
|
|
||||||
public VillageStage(int dHealth, int goldCost, int requiredVillageLevel, int upgradeTime, int ironCost, int woodCost,
|
public VillageStage(int dHealth, int goldCost, int requiredVillageLevel, Time upgradeTime, int ironCost, int woodCost,
|
||||||
int goldCapIncrease, int ironCapIncrease, int woodCapIncrease) {
|
int goldCapIncrease, int ironCapIncrease, int woodCapIncrease) {
|
||||||
super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost);
|
super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost);
|
||||||
this.goldCapacityIncrease = goldCapIncrease;
|
this.goldCapacityIncrease = goldCapIncrease;
|
||||||
|
|
Loading…
Reference in New Issue