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 static void main(String[] args) {
|
||||
GameEngine engine = new GameEngine();
|
||||
|
||||
engine.run();
|
||||
new GameEngine().run();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,11 @@ package ca.cosc3p91.a2.game;
|
|||
import ca.cosc3p91.a2.gameobjects.*;
|
||||
import ca.cosc3p91.a2.player.*;
|
||||
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;
|
||||
|
||||
public class GameEngine implements Runnable {
|
||||
|
@ -19,9 +23,7 @@ public class GameEngine implements Runnable {
|
|||
|
||||
public GameEngine() {
|
||||
player = new Player();
|
||||
VillageStage vInitialStage = new VillageStage(100, 0, 2, 30, 0,
|
||||
0, 1000, 2500, 5000);
|
||||
map = new Map(new VillageHall(1, vInitialStage), 30);
|
||||
map = generateMap();
|
||||
}
|
||||
|
||||
private void printState() {
|
||||
|
@ -71,21 +73,52 @@ public class GameEngine implements Runnable {
|
|||
}
|
||||
|
||||
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() {
|
||||
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) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
|
||||
Scanner sc = new Scanner(rd);
|
||||
printState();
|
||||
System.out.println();
|
||||
while (running) {
|
||||
printState();
|
||||
int in = sc.nextInt();
|
||||
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;
|
||||
|
||||
private VillageHall townHall;
|
||||
private CasaDeNarino townHall;
|
||||
|
||||
private int guardTime;
|
||||
|
||||
|
@ -17,11 +17,11 @@ public class Map {
|
|||
|
||||
public List<Inhabitant> inhabitants;
|
||||
|
||||
public Map(VillageHall villageHall, int gTime) {
|
||||
public Map(CasaDeNarino casaDeNarino, int gTime) {
|
||||
contains = new ArrayList<>();
|
||||
inhabitants = new ArrayList<>();
|
||||
this.townHall = villageHall;
|
||||
this.contains.add(villageHall);
|
||||
this.townHall = casaDeNarino;
|
||||
this.contains.add(casaDeNarino);
|
||||
this.guardTime = gTime;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class Map {
|
|||
this.guardTime = gTime;
|
||||
}
|
||||
|
||||
public VillageHall getTownHall(){
|
||||
public CasaDeNarino getTownHall(){
|
||||
return townHall;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package ca.cosc3p91.a2.gameobjects;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class VillageHall extends Building {
|
||||
public class CasaDeNarino extends Building {
|
||||
|
||||
private int goldCapacity = 0;
|
||||
private int ironCapacity = 0;
|
||||
|
@ -12,7 +12,7 @@ public class VillageHall extends Building {
|
|||
private int currentIron;
|
||||
private int currentWood;
|
||||
|
||||
public VillageHall(int lvl, VillageStage baseStage) {
|
||||
public CasaDeNarino(int lvl, VillageStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
}
|
|
@ -12,5 +12,7 @@ public class Farm extends ResourceBuilding {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void harvest(VillageHall hall) {}
|
||||
protected ResourceHarvestHandler getHarvestHandler() {
|
||||
return hall -> {};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ public class IronMine extends ResourceBuilding {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void harvest(VillageHall hall) {
|
||||
hall.addCurrentIron(getHarvestRate());
|
||||
protected ResourceHarvestHandler getHarvestHandler() {
|
||||
return hall -> hall.addCurrentIron(getHarvestRate());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@ public class LumberMine extends ResourceBuilding {
|
|||
upgrade(baseStage);
|
||||
}
|
||||
|
||||
public void harvest(VillageHall hall) {
|
||||
hall.addCurrentWood(getHarvestRate());
|
||||
@Override
|
||||
protected ResourceHarvestHandler getHarvestHandler() {
|
||||
return hall -> hall.addCurrentWood(getHarvestRate());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,10 @@ import ca.cosc3p91.a2.util.Time;
|
|||
|
||||
public abstract class ResourceBuilding extends Building {
|
||||
|
||||
protected interface ResourceHarvestHandler {
|
||||
void harvest(CasaDeNarino hall);
|
||||
}
|
||||
|
||||
public static String resource;
|
||||
|
||||
private final Time harvestMinTime = new Time().offsetSeconds(10);
|
||||
|
@ -20,14 +24,14 @@ public abstract class ResourceBuilding extends Building {
|
|||
this.harvest_rate += stage.getHarvestRateIncrease();
|
||||
}
|
||||
|
||||
public void update(VillageHall hall){
|
||||
public void update(CasaDeNarino hall){
|
||||
if (nextHarvestTime.occurred()){
|
||||
harvest(hall);
|
||||
getHarvestHandler().harvest(hall);
|
||||
nextHarvestTime = Time.getTime().offsetTime(harvestMinTime);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void harvest(VillageHall hall);
|
||||
protected abstract ResourceHarvestHandler getHarvestHandler();
|
||||
|
||||
public int getHarvestRate(){
|
||||
return harvest_rate;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package ca.cosc3p91.a2.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a2.util.Time;
|
||||
|
||||
public class ResourceStage extends Stage {
|
||||
|
||||
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) {
|
||||
super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost);
|
||||
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
|
||||
public void harvest(VillageHall hall) {
|
||||
hall.addCurrentGold(getHarvestRate());
|
||||
protected ResourceHarvestHandler getHarvestHandler() {
|
||||
return hall -> hall.addCurrentGold(getHarvestRate());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ca.cosc3p91.a2.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a2.util.Time;
|
||||
|
||||
abstract class Stage {
|
||||
|
||||
protected int dHealth;
|
||||
|
@ -8,13 +10,13 @@ abstract class Stage {
|
|||
|
||||
protected int requiredVillageLevel;
|
||||
|
||||
protected int upgradeTime;
|
||||
protected Time upgradeTime;
|
||||
|
||||
protected int ironCost;
|
||||
|
||||
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.goldCost = goldCost;
|
||||
this.requiredVillageLevel = requiredVillageLevel;
|
||||
|
@ -36,7 +38,7 @@ abstract class Stage {
|
|||
return requiredVillageLevel;
|
||||
}
|
||||
|
||||
public int getUpgradeTime() {
|
||||
public Time getUpgradeTime() {
|
||||
return upgradeTime;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ca.cosc3p91.a2.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a2.util.Time;
|
||||
|
||||
public class VillageStage extends Stage {
|
||||
|
||||
protected int goldCapacityIncrease;
|
||||
|
@ -8,7 +10,7 @@ public class VillageStage extends Stage {
|
|||
|
||||
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) {
|
||||
super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost);
|
||||
this.goldCapacityIncrease = goldCapIncrease;
|
||||
|
|
Loading…
Reference in New Issue