Skip to content

Commit

Permalink
added currentClass and hashmap for all classes as a start for #77 (fi…
Browse files Browse the repository at this point in the history
…nally :D)
  • Loading branch information
projectdelphai committed Oct 23, 2014
1 parent b97cf50 commit 1e3d51e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/main/java/com/jadventure/game/entities/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Iterator;

/**
* superclass for all entities (includes player, monsters...)
Expand Down Expand Up @@ -39,8 +40,37 @@ public abstract class Entity {
private int armour;
private String weapon = "empty";
private HashMap<String, Item> equipment;
public HashMap<String, Integer> classStats = new HashMap<String, Integer>() {
{
put("Recruit", 0);
put("Sewer Rat", 0);
};
};
private String currentClassName;
protected Storage storage;
Random globalRand = new Random();

public String getCurrentClass() {
return this.currentClassName;
}

public void setCurrentClass(String className) {
this.currentClassName = className;
}

public void checkCurrentClass() {
Iterator it = this.classStats.entrySet().iterator();
int highestClassLevel = 0;
String highestClassName = "";
while (it.hasNext()) {
Map.Entry<String, Integer> pairs = (Map.Entry<String, Integer>)it.next();
if (pairs.getValue() > highestClassLevel) {
highestClassLevel = pairs.getValue();
highestClassName = pairs.getKey();
}
}
this.currentClassName = highestClassName;
}

// maybe not all entities start at full health, etc.
public Entity() {
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/jadventure/game/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static Player load(String name) {
player.setDexterity(json.get("dexterity").getAsInt());
player.setLuck(json.get("luck").getAsInt());
player.setStealth(json.get("stealth").getAsInt());
player.equipItem("rightHand", new Item(json.get("weapon").getAsString()));
player.equipItem("rightHand", new Item(json.get("weapon").getAsString()));
if (json.has("items")) {
HashMap<String, Integer> items = new Gson().fromJson(json.get("items"), new TypeToken<HashMap<String, Integer>>(){}.getType());
ArrayList<ItemStack> itemList = new ArrayList<ItemStack>();
Expand Down Expand Up @@ -145,6 +145,15 @@ public static Player getInstance(String playerClass){
player.setLuck(luck);
player.setStealth(json.get("stealth").getAsInt());
player.setIntro(json.get("intro").getAsString());
if (player.getName().equals("Recruit")) {
player.classStats.put("Recruit", 50);
player.setCurrentClass("Recruit");
} else if (player.getName().equals("Sewer Rat")) {
player.classStats.put("Sewer Rat", 50);
player.setCurrentClass("Sewer Rat");
} else {
System.out.println("Not a valid class");
}
reader.close();
} catch (FileNotFoundException ex) {
QueueProvider.offer( "Unable to open file '" + fileName + "'.");
Expand Down Expand Up @@ -178,6 +187,7 @@ public void getStats(){
weaponName = "hands";
}
String message = "\nPlayer name: " + getName();
message += "\nClass: " + getCurrentClass();
message += "\nCurrent weapon: " + weaponName;
message += "\nGold: " + getGold();
message += "\nHealth/Max: " + getHealth() + "/" + getHealthMax();
Expand Down

0 comments on commit 1e3d51e

Please sign in to comment.