Assign4 setup, fix package name issue
parent
e20d1a73f1
commit
02683303dd
|
@ -1,7 +1,7 @@
|
|||
package ca.cosc3p91.a3;
|
||||
package ca.cosc3p91.a4;
|
||||
|
||||
import ca.cosc3p91.a3.game.GameEngine;
|
||||
import ca.cosc3p91.a3.gameobjects.Stage;
|
||||
import ca.cosc3p91.a4.game.GameEngine;
|
||||
import ca.cosc3p91.a4.gameobjects.Stage;
|
||||
|
||||
public class Main {
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package ca.cosc3p91.a3.game;
|
||||
package ca.cosc3p91.a4.game;
|
||||
|
||||
import ca.cosc3p91.a3.gameobjects.*;
|
||||
import ca.cosc3p91.a3.player.*;
|
||||
import ca.cosc3p91.a3.util.Print;
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a3.util.Util;
|
||||
import ca.cosc3p91.a4.gameobjects.*;
|
||||
import ca.cosc3p91.a4.player.*;
|
||||
import ca.cosc3p91.a4.util.Print;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
import ca.cosc3p91.a4.util.Util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.game;
|
||||
package ca.cosc3p91.a4.game;
|
||||
|
||||
import ca.cosc3p91.a3.gameobjects.*;
|
||||
import ca.cosc3p91.a4.gameobjects.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Archer extends Infantry {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class ArcherTower extends DefenseBuilding {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Cannon extends DefenseBuilding {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class CasaDeNarino extends Building {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Catapult extends Infantry {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Collector implements Inhabitant {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public abstract class DefenseBuilding extends Building {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
class DefenseStage extends Stage {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class DefenseStages {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Farm extends ResourceBuilding {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public abstract class Infantry implements Inhabitant {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.game.Map;
|
||||
import ca.cosc3p91.a4.game.Map;
|
||||
|
||||
public interface Inhabitant {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class IronMine extends ResourceBuilding {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Knight extends Infantry {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class LumberMine extends ResourceBuilding {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public abstract class ResourceBuilding extends Building {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class ResourceStage extends Stage {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class ResourceStages {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class SaulGoodMine extends ResourceBuilding {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Soldier extends Infantry {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class VillageHallStages {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class VillageStage extends Stage {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Worker implements Inhabitant {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.player;
|
||||
package ca.cosc3p91.a4.player;
|
||||
|
||||
public class Player {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.userinterface;
|
||||
package ca.cosc3p91.a4.userinterface;
|
||||
|
||||
public class GuiManager {
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.util;
|
||||
package ca.cosc3p91.a4.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.util;
|
||||
package ca.cosc3p91.a4.util;
|
||||
|
||||
public class Time {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.util;
|
||||
package ca.cosc3p91.a4.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3;
|
||||
package ca.cosc3p91.a4;
|
||||
|
||||
import ca.cosc3p91.a3.game.GameEngine;
|
||||
import ca.cosc3p91.a4.game.GameEngine;
|
||||
|
||||
public class Main {
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package ca.cosc3p91.a3.game;
|
||||
package ca.cosc3p91.a4.game;
|
||||
|
||||
import ca.cosc3p91.a3.gameobjects.*;
|
||||
import ca.cosc3p91.a3.gameobjects.factory.BuildingFactory;
|
||||
import ca.cosc3p91.a3.gameobjects.factory.InhabitantFactory;
|
||||
import ca.cosc3p91.a3.player.*;
|
||||
import ca.cosc3p91.a3.userinterface.GameDisplay;
|
||||
import ca.cosc3p91.a3.util.ChallengeAdapter;
|
||||
import ca.cosc3p91.a4.gameobjects.*;
|
||||
import ca.cosc3p91.a4.gameobjects.factory.BuildingFactory;
|
||||
import ca.cosc3p91.a4.gameobjects.factory.InhabitantFactory;
|
||||
import ca.cosc3p91.a4.player.*;
|
||||
import ca.cosc3p91.a4.userinterface.GameDisplay;
|
||||
import ca.cosc3p91.a4.util.ChallengeAdapter;
|
||||
|
||||
import java.beans.XMLEncoder;
|
||||
import java.io.BufferedOutputStream;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.game;
|
||||
package ca.cosc3p91.a4.game;
|
||||
|
||||
import ca.cosc3p91.a3.gameobjects.*;
|
||||
import ca.cosc3p91.a4.gameobjects.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Archer extends Infantry {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class ArcherTower extends DefenseBuilding {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Cannon extends DefenseBuilding {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class CasaDeNarino extends Building {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Catapult extends Infantry {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Collector implements Inhabitant {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public abstract class DefenseBuilding extends Building {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
class DefenseStage extends Stage {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class DefenseStages {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Farm extends ResourceBuilding {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public abstract class Infantry implements Inhabitant {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class IronMine extends ResourceBuilding {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Knight extends Infantry {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class LumberMine extends ResourceBuilding {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public abstract class ResourceBuilding extends Building {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class ResourceStage extends Stage {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class ResourceStages {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class SaulGoodMine extends ResourceBuilding {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Soldier extends Infantry {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Tile {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class VillageHallStages {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a3.util.Time;
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class VillageStage extends Stage {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.gameobjects;
|
||||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Worker implements Inhabitant {
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package ca.cosc3p91.a3.gameobjects.factory;
|
||||
package ca.cosc3p91.a4.gameobjects.factory;
|
||||
|
||||
import ca.cosc3p91.a3.gameobjects.*;
|
||||
import ca.cosc3p91.a3.util.Util;
|
||||
import ca.cosc3p91.a4.gameobjects.*;
|
||||
import ca.cosc3p91.a4.util.Util;
|
||||
|
||||
public class BuildingFactory {
|
||||
public Building getBuilding(String buildingName) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package ca.cosc3p91.a3.gameobjects.factory;
|
||||
package ca.cosc3p91.a4.gameobjects.factory;
|
||||
|
||||
import ca.cosc3p91.a3.gameobjects.*;
|
||||
import ca.cosc3p91.a3.util.Util;
|
||||
import ca.cosc3p91.a4.gameobjects.*;
|
||||
import ca.cosc3p91.a4.util.Util;
|
||||
|
||||
public class InhabitantFactory {
|
||||
public Inhabitant getInhabitant(String inhabitantName) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.player;
|
||||
package ca.cosc3p91.a4.player;
|
||||
|
||||
public class Player {
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package ca.cosc3p91.a3.userinterface;
|
||||
package ca.cosc3p91.a4.userinterface;
|
||||
|
||||
import ca.cosc3p91.a3.game.Map;
|
||||
import ca.cosc3p91.a3.gameobjects.Building;
|
||||
import ca.cosc3p91.a3.gameobjects.Inhabitant;
|
||||
import ca.cosc3p91.a3.util.Print;
|
||||
import ca.cosc3p91.a4.game.Map;
|
||||
import ca.cosc3p91.a4.gameobjects.Building;
|
||||
import ca.cosc3p91.a4.gameobjects.Inhabitant;
|
||||
import ca.cosc3p91.a4.util.Print;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package ca.cosc3p91.a3.util;
|
||||
package ca.cosc3p91.a4.util;
|
||||
|
||||
import ChallengeDecision.*;
|
||||
import ca.cosc3p91.a3.game.Map;
|
||||
import ca.cosc3p91.a3.gameobjects.*;
|
||||
import ca.cosc3p91.a4.game.Map;
|
||||
import ca.cosc3p91.a4.gameobjects.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.util;
|
||||
package ca.cosc3p91.a4.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.util;
|
||||
package ca.cosc3p91.a4.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.cosc3p91.a3.util;
|
||||
package ca.cosc3p91.a4.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ChallengeDecision;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robson
|
||||
*/
|
||||
public class Arbitrer {
|
||||
|
||||
public static ChallengeResult challengeDecide( ChallengeEntitySet<Double,Double> challenger, ChallengeEntitySet<Double,Double> challengee ) {
|
||||
ChallengeResult challengeResult = new ChallengeResult( false );
|
||||
int i = 0, j = 0, challengerSize, challengeeSize;
|
||||
FightResult fr;
|
||||
ChallengeEntity tempCE;
|
||||
Boolean challengerTurn = true;
|
||||
double challengerPower = 0;
|
||||
List<ChallengeResource<Double,Double>> resultingResources = new ArrayList<>();
|
||||
|
||||
challengerSize = challenger.getEntityAttackList().size();
|
||||
challengeeSize = challengee.getEntityDefenseList().size();
|
||||
|
||||
for ( ChallengeAttack ce : challenger.getEntityAttackList() )
|
||||
challengerPower += ce.getProperty().doubleValue();
|
||||
|
||||
if ( challengerSize > 0 ) {
|
||||
tempCE = challenger.getEntityAttackList().get( i++ );
|
||||
|
||||
while ( i < challengerSize && j < challengeeSize ) {
|
||||
if ( challengerTurn ) { //tempCE is the challenger
|
||||
fr = tempCE.fight( challengee.entityDefenseList.get( j ) );
|
||||
challengerTurn = fr.getResult();
|
||||
tempCE = fr.getChallengeEntity();
|
||||
if ( challengerTurn )
|
||||
j++;
|
||||
else i++;
|
||||
} else { //tempCE is the challengee
|
||||
fr = challenger.getEntityAttackList().get( i ).fight( tempCE );
|
||||
challengerTurn = fr.getResult();
|
||||
tempCE = fr.getChallengeEntity();
|
||||
if ( challengerTurn )
|
||||
j++;
|
||||
else i++;
|
||||
}
|
||||
}
|
||||
|
||||
// check what is remaining
|
||||
|
||||
if ( i < challengerSize ) { // 1 - there are still reamaining challengers
|
||||
double sum = 0;
|
||||
double proportion;
|
||||
|
||||
while ( i < challengerSize ) {
|
||||
sum += challenger.getEntityAttackList().get( i++ ).getProperty().doubleValue();
|
||||
}
|
||||
|
||||
proportion = sum / challengerPower;
|
||||
|
||||
challengee.getEntityResourceList().forEach((ce) -> {
|
||||
resultingResources.add( new ChallengeResource( ce.getProperty().doubleValue() * ( proportion * getLootChance() ) ) );
|
||||
});
|
||||
|
||||
challengeResult = new ChallengeResult( true, resultingResources );
|
||||
} else if ( j < challengerSize ) { // 2 - there are still reamaining challengees
|
||||
// no resources got back from attack
|
||||
challengeResult = new ChallengeResult( false );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return challengeResult;
|
||||
}
|
||||
|
||||
private static double getLootChance() {
|
||||
return ( ThreadLocalRandom.current().nextInt(1, 10 ) + 10 ) / 20.0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ChallengeDecision;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robson
|
||||
* @param <T>
|
||||
*/
|
||||
public class ChallengeAttack <T extends Number, V extends Number> extends ChallengeEntity<T,V> {
|
||||
T attack;
|
||||
V hit;
|
||||
|
||||
public ChallengeAttack( T attack, V hit ) {
|
||||
this.attack = attack;
|
||||
this.hit = hit;
|
||||
}
|
||||
|
||||
public ChallengeAttack( T attack ) {
|
||||
this.attack = attack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getProperty() {
|
||||
return this.attack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty( T attack ) {
|
||||
this.attack = attack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getHitPoints() {
|
||||
return hit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHitPoints( V value ) {
|
||||
hit = value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compare( ChallengeEntity ce ) {
|
||||
double result;
|
||||
result = this.attack.doubleValue() - ce.getProperty().doubleValue();
|
||||
|
||||
if ( result == 0 )
|
||||
return 0;
|
||||
else if ( result > 0 )
|
||||
return 1;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double checkDifference( ChallengeEntity ce ) {
|
||||
return this.attack.doubleValue() - ce.getProperty().doubleValue();
|
||||
}
|
||||
|
||||
public FightResult fight( ChallengeEntity<T,V> ce ) {
|
||||
Boolean fightOutcome = false;
|
||||
ChallengeEntity<Double,Double> re;
|
||||
|
||||
double result;
|
||||
result = ( attack.doubleValue() + hit.doubleValue() ) - ( ce.getProperty().doubleValue() + ce.getHitPoints().doubleValue() );
|
||||
|
||||
if ( result > 0 ) {
|
||||
if ( result / ( attack.doubleValue() + hit.doubleValue() ) > 0.2 ) { // it won by a large difference
|
||||
fightOutcome = ThreadLocalRandom.current().nextInt(1, 100) > 10; //attack success
|
||||
if ( fightOutcome ) { //attack success -> attacker remains
|
||||
re = new ChallengeAttack<>( attack.doubleValue() );
|
||||
re.setHitPoints( ce.getHitPoints().doubleValue() * 0.75 );
|
||||
} else { //attack fail -> defense remains
|
||||
re = new ChallengeDefense<>( ce.getProperty().doubleValue() );
|
||||
re.setHitPoints( ce.getHitPoints().doubleValue() * 0.3 );
|
||||
}
|
||||
} else { // it won by a small difference
|
||||
fightOutcome = ThreadLocalRandom.current().nextInt(1, 100) > 50; //attack success
|
||||
if ( fightOutcome ) { //attack success -> attacker remains
|
||||
re = new ChallengeAttack<>( attack.doubleValue() );
|
||||
re.setHitPoints( ce.getHitPoints().doubleValue() * 0.5 );
|
||||
} else { //attack fail -> defense remains
|
||||
re = new ChallengeDefense<>( ce.getProperty().doubleValue() );
|
||||
re.setHitPoints( ce.getHitPoints().doubleValue() * 0.5 );
|
||||
}
|
||||
}
|
||||
} else { // attack fail
|
||||
re = new ChallengeDefense<>( ce.getProperty().doubleValue() );
|
||||
if ( ( result * -1 ) / ( ce.getProperty().doubleValue() + ce.getHitPoints().doubleValue() ) > 0.5 ) { // it defended by a large difference -> it keeps 80% of health
|
||||
re.setHitPoints( ce.getHitPoints().doubleValue() * 0.75 );
|
||||
} else { // it defended by a small difference -> it keeps 505 of health
|
||||
re.setHitPoints( ce.getHitPoints().doubleValue() * 0.5 );
|
||||
}
|
||||
}
|
||||
|
||||
return new FightResult( fightOutcome, re );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ChallengeDecision;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robson
|
||||
* @param <T>
|
||||
*/
|
||||
public class ChallengeDefense <T extends Number, V extends Number> extends ChallengeEntity<T,V> {
|
||||
T defense;
|
||||
V hit;
|
||||
|
||||
public ChallengeDefense( T defense ) {
|
||||
this.defense = defense;
|
||||
}
|
||||
|
||||
public ChallengeDefense( T defense, V hit ) {
|
||||
this.defense = defense;
|
||||
this.hit = hit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getProperty() {
|
||||
return this.defense;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty( T defense ) {
|
||||
this.defense = defense;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getHitPoints() {
|
||||
return hit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHitPoints( V value ) {
|
||||
hit = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare( ChallengeEntity ce ) {
|
||||
double result;
|
||||
result = this.defense.doubleValue() - ce.getProperty().doubleValue();
|
||||
|
||||
if ( result == 0 )
|
||||
return 0;
|
||||
else if ( result > 0 )
|
||||
return 1;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double checkDifference( ChallengeEntity ce ) {
|
||||
return this.defense.doubleValue() - ce.getProperty().doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FightResult fight(ChallengeEntity<T, V> ce) {
|
||||
return new FightResult( false, new ChallengeDefense( 0 ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ChallengeDecision;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robson
|
||||
*/
|
||||
public abstract class ChallengeEntity<T extends Number, V extends Number> {
|
||||
|
||||
public abstract T getProperty();
|
||||
|
||||
public abstract void setProperty( T property );
|
||||
|
||||
public abstract V getHitPoints();
|
||||
|
||||
public abstract void setHitPoints( V value );
|
||||
|
||||
public abstract int compare( ChallengeEntity ce );
|
||||
|
||||
public abstract FightResult fight( ChallengeEntity<T,V> ce );
|
||||
|
||||
public abstract double checkDifference( ChallengeEntity ce );
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ChallengeDecision;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robson
|
||||
*/
|
||||
public class ChallengeEntitySet <T extends Number, V extends Number> {
|
||||
List<ChallengeAttack<T,V>> entityAttackList;
|
||||
List<ChallengeDefense<T,V>> entityDefenseList;
|
||||
List<ChallengeResource<T,V>> entityResourceList;
|
||||
|
||||
public ChallengeEntitySet( List<ChallengeAttack<T,V>> entityAttackList, List<ChallengeDefense<T,V>> entityDefenseList, List<ChallengeResource<T,V>> entityResourceList ) {
|
||||
this.entityAttackList = entityAttackList;
|
||||
this.entityDefenseList = entityDefenseList;
|
||||
this.entityResourceList = entityResourceList;
|
||||
}
|
||||
|
||||
public ChallengeEntitySet() {
|
||||
entityAttackList = new ArrayList();
|
||||
entityDefenseList = new ArrayList();
|
||||
entityResourceList = new ArrayList();
|
||||
}
|
||||
|
||||
public void setEntityAttackList( List<ChallengeAttack<T,V>> entityAttackList ) {
|
||||
this.entityAttackList = entityAttackList;
|
||||
|
||||
}
|
||||
|
||||
public void setEntityDefenseList( List<ChallengeDefense<T,V>> entityDefenseList ) {
|
||||
this.entityDefenseList = entityDefenseList;
|
||||
}
|
||||
|
||||
public void setEntityResourceList( List<ChallengeResource<T,V>> entityResourceList ) {
|
||||
this.entityResourceList = entityResourceList;
|
||||
}
|
||||
|
||||
public List<ChallengeAttack<T,V>> getEntityAttackList(){
|
||||
return this.entityAttackList;
|
||||
}
|
||||
|
||||
public List<ChallengeDefense<T,V>> getEntityDefenseList(){
|
||||
return this.entityDefenseList;
|
||||
}
|
||||
|
||||
public List<ChallengeResource<T,V>> getEntityResourceList(){
|
||||
return this.entityResourceList;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ChallengeDecision;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robson
|
||||
* @param <T>
|
||||
*/
|
||||
public class ChallengeResource <T extends Number, V extends Number> extends ChallengeEntity<T,V> {
|
||||
T resource;
|
||||
V hit;
|
||||
|
||||
public ChallengeResource() {
|
||||
}
|
||||
|
||||
public ChallengeResource( T resource ) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public ChallengeResource( T resource, V hit ) {
|
||||
this.resource = resource;
|
||||
this.hit = hit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getProperty() {
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty( T resource ) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getHitPoints() {
|
||||
return hit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHitPoints( V value ) {
|
||||
hit = value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compare( ChallengeEntity ce ) {
|
||||
double result;
|
||||
result = this.resource.doubleValue() - ce.getProperty().doubleValue();
|
||||
|
||||
if ( result == 0 )
|
||||
return 0;
|
||||
else if ( result > 0 )
|
||||
return 1;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double checkDifference( ChallengeEntity ce ) {
|
||||
return this.resource.doubleValue() - ce.getProperty().doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FightResult fight(ChallengeEntity<T, V> ce) {
|
||||
return new FightResult( false, new ChallengeDefense( 0 ) );
|
||||
}
|
||||
|
||||
public void print() {
|
||||
System.out.println( "Resource: " + resource + " / Hit: " + hit );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ChallengeDecision;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robson
|
||||
*/
|
||||
public class ChallengeResult {
|
||||
Boolean challengeWon;
|
||||
List<ChallengeResource<Double,Double>> loot;
|
||||
|
||||
public ChallengeResult( Boolean won, List<ChallengeResource<Double,Double>> loot ) {
|
||||
challengeWon = won;
|
||||
this.loot = loot;
|
||||
}
|
||||
|
||||
public ChallengeResult( Boolean won ) {
|
||||
challengeWon = won;
|
||||
loot = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Boolean getChallengeWon() {
|
||||
return challengeWon;
|
||||
}
|
||||
|
||||
public List<ChallengeResource<Double,Double>> getLoot() {
|
||||
return loot;
|
||||
}
|
||||
|
||||
public void print() {
|
||||
System.out.println( "Result: " + challengeWon );
|
||||
for ( ChallengeResource e : loot ) {
|
||||
e.print();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ChallengeDecision;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robson
|
||||
*/
|
||||
class FightResult {
|
||||
Boolean result;
|
||||
ChallengeEntity<Double, Double> ce;
|
||||
|
||||
public FightResult( Boolean result, ChallengeEntity ce ) {
|
||||
this.result = result;
|
||||
this.ce = ce;
|
||||
}
|
||||
|
||||
public Boolean getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public ChallengeEntity<Double, Double> getChallengeEntity() {
|
||||
return ce;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package ca.cosc3p91.a4;
|
||||
|
||||
import ca.cosc3p91.a4.game.GameEngine;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new GameEngine().run();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,265 @@
|
|||
package ca.cosc3p91.a4.game;
|
||||
|
||||
import ca.cosc3p91.a4.gameobjects.*;
|
||||
import ca.cosc3p91.a4.gameobjects.factory.BuildingFactory;
|
||||
import ca.cosc3p91.a4.gameobjects.factory.InhabitantFactory;
|
||||
import ca.cosc3p91.a4.player.*;
|
||||
import ca.cosc3p91.a4.userinterface.GameDisplay;
|
||||
import ca.cosc3p91.a4.util.ChallengeAdapter;
|
||||
|
||||
import java.beans.XMLEncoder;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Random;
|
||||
|
||||
public class GameEngine implements Runnable {
|
||||
|
||||
public static final double GOLD_FACTOR = 5;
|
||||
public static final double IRON_FACTOR = 1;
|
||||
public static final double WOOD_FACTOR = 0.1;
|
||||
|
||||
private Player player;
|
||||
boolean running = true;
|
||||
|
||||
private float pillageFactor = 0.5f;
|
||||
|
||||
private int currentTime;
|
||||
|
||||
private final Random random = new Random(System.nanoTime());
|
||||
|
||||
public Map map;
|
||||
public GameDisplay view;
|
||||
|
||||
public GameEngine() {
|
||||
player = new Player();
|
||||
map = generateInitialMap();
|
||||
}
|
||||
|
||||
public void attackVillage(Map map) {
|
||||
// int defenseiveCounter = 1;
|
||||
// int inhabCounter = 0;
|
||||
// for (Building b : map.contains)
|
||||
// if (b instanceof DefenseBuilding)
|
||||
// defenseiveCounter++;
|
||||
// for (Inhabitant i : map.inhabitants)
|
||||
// if (i instanceof Infantry)
|
||||
// inhabCounter++;
|
||||
// pillageFactor = (float) inhabCounter / (float) defenseiveCounter;
|
||||
// if (pillageFactor < 0)
|
||||
// pillageFactor = 0;
|
||||
// if (pillageFactor > 1)
|
||||
// pillageFactor = 1;
|
||||
// this.map.getTownHall().addWood((int) (map.getTownHall().getCurrentWood() * pillageFactor));
|
||||
// this.map.getTownHall().addIron((int) (map.getTownHall().getCurrentIron() * pillageFactor));
|
||||
// this.map.getTownHall().addGold((int) (map.getTownHall().getCurrentGold() * pillageFactor));
|
||||
ChallengeAdapter adapter = new ChallengeAdapter(this.map);
|
||||
adapter.attack(map);
|
||||
}
|
||||
|
||||
private Map generateInitialMap(){
|
||||
return new Map(new CasaDeNarino(1, VillageHallStages.villageStages[0]), 30);
|
||||
}
|
||||
|
||||
public Map generateMap() {
|
||||
Map initialMap = generateInitialMap();
|
||||
|
||||
CasaDeNarino hall = initialMap.getTownHall();
|
||||
|
||||
// generate a similar town hall
|
||||
int levelChange = random.nextInt(2) - 1;
|
||||
int nextLevel = this.map.getTownHall().getLevel() + levelChange;
|
||||
// only need to change if the new village level is higher than initial
|
||||
if (nextLevel > 0)
|
||||
hall.upgrade(VillageHallStages.villageStages[nextLevel]);
|
||||
|
||||
hall.addWood(this.map.getTownHall().getCurrentWood() + random.nextInt(500) - 150);
|
||||
hall.addIron(this.map.getTownHall().getCurrentIron() + random.nextInt(500) - 150);
|
||||
hall.addGold(this.map.getTownHall().getCurrentGold() + random.nextInt(500) - 150);
|
||||
|
||||
int buildingCount = this.map.contains.size();
|
||||
|
||||
int saulGoodMines = 0;
|
||||
int ironMines = 0;
|
||||
int woodMines = 0;
|
||||
int archerTowers = 0;
|
||||
int cannons = 0;
|
||||
|
||||
// count buildings in our map
|
||||
for (Building b : this.map.contains){
|
||||
if (b instanceof SaulGoodMine)
|
||||
saulGoodMines++;
|
||||
else if (b instanceof IronMine)
|
||||
ironMines++;
|
||||
else if (b instanceof LumberMine)
|
||||
woodMines++;
|
||||
else if (b instanceof ArcherTower)
|
||||
archerTowers++;
|
||||
else if (b instanceof Cannon)
|
||||
cannons++;
|
||||
}
|
||||
|
||||
// variate
|
||||
saulGoodMines += random.nextInt();;
|
||||
ironMines += random.nextInt();
|
||||
woodMines += random.nextInt();
|
||||
archerTowers += random.nextInt();
|
||||
cannons += random.nextInt();
|
||||
|
||||
// generate a map with a similar number of buildings
|
||||
for (int i = 0; i < Math.max(buildingCount + random.nextInt(5) - 2, 1); i++) {
|
||||
int selection = random.nextInt(5);
|
||||
// select a random building. Doing it this way because if we build based on buildings we have
|
||||
// then the maps will be VERY boring as they would be all the same
|
||||
switch (selection) {
|
||||
case 0:
|
||||
initialMap.contains.add(new LumberMine(ResourceStages.woodStages[random.nextInt(ResourceStages.woodStages.length)]));
|
||||
break;
|
||||
case 1:
|
||||
if (ironMines > 0)
|
||||
initialMap.contains.add(new IronMine(ResourceStages.ironStages[random.nextInt(ResourceStages.ironStages.length)]));
|
||||
break;
|
||||
case 2:
|
||||
if (saulGoodMines > 0)
|
||||
initialMap.contains.add(new SaulGoodMine(ResourceStages.goldStages[random.nextInt(ResourceStages.goldStages.length)]));
|
||||
break;
|
||||
case 3:
|
||||
initialMap.contains.add(new ArcherTower());
|
||||
break;
|
||||
case 4:
|
||||
initialMap.contains.add(new Cannon());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return initialMap;
|
||||
}
|
||||
|
||||
public int getScore(Map map) {
|
||||
CasaDeNarino hall = map.getTownHall();
|
||||
int score = (int)(hall.getCurrentGold() * GOLD_FACTOR + hall.getCurrentIron() * IRON_FACTOR + hall.getCurrentWood() * WOOD_FACTOR);
|
||||
score += map.contains.size();
|
||||
score += map.inhabitants.size();
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String in;
|
||||
|
||||
view = new GameDisplay();
|
||||
view.printVillageState(this.map,"Current Village State");
|
||||
view.printGameMenu();
|
||||
|
||||
Map exploringMap = null;
|
||||
boolean deleteMyHeart = true;
|
||||
while (running) {
|
||||
for (Building b : this.map.contains){
|
||||
if ((b instanceof ResourceBuilding)) {
|
||||
((ResourceBuilding) b).update(this.map.getTownHall());
|
||||
}
|
||||
}
|
||||
try {
|
||||
if ((in = view.nextInput()) != null) {
|
||||
String[] args = in.split(" ");
|
||||
|
||||
view.printLastInput();
|
||||
// reset the map if they aren't exploring
|
||||
if (in.charAt(0) != '4')
|
||||
deleteMyHeart = true;
|
||||
switch (in.charAt(0)) {
|
||||
case '1':
|
||||
if (args.length < 2) {
|
||||
System.err.println("Args must include type!");
|
||||
} else {
|
||||
BuildingFactory bfactory = new BuildingFactory();
|
||||
Building type = bfactory.getBuilding(args[1]);
|
||||
if (type == null)
|
||||
System.err.println("Args are not a valid building!");
|
||||
else if (this.map.build(new Tile(), type) ) {
|
||||
System.out.println(type.getClass().getSimpleName()+" successfully built\n");
|
||||
} else
|
||||
System.out.println("Missing resources to build "+type.getClass().getSimpleName());
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if (args.length < 2) {
|
||||
System.err.println("Args must include type!");
|
||||
} else {
|
||||
InhabitantFactory ifactory = new InhabitantFactory();
|
||||
Inhabitant type = ifactory.getInhabitant(args[1]);
|
||||
if (type == null)
|
||||
System.err.println("Args are not a valid inhabitant!");
|
||||
else if (this.map.train(type) ) {
|
||||
System.out.println("successfully trained a(n) "+type.getClass().getSimpleName());
|
||||
} else System.out.println("Missing gold to train "+type.getClass().getSimpleName());
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
if (args.length < 2) {
|
||||
System.err.println("Args must include type!");
|
||||
} else {
|
||||
int unitIndex = Integer.parseInt(args[1].substring(1));
|
||||
|
||||
if (unitIndex < 0) {
|
||||
System.err.println("Invalid Index");
|
||||
break;
|
||||
}
|
||||
|
||||
if (args[1].contains("i") && (unitIndex < map.inhabitants.size()) ) {
|
||||
if ( map.upgradeInhabitant(unitIndex) ) {
|
||||
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 {
|
||||
System.err.println("Args are not a valid unit!");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '4':
|
||||
deleteMyHeart = false;
|
||||
exploringMap = generateMap();
|
||||
view.printVillageState(exploringMap,"Other Village");
|
||||
break;
|
||||
case '7':
|
||||
if (exploringMap != null)
|
||||
attackVillage(exploringMap);
|
||||
else
|
||||
System.out.println("Error: Explored map is null. Have you explored last command?");
|
||||
break;
|
||||
case '5':
|
||||
view.printVillageState(this.map,"Home Village");
|
||||
break;
|
||||
case '6':
|
||||
System.exit(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
view.printGameMenu();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (deleteMyHeart)
|
||||
exploringMap = null;
|
||||
}
|
||||
save("test.xml", this.map);
|
||||
}
|
||||
|
||||
public void save(String file, Map map){
|
||||
try (XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(Files.newOutputStream(Paths.get(file))))) {
|
||||
map.contains.forEach(encoder::writeObject);
|
||||
map.inhabitants.forEach(encoder::writeObject);
|
||||
System.out.println("Wrote map");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
package ca.cosc3p91.a4.game;
|
||||
|
||||
import ca.cosc3p91.a4.gameobjects.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Map {
|
||||
|
||||
static int MAXSIZE = 50;
|
||||
|
||||
private CasaDeNarino townHall;
|
||||
|
||||
private int guardTime;
|
||||
|
||||
public List<Building> contains;
|
||||
|
||||
public List<Inhabitant> inhabitants;
|
||||
|
||||
public Map(CasaDeNarino casaDeNarino, int gTime) {
|
||||
contains = new ArrayList<>();
|
||||
inhabitants = new ArrayList<>();
|
||||
this.townHall = casaDeNarino;
|
||||
this.contains.add(casaDeNarino);
|
||||
this.inhabitants.add(new Worker()); this.inhabitants.add(new Worker());
|
||||
this.inhabitants.add(new Collector());
|
||||
this.guardTime = gTime;
|
||||
}
|
||||
|
||||
public void move(Infantry i, Tile t) {
|
||||
|
||||
}
|
||||
|
||||
public void inRange(Infantry i, Building b) {
|
||||
|
||||
}
|
||||
|
||||
public boolean build(Tile t, Building b) {
|
||||
int goldCost = b.getStage().getCost(SaulGoodMine.resource);
|
||||
int ironCost = b.getStage().getCost(IronMine.resource);
|
||||
int woodCost = b.getStage().getCost(LumberMine.resource);
|
||||
CasaDeNarino hall = getTownHall();
|
||||
if (hall.getCurrentGold() >= goldCost && hall.getCurrentIron() >= ironCost && hall.getCurrentWood() >= woodCost) {
|
||||
if(!hall.addGold(-goldCost))
|
||||
throw new RuntimeException("Unable to subtract gold despite valid check!");
|
||||
if(!hall.addIron(-ironCost))
|
||||
throw new RuntimeException("Unable to subtract iron despite valid check!");
|
||||
if(!hall.addWood(-woodCost))
|
||||
throw new RuntimeException("Unable to subtract wood despite valid check!");
|
||||
contains.add(b);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean upgradeBuilding(int buildingIndex) {
|
||||
|
||||
if (buildingIndex >= contains.size()) return false;
|
||||
|
||||
Building b = contains.get(buildingIndex);
|
||||
|
||||
int currentLevel = b.getLevel();
|
||||
CasaDeNarino hall = getTownHall();
|
||||
|
||||
if (currentLevel >= 2) return false;
|
||||
else 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(int inhabitantIndex) {
|
||||
|
||||
if (inhabitantIndex >= inhabitants.size()) return false;
|
||||
|
||||
Inhabitant i = inhabitants.get(inhabitantIndex);
|
||||
|
||||
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) {
|
||||
CasaDeNarino hall = getTownHall();
|
||||
int goldCost = i.getCost();
|
||||
|
||||
if (hall.getCurrentGold() >= goldCost) {
|
||||
if(!hall.addGold(-goldCost))
|
||||
throw new RuntimeException("Unable to subtract gold despite valid check!");
|
||||
inhabitants.add(i);
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public int getGuardTime() {
|
||||
return guardTime;
|
||||
}
|
||||
|
||||
public void setGuardTime(int gTime) {
|
||||
this.guardTime = gTime;
|
||||
}
|
||||
|
||||
public CasaDeNarino getTownHall(){
|
||||
return townHall;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Archer extends Infantry {
|
||||
|
||||
static int cost = 4;
|
||||
|
||||
private int lvl = 0;
|
||||
|
||||
public Archer() {
|
||||
super(90, 2, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(Tile t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPosition() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return lvl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevel(int level) {
|
||||
lvl = level;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class ArcherTower extends DefenseBuilding {
|
||||
|
||||
public ArcherTower() {
|
||||
setLevel(1);
|
||||
upgrade(DefenseStages.archerTowerStages[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stage getUpgradeStage() {
|
||||
return DefenseStages.archerTowerStages[getLevel()+1];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class Building implements Serializable {
|
||||
|
||||
// members
|
||||
private int level;
|
||||
private int health;
|
||||
|
||||
private Stage stage;
|
||||
|
||||
private int goldCost;
|
||||
private int ironCost;
|
||||
private int woodCost;
|
||||
|
||||
private int buildTime;
|
||||
|
||||
public ArrayList<Tile> tiles = new ArrayList<>();
|
||||
public ArrayList<Inhabitant> inhabitants = new ArrayList<>();
|
||||
|
||||
// functions
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public int getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public int getCost(String type) {
|
||||
return (type.equals("gold")) ? (goldCost) :
|
||||
(type.equals("iron")) ? (ironCost) : woodCost;
|
||||
}
|
||||
|
||||
public Stage getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
public abstract Stage getUpgradeStage();
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public void setHealth(int health) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public void setStage(Stage stage) {
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
public void addInhabitant(Inhabitant newMember) {
|
||||
inhabitants.add(newMember);
|
||||
// newMember.setBuilding(this);
|
||||
}
|
||||
|
||||
public void upgrade(Stage stage) {
|
||||
this.stage = stage;
|
||||
this.health += stage.dHealth;
|
||||
// evil hack
|
||||
String name = stage.getClass().getSimpleName();
|
||||
this.level = Integer.parseInt(name.charAt(name.length()-1) + "") - 1;
|
||||
// interact with the timer regarding Upgrade time
|
||||
}
|
||||
|
||||
public int getBuildTime() {
|
||||
return buildTime;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Cannon extends DefenseBuilding {
|
||||
|
||||
public Cannon() {
|
||||
setLevel(1);
|
||||
upgrade(DefenseStages.cannonStages[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stage getUpgradeStage() {
|
||||
return DefenseStages.cannonStages[getLevel()+1];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class CasaDeNarino extends Building {
|
||||
|
||||
private int goldCapacity = 0;
|
||||
private int ironCapacity = 0;
|
||||
private int woodCapacity = 0;
|
||||
|
||||
private int currentGold = 0;
|
||||
private int currentIron = 0;
|
||||
private int currentWood = 50;
|
||||
|
||||
public CasaDeNarino(int lvl, VillageStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stage getUpgradeStage() {
|
||||
return VillageHallStages.villageStages[getLevel()+1];
|
||||
}
|
||||
|
||||
public void upgrade(VillageStage stage) {
|
||||
super.upgrade(stage);
|
||||
this.goldCapacity += stage.getGoldCapacityIncrease();
|
||||
this.ironCapacity += stage.getIronCapacityIncrease();
|
||||
this.woodCapacity += stage.getWoodCapacityIncrease();
|
||||
}
|
||||
|
||||
|
||||
public int getGoldCapacity() {
|
||||
return goldCapacity;
|
||||
}
|
||||
|
||||
public int getIronCapacity() {
|
||||
return ironCapacity;
|
||||
}
|
||||
|
||||
public int getWoodCapacity() {
|
||||
return woodCapacity;
|
||||
}
|
||||
|
||||
public int getCurrentGold() {
|
||||
return currentGold;
|
||||
}
|
||||
|
||||
public int getCurrentIron() {
|
||||
return currentIron;
|
||||
}
|
||||
|
||||
public int getCurrentWood() {return currentWood;}
|
||||
|
||||
public boolean addGold(int amount) {
|
||||
int newGold = this.currentGold + amount;
|
||||
if (newGold <= goldCapacity && this.currentGold + amount >= 0){
|
||||
this.currentGold += amount;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addIron(int amount) {
|
||||
int newIron = this.currentIron + amount;
|
||||
if (newIron <= ironCapacity && newIron >= 0) {
|
||||
this.currentIron += amount;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addWood(int amount) {
|
||||
int newWood = this.currentWood + amount;
|
||||
if (newWood <= woodCapacity && newWood >= 0) {
|
||||
this.currentWood += amount;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Catapult extends Infantry {
|
||||
|
||||
static int cost = 6;
|
||||
|
||||
private int lvl = 0;
|
||||
|
||||
public Catapult() {
|
||||
super(80, 12, 12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(Tile t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPosition() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return lvl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevel(int level) {
|
||||
lvl = level;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Collector implements Inhabitant {
|
||||
|
||||
private int averageCollectionRate;
|
||||
|
||||
static int cost = 2;
|
||||
|
||||
private int lvl = 0;
|
||||
|
||||
public int getCollectionRate() {
|
||||
return averageCollectionRate;
|
||||
}
|
||||
|
||||
public void setCollectionRate(int rate) {
|
||||
averageCollectionRate = rate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(Tile t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPosition() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return lvl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevel(int level) {
|
||||
lvl = level;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public abstract class DefenseBuilding extends Building {
|
||||
|
||||
private int damage = 0;
|
||||
private int range = 0;
|
||||
|
||||
public void upgrade(DefenseStage stage) {
|
||||
super.upgrade(stage);
|
||||
this.damage += stage.getDamageChange();
|
||||
this.range += stage.getRangeChange();
|
||||
}
|
||||
|
||||
public void attack(Infantry attacker) {
|
||||
|
||||
}
|
||||
|
||||
public int getDamage(){
|
||||
return damage;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
class DefenseStage extends Stage {
|
||||
|
||||
protected int dDamage;
|
||||
|
||||
protected int dRange;
|
||||
|
||||
public DefenseStage(int dHealth, int goldCost, int requiredVillageLevel, Time upgradeTime, int ironCost, int woodCost,
|
||||
int damageIncrease, int rangeIncrease) {
|
||||
super(dHealth, goldCost, requiredVillageLevel, upgradeTime, ironCost, woodCost);
|
||||
this.dDamage = damageIncrease;
|
||||
this.dRange = rangeIncrease;
|
||||
}
|
||||
|
||||
public int getDamageChange() {
|
||||
return dDamage;
|
||||
}
|
||||
|
||||
public int getRangeChange() {
|
||||
return dRange;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a4.util.Time;
|
||||
|
||||
public class DefenseStages {
|
||||
|
||||
public static class ArcherTowerStage1 extends DefenseStage {
|
||||
public ArcherTowerStage1() {
|
||||
super(100, 0, 0, new Time().offsetMinutes(1), 25, 75, 4,6);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ArcherTowerStage2 extends DefenseStage {
|
||||
public ArcherTowerStage2() {
|
||||
super(150, 50, 1, new Time().offsetMinutes(15), 25, 200, 8,8);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ArcherTowerStage3 extends DefenseStage {
|
||||
public ArcherTowerStage3() {
|
||||
super(200, 100, 2, new Time().offsetHours(1), 50, 300, 12,12);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CannonStage1 extends DefenseStage {
|
||||
public CannonStage1() {
|
||||
super(125, 0, 0, new Time().offsetMinutes(2), 100, 25, 8,4);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CannonStage2 extends DefenseStage {
|
||||
public CannonStage2() {
|
||||
super(175, 50, 1, new Time().offsetMinutes(20), 125, 25, 12,6);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CannonStage3 extends DefenseStage {
|
||||
public CannonStage3() {
|
||||
super(225, 100, 2, new Time().offsetHours(1), 200, 50, 14,8);
|
||||
}
|
||||
}
|
||||
|
||||
public static DefenseStage[] archerTowerStages = {new DefenseStages.ArcherTowerStage1(), new DefenseStages.ArcherTowerStage2(), new DefenseStages.ArcherTowerStage3()};
|
||||
public static DefenseStage[] cannonStages = {new DefenseStages.CannonStage1(), new DefenseStages.CannonStage2(), new DefenseStages.CannonStage3()};
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Farm extends ResourceBuilding {
|
||||
|
||||
public Farm(int lvl, ResourceStage baseStage) {
|
||||
setLevel(lvl);
|
||||
upgrade(baseStage);
|
||||
}
|
||||
|
||||
public int getPopulationContribution() {
|
||||
return getHarvestRate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceHarvestHandler getHarvestHandler() {
|
||||
return hall -> {};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResource() {
|
||||
return "UNUSED";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stage getUpgradeStage() {
|
||||
return ResourceStages.goldStages[getLevel()+1];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public abstract class Infantry implements Inhabitant {
|
||||
|
||||
private int health;
|
||||
|
||||
private int damage;
|
||||
|
||||
private int range;
|
||||
|
||||
public Infantry(int hitPoints, int damage, int range) {
|
||||
this.health = hitPoints;
|
||||
this.damage = damage;
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
public void attack(Building b) {
|
||||
}
|
||||
|
||||
public int getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
public int getRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
public void setHealth(int health) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public void setDamage(int damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public void setRange(int range) {
|
||||
this.range = range;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface Inhabitant extends Serializable {
|
||||
|
||||
int lvl = 0;
|
||||
|
||||
void move(Tile t);
|
||||
|
||||
void getPosition();
|
||||
|
||||
int getLevel();
|
||||
void setLevel(int level);
|
||||
int getCost();
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class IronMine extends ResourceBuilding {
|
||||
|
||||
public static String resource = "iron";
|
||||
|
||||
public IronMine(ResourceStage baseStage) {
|
||||
upgrade(baseStage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceHarvestHandler getHarvestHandler() {
|
||||
return hall -> hall.addIron(getHarvestRate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stage getUpgradeStage() {
|
||||
return ResourceStages.ironStages[getLevel()+1];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class Knight extends Infantry {
|
||||
|
||||
static int cost = 6;
|
||||
|
||||
private int lvl = 0;
|
||||
|
||||
public Knight() {
|
||||
super(150, 6, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(Tile t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPosition() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return lvl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevel(int level) {
|
||||
lvl = level;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
public class LumberMine extends ResourceBuilding {
|
||||
|
||||
public static String resource = "wood";
|
||||
|
||||
public LumberMine(ResourceStage baseStage) {
|
||||
upgrade(baseStage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceHarvestHandler getHarvestHandler() {
|
||||
return hall -> hall.addWood(getHarvestRate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stage getUpgradeStage() {
|
||||
return ResourceStages.woodStages[getLevel()+1];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package ca.cosc3p91.a4.gameobjects;
|
||||
|
||||
import ca.cosc3p91.a4.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);
|
||||
|
||||
private int harvest_rate;
|
||||
private Time nextHarvestTime;
|
||||
|
||||
public ResourceBuilding() {
|
||||
nextHarvestTime = Time.getTime().offsetTime(harvestMinTime);
|
||||
}
|
||||
|
||||
public void upgrade(ResourceStage stage) {
|
||||
super.upgrade(stage);
|
||||
this.harvest_rate += stage.getHarvestRateIncrease();
|
||||
}
|
||||
|
||||
public void update(CasaDeNarino hall){
|
||||
if (nextHarvestTime.occurred()){
|
||||
getHarvestHandler().harvest(hall);
|
||||
nextHarvestTime = Time.getTime().offsetTime(harvestMinTime);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract ResourceHarvestHandler getHarvestHandler();
|
||||
|
||||
public int getHarvestRate(){
|
||||
return harvest_rate;
|
||||
}
|
||||
|
||||
public abstract String getResource();
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue