Skip to content

Commit

Permalink
unit info 2
Browse files Browse the repository at this point in the history
  • Loading branch information
NikiSP committed Apr 25, 2022
1 parent 2c3cdf4 commit 23f8136
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 18 deletions.
46 changes: 46 additions & 0 deletions controllers/InitializeGameInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
import models.maprelated.*;

public class InitializeGameInfo {
public static HashMap<String, String> unitNeededResource=new HashMap<String,String>();
public static HashMap<String, String> unitNeededTech=new HashMap<String,String>();
private static HashMap<String, String> terrainInfo = new HashMap<>();
private static HashMap<String, String> featureInfo = new HashMap<>();
private static HashMap<String, String> resourceInfo = new HashMap<>();
private static HashMap<String, String> technologyInfo = new HashMap<>();
public static HashMap<String, String> unitInfo=new HashMap<>();
private static final ArrayList<String> terrainNames = new ArrayList<String>();
private static final ArrayList<String> resourceNames = new ArrayList<String>();
private static final HashMap<String, ArrayList<String>> appropriateTerrain = new HashMap<String, ArrayList<String>>();
Expand Down Expand Up @@ -52,6 +55,48 @@ public static World getWorld() {
return world;
}

public static void initializeUnitInfo(){

try {
String readUnitInfo = new String(Files.readAllBytes(Paths.get("files/UnitInfo.txt")));
String[] readInfo = readUnitInfo.split("\n");
for (String temp : readInfo) {
String[] read = temp.split("#");
String name = read[0];
String info = read[1];

String tech=info.split(" ")[6];
String resource=info.split(" ")[5];

if(tech.equals("NA"))
{
unitInfo.put(name, null);
}
else
{
unitInfo.put(name, tech);
}
if(resource.equals("NA"))
{
unitNeededResource.put(name,null);
}
else
{
unitNeededResource.put(name,resource);
}



}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

public static void initializeTerrainInfo() {
try {
String readTerrainInfo = new String(Files.readAllBytes(Paths.get("files/TerrainInfo.txt")));
Expand Down Expand Up @@ -178,6 +223,7 @@ public static void run() {
initializeTechnologyInfo();
initializeHashMap();
initializeGameWorld();
initializeUnitInfo();
}

private static void initializeGameWorld() {
Expand Down
70 changes: 52 additions & 18 deletions models/units/Unit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package models.units;

import controllers.InitializeGameInfo;
import enums.UnitState;
import enums.UnitType;
import models.Player;
Expand All @@ -8,25 +9,61 @@
public class Unit
{
private int health;
private int speed;
private int militaryPower;
private int combatStrength;
private int rangedStrength;
private int range;
private Hex currentHex;
private UnitState state;
private int MP;
private UnitType type;
private int maxDistance;
private Player owner;
private String name;
private int cost;
private String neededTech;
private String neededResource;
private Player owner;

public Unit(String name,Hex hex )
{
this.currentHex=hex;
this.name=name;

String[] info=InitializeGameInfo.unitInfo.get(name).split(" ");
this.cost=Integer.parseInt(info[0]);
combatStrength=Integer.parseInt(info[1]);
rangedStrength=Integer.parseInt(info[2]);
range=Integer.parseInt(info[3]);
MP=Integer.parseInt(info[4]);
health=10;


String tech=info[6];
String resource=info[5];

if(tech.equals("NA"))
{
neededTech=null;
}
else
{
neededTech=tech;
}
if(resource.equals("NA"))
{
neededResource=null;
}
else
{
neededResource=resource;
}

Unit(String name, int speed, int militaryPower, UnitType type, int maxDistance, Player owner){
this.name = name;
this.speed = speed;
this.militaryPower = militaryPower;
this.type = type;
this.maxDistance = maxDistance;
this.owner = owner;
}



public Unit(String name, int speed, int militaryPower, UnitType type2, int maxDistance, Player owner) {
}



public int getHealth() {
return this.health;
}
Expand All @@ -39,10 +76,7 @@ public void decreaseHealth(int amount) {
health-=amount;
}

public int getSpeed() {
return this.speed;
}


public Hex getCurrentHex() {
return this.currentHex;
}
Expand Down Expand Up @@ -71,8 +105,8 @@ public void decreaseMP(int amount) {
}


public int getMaxDistance() {
return maxDistance;
public int getRange() {
return range;
}

public Player getOwner() {
Expand Down

0 comments on commit 23f8136

Please sign in to comment.