refine package name

main
Brett 2023-03-24 15:15:07 -04:00
parent 610c9b5801
commit e20d1a73f1
74 changed files with 186 additions and 160 deletions

View File

@ -0,0 +1,10 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="378" name="Java" />
</Languages>
</inspection_tool>
</profile>
</component>

View File

@ -1,7 +1,7 @@
package ca.cosc3p91.a2;
package ca.cosc3p91.a3;
import ca.cosc3p91.a2.game.GameEngine;
import ca.cosc3p91.a2.gameobjects.Stage;
import ca.cosc3p91.a3.game.GameEngine;
import ca.cosc3p91.a3.gameobjects.Stage;
public class Main {

View File

@ -1,10 +1,10 @@
package ca.cosc3p91.a2.game;
package ca.cosc3p91.a3.game;
import ca.cosc3p91.a2.gameobjects.*;
import ca.cosc3p91.a2.player.*;
import ca.cosc3p91.a2.util.Print;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a2.util.Util;
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 java.io.BufferedReader;
import java.io.IOException;

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.game;
package ca.cosc3p91.a3.game;
import ca.cosc3p91.a2.gameobjects.*;
import ca.cosc3p91.a3.gameobjects.*;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Archer extends Infantry {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class ArcherTower extends DefenseBuilding {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Cannon extends DefenseBuilding {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class CasaDeNarino extends Building {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Catapult extends Infantry {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Collector implements Inhabitant {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public abstract class DefenseBuilding extends Building {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
class DefenseStage extends Stage {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public class DefenseStages {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Farm extends ResourceBuilding {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public abstract class Infantry implements Inhabitant {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.game.Map;
import ca.cosc3p91.a3.game.Map;
public interface Inhabitant {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class IronMine extends ResourceBuilding {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Knight extends Infantry {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class LumberMine extends ResourceBuilding {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public abstract class ResourceBuilding extends Building {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public class ResourceStage extends Stage {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public class ResourceStages {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class SaulGoodMine extends ResourceBuilding {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Soldier extends Infantry {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
import java.util.HashMap;

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import java.util.List;

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public class VillageHallStages {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public class VillageStage extends Stage {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Worker implements Inhabitant {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.player;
package ca.cosc3p91.a3.player;
public class Player {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.userinterface;
package ca.cosc3p91.a3.userinterface;
public class GuiManager {
}

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.util;
package ca.cosc3p91.a3.util;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.util;
package ca.cosc3p91.a3.util;
public class Time {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.util;
package ca.cosc3p91.a3.util;
import java.util.Random;

View File

@ -1,19 +0,0 @@
package ca.cosc3p91.a2.gameobjects;
import ca.cosc3p91.a2.game.Map;
public interface Inhabitant {
Map map = null;
Building building = null;
int lvl = 0;
void move(Tile t);
void getPosition();
int getLevel();
void setLevel(int level);
int getCost();
}

View File

@ -1,6 +0,0 @@
package ca.cosc3p91.a2.player;
public class Player {
}

View File

@ -1,7 +1,6 @@
package ca.cosc3p91.a2;
package ca.cosc3p91.a3;
import ca.cosc3p91.a2.game.GameEngine;
import ca.cosc3p91.a2.gameobjects.Stage;
import ca.cosc3p91.a3.game.GameEngine;
public class Main {

View File

@ -1,14 +1,19 @@
package ca.cosc3p91.a2.game;
package ca.cosc3p91.a3.game;
import ca.cosc3p91.a2.gameobjects.*;
import ca.cosc3p91.a2.gameobjects.factory.BuildingFactory;
import ca.cosc3p91.a2.gameobjects.factory.InhabitantFactory;
import ca.cosc3p91.a2.player.*;
import ca.cosc3p91.a2.userinterface.GameDisplay;
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 java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Random;
public class GameEngine<T> implements Runnable {
public class GameEngine implements Runnable {
public static final double GOLD_FACTOR = 5;
public static final double IRON_FACTOR = 1;
@ -32,22 +37,24 @@ public class GameEngine<T> implements Runnable {
}
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));
// 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(){
@ -242,6 +249,17 @@ public class GameEngine<T> implements Runnable {
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();
}
}
}

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.game;
package ca.cosc3p91.a3.game;
import ca.cosc3p91.a2.gameobjects.*;
import ca.cosc3p91.a3.gameobjects.*;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Archer extends Infantry {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class ArcherTower extends DefenseBuilding {

View File

@ -1,8 +1,9 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import java.io.Serializable;
import java.util.ArrayList;
public abstract class Building {
public abstract class Building implements Serializable {
// members
private int level;

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Cannon extends DefenseBuilding {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class CasaDeNarino extends Building {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Catapult extends Infantry {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Collector implements Inhabitant {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public abstract class DefenseBuilding extends Building {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
class DefenseStage extends Stage {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public class DefenseStages {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Farm extends ResourceBuilding {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public abstract class Infantry implements Inhabitant {

View File

@ -0,0 +1,17 @@
package ca.cosc3p91.a3.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();
}

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class IronMine extends ResourceBuilding {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Knight extends Infantry {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class LumberMine extends ResourceBuilding {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public abstract class ResourceBuilding extends Building {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public class ResourceStage extends Stage {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public class ResourceStages {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class SaulGoodMine extends ResourceBuilding {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Soldier extends Infantry {

View File

@ -1,10 +1,10 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
import java.util.HashMap;
import java.io.Serializable;
public abstract class Stage {
public abstract class Stage implements Serializable {
protected int dHealth;

View File

@ -1,6 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
import java.util.List;
package ca.cosc3p91.a3.gameobjects;
public class Tile {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public class VillageHallStages {

View File

@ -1,6 +1,6 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
import ca.cosc3p91.a2.util.Time;
import ca.cosc3p91.a3.util.Time;
public class VillageStage extends Stage {

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.gameobjects;
package ca.cosc3p91.a3.gameobjects;
public class Worker implements Inhabitant {

View File

@ -1,7 +1,7 @@
package ca.cosc3p91.a2.gameobjects.factory;
package ca.cosc3p91.a3.gameobjects.factory;
import ca.cosc3p91.a2.gameobjects.*;
import ca.cosc3p91.a2.util.Util;
import ca.cosc3p91.a3.gameobjects.*;
import ca.cosc3p91.a3.util.Util;
public class BuildingFactory {
public Building getBuilding(String buildingName) {

View File

@ -1,7 +1,7 @@
package ca.cosc3p91.a2.gameobjects.factory;
package ca.cosc3p91.a3.gameobjects.factory;
import ca.cosc3p91.a2.gameobjects.*;
import ca.cosc3p91.a2.util.Util;
import ca.cosc3p91.a3.gameobjects.*;
import ca.cosc3p91.a3.util.Util;
public class InhabitantFactory {
public Inhabitant getInhabitant(String inhabitantName) {

View File

@ -0,0 +1,6 @@
package ca.cosc3p91.a3.player;
public class Player {
}

View File

@ -1,9 +1,9 @@
package ca.cosc3p91.a2.userinterface;
package ca.cosc3p91.a3.userinterface;
import ca.cosc3p91.a2.game.Map;
import ca.cosc3p91.a2.gameobjects.Building;
import ca.cosc3p91.a2.gameobjects.Inhabitant;
import ca.cosc3p91.a2.util.Print;
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 java.io.BufferedReader;
import java.io.IOException;

View File

@ -1,8 +1,8 @@
package ca.cosc3p91.a2.util;
package ca.cosc3p91.a3.util;
import ChallengeDecision.*;
import ca.cosc3p91.a2.game.Map;
import ca.cosc3p91.a2.gameobjects.*;
import ca.cosc3p91.a3.game.Map;
import ca.cosc3p91.a3.gameobjects.*;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.util;
package ca.cosc3p91.a3.util;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -1,6 +1,8 @@
package ca.cosc3p91.a2.util;
package ca.cosc3p91.a3.util;
public class Time {
import java.io.Serializable;
public class Time implements Serializable {
private long timeSeconds;

View File

@ -1,4 +1,4 @@
package ca.cosc3p91.a2.util;
package ca.cosc3p91.a3.util;
import java.util.Random;