diff --git a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/Money.java b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/Money.java new file mode 100644 index 0000000..96a0968 --- /dev/null +++ b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/Money.java @@ -0,0 +1,27 @@ +package com.example.cis.mazeminotaurs.character; + +import com.example.cis.mazeminotaurs.R; + +/** + * Created by jusmith on 4/5/17. + */ + +public enum Money { + COPPER(R.string.copper), + SILVER(R.string.silver), + GOLD(R.string.gold); + + private int resId; + + Money(int resId) { + setResId(resId); + } + + public int getResId() { + return resId; + } + + public void setResId(int resId) { + this.resId = resId; + } +} diff --git a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/PlayerCharacter.java b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/PlayerCharacter.java index c1eb69c..6e719a6 100644 --- a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/PlayerCharacter.java +++ b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/PlayerCharacter.java @@ -1,11 +1,10 @@ package com.example.cis.mazeminotaurs.character; -import android.util.Log; - import com.example.cis.mazeminotaurs.Armor; import com.example.cis.mazeminotaurs.AttributeScore; import com.example.cis.mazeminotaurs.AttributeScoreGenerator; import com.example.cis.mazeminotaurs.R; +import com.example.cis.mazeminotaurs.character.classes.Amazon; import com.example.cis.mazeminotaurs.character.classes.Barbarian; import com.example.cis.mazeminotaurs.character.classes.BaseClass; import com.example.cis.mazeminotaurs.character.stats.Score; @@ -17,11 +16,11 @@ */ public class PlayerCharacter { - private final String TAG = "PlayerCharacter Class"; - private HashMap mCoreStats = new HashMap<>(); + private HashMap mScores = new HashMap<>(); private BaseClass mCharClass; private Gender mGender; + private HashMap mMoney = new HashMap<>(); private int mAge; private String mName; private Armor mHelmet; @@ -29,36 +28,39 @@ public class PlayerCharacter { private Armor mShield; public PlayerCharacter() { - Log.i(TAG, "Creating PlayerCharacter"); + initalizeMoneyMap(); + setAge(0); setCharClass(new Barbarian(this, R.string.barb_axe, R.string.bow)); setName("Thorin"); - + + getMoney().put(Money.SILVER, getCharClass().getStartGold()); + AttributeScore[] scores = new AttributeScoreGenerator().nextValidSet(); for (int i = 0; i < scores.length; i++) { - mCoreStats.put(Score.values()[i], scores[i]); + mScores.put(Score.values()[i], scores[i]); } } public int getMeleeMod() { - return getCoreStatScore(Score.MIGHT).getModifier() + - getCoreStatScore(Score.GRACE).getModifier() + - getCoreStatScore(Score.LUCK).getModifier(); + return getScore(Score.MIGHT).getModifier() + + getScore(Score.GRACE).getModifier() + + getScore(Score.LUCK).getModifier(); } public int getMissleMod() { - return getCoreStatScore(Score.SKILL).getModifier() + - getCoreStatScore(Score.WITS).getModifier() + - getCoreStatScore(Score.LUCK).getModifier(); + return getScore(Score.SKILL).getModifier() + + getScore(Score.WITS).getModifier() + + getScore(Score.LUCK).getModifier(); } public int getInititive() { - return 10 + getCoreStatScore(Score.SKILL).getModifier() + - getCoreStatScore(Score.WITS).getModifier(); + return 10 + getScore(Score.SKILL).getModifier() + + getScore(Score.WITS).getModifier(); } public int getDC() { - return 12 + getCoreStatScore(Score.LUCK).getModifier(); + return 12 + getScore(Score.LUCK).getModifier(); } public int getEDC() { @@ -76,27 +78,143 @@ public int getEDC() { return getDC() + armorBonus; } - public int getHitTotal(){ + public int getHitTotal() { //return mCharClass.getHits() + getMod(Score.MIGHT); return 0; } - public int getCharisma(){ - return getCoreStatScore(Score.WILL).getModifier() + - getCoreStatScore(Score.GRACE).getModifier() + - getCoreStatScore(Score.LUCK).getModifier(); + public int getAthleticProwess(){ + return getScore(Score.MIGHT).getModifier() + + getScore(Score.SKILL).getModifier() + + getScore(Score.LUCK).getModifier(); + } + + public int getDangerEvasion(){ + return getScore(Score.WITS).getModifier() + + getScore(Score.SKILL).getModifier() + + getScore(Score.LUCK).getModifier(); + } + + public int getMysticForitude(){ + return getScore(Score.WITS).getModifier() + + getScore(Score.WILL).getModifier() + + getScore(Score.LUCK).getModifier(); + } + + public int getPhysicalVigor(){ + return getScore(Score.MIGHT).getModifier() + + getScore(Score.WILL).getModifier() + + getScore(Score.LUCK).getModifier(); + } + + public int getCharisma() { + return getScore(Score.WILL).getModifier() + + getScore(Score.GRACE).getModifier() + + getScore(Score.LUCK).getModifier(); + } + + public Gender getGender() { + return mGender; + } + + public void setGender(Gender gender) { + mGender = gender; + } + + public void addMoney(Money money, int amount) { + getMoney().put(money, getMoney().get(money) + amount); + validateMoney(); + } + + public HashMap getMoney() { + return mMoney; + } + + public void setMoney(HashMap money) { + mMoney = money; + } + + private void initalizeMoneyMap() { + mMoney.put(Money.COPPER, 0); + mMoney.put(Money.SILVER, 0); + mMoney.put(Money.GOLD, 0); + } + + public void validateMoney() { + HashMap cash = getMoney(); + + int tradedUpSilver = cash.get(Money.COPPER) / 100; + int tradedUpGold = cash.get(Money.SILVER) / 100; + + cash.put(Money.COPPER, cash.get(Money.COPPER) % 100); + cash.put(Money.SILVER, (cash.get(Money.SILVER) % 100) + tradedUpSilver); + cash.put(Money.GOLD, cash.get(Money.GOLD) + tradedUpGold); + } + + public Armor getHelmet() { + return mHelmet; + } + + public void setHelmet(Armor helmet) { + mHelmet = helmet; + } + + public Armor getBreastplate() { + return mBreastplate; + } + + public void setBreastplate(Armor breastplate) { + mBreastplate = breastplate; + } + + public Armor getShield() { + return mShield; + } + + public void setShield(Armor shield) { + mShield = shield; } - public AttributeScore getCoreStatScore(Score scoreStat) { - return mCoreStats.get(scoreStat); + public boolean canAddToScore(Score score) { + boolean isPrimary = getCharClass().getPrimaryAttributes().contains(score); + int scoreValue = getScore(score).getScore(); + + if (isPrimary) { + return scoreValue < 21; + } else { + return scoreValue < 20; + } } - public HashMap getCoreStats() { - return mCoreStats; + public void validateScores() { + for (Score score: Score.values()) { + boolean isPrimary = getCharClass().getPrimaryAttributes().contains(score); + int scoreValue = getScore(score).getScore(); + + if (isPrimary && scoreValue > 21) { + getScore(score).setScore(21); + } else if (!isPrimary && scoreValue > 20) { + getScore(score).setScore(20); + } + } } - public void setCoreStats(HashMap coreStats) { - mCoreStats = coreStats; + protected void debugPrintScores() { + for (Score score : getScores().keySet()) { + System.out.println(score.toString() + ":" + String.valueOf(getScore(score).getScore())); + } + } + + public AttributeScore getScore(Score scoreStat) { + return mScores.get(scoreStat); + } + + public HashMap getScores() { + return mScores; + } + + public void setScores(HashMap scores) { + mScores = scores; } public BaseClass getCharClass() { @@ -122,4 +240,5 @@ public String getName() { public void setName(String name) { mName = name; } + } diff --git a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Amazon.java b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Amazon.java index 626d9e5..22c24df 100644 --- a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Amazon.java +++ b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Amazon.java @@ -1,41 +1,8 @@ package com.example.cis.mazeminotaurs.character.classes; -import com.example.cis.mazeminotaurs.R; -import com.example.cis.mazeminotaurs.character.PlayerCharacter; -import com.example.cis.mazeminotaurs.character.Gender; -import com.example.cis.mazeminotaurs.character.stats.Score; -import com.example.cis.mazeminotaurs.util.Util; - /** - * Created by jusmith on 4/4/17. + * Created by jusmith on 4/13/17. */ -public class Amazon extends Warrior{ - public Amazon(PlayerCharacter playerCharacter) { - Score[] primAttributes = {Score.SKILL, Score.GRACE}; - - int rolledGold = 0; - for (int i = 0; i < 3; i++) { - rolledGold += Util.roll(6); - } - - setAddedHits(0); - setBasicHits(12); - setPlayerCharacter(playerCharacter); - setExperience(0); - setLevel(1); - setPrimaryAttributes(primAttributes); - setRequiredGender(Gender.FEMALE); - setResId(Classes.AMAZON.getResId()); - setStartGold(rolledGold); - setWeaponOfChoice(R.string.bow); - } - - public int getDeadlyShotBonus(){ - return getPlayerCharacter().getCoreStatScore(Score.SKILL).getModifier(); - } - - public int getBattleGraceBonus(){ - return getPlayerCharacter().getCoreStatScore(Score.GRACE).getModifier(); - } +public class Amazon extends Warrior implements Level { } diff --git a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Barbarian.java b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Barbarian.java index e866546..d0bec6a 100644 --- a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Barbarian.java +++ b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Barbarian.java @@ -1,37 +1,39 @@ package com.example.cis.mazeminotaurs.character.classes; -import com.example.cis.mazeminotaurs.R; +import com.example.cis.mazeminotaurs.AttributeScore; import com.example.cis.mazeminotaurs.character.PlayerCharacter; import com.example.cis.mazeminotaurs.character.Gender; import com.example.cis.mazeminotaurs.character.stats.Score; import com.example.cis.mazeminotaurs.util.Util; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; /** * Created by jusmith on 3/31/17. */ -public class Barbarian extends Warrior { +public class Barbarian extends Warrior implements Level{ + private ArrayList> mScoreLevelChoice = new ArrayList<>(); public Barbarian(PlayerCharacter playerCharacter, int choiceWeapon, int startingMissleWeapon) { - Score[] primAttributes = {Score.MIGHT, Score.WILL}; + Score[] primAttrs = {Score.MIGHT, Score.WILL}; + ArrayList primAttributes = new ArrayList<>(); + Collections.addAll(primAttributes, primAttrs); + ArrayList wepsOfChoice = new ArrayList<>(); - wepsOfChoice.add(R.string.barb_axe); - wepsOfChoice.add(R.string.barb_club); - wepsOfChoice.add(R.string.barb_mace); - wepsOfChoice.add(R.string.barb_sword); + for (int weaponResId: Util.sBarbWeapons) { + wepsOfChoice.add(weaponResId); + } int rolledGold = 0; for (int i =0; i < 3; i++) { rolledGold += Util.roll(6); } - setAddedHits(0); setBasicHits(12); - setPlayerCharacter(playerCharacter); - setExperience(0); - setLevel(1); + setCharacter(playerCharacter); setPrimaryAttributes(primAttributes); setRequiredGender(Gender.MALE); setResId(Classes.BARBARIAN.getResId()); @@ -47,11 +49,94 @@ public Barbarian(PlayerCharacter playerCharacter, int choiceWeapon, int starting } } + public void doLevelUp(){ + Score[] possibleScores = {Score.SKILL, Score.WILL, Score.MIGHT}; + doLevelUp(possibleScores[Util.roll(3) - 1]); + } + + public void doLevelUp(Score score) { + if (getLevel() < getEffectiveLevel()){ + + Score[] choices = {Score.SKILL, Score.WILL, Score.MIGHT}; + ArrayList possibleScores = new ArrayList<>(); + for (Score selectScore: choices) { + if(getCharacter().canAddToScore(selectScore)) { + possibleScores.add(selectScore); + } + } + + Score selectedScore; + if (possibleScores.contains(score)) { + selectedScore = score; + } else { + selectedScore = possibleScores.get(Util.roll(possibleScores.size()) - 1); + } + + if (possibleScores.size() > 0) { + while (!getCharacter().canAddToScore(selectedScore)) { + selectedScore = possibleScores.get((possibleScores.indexOf(selectedScore) + 1) % possibleScores.size()); + } + } + + // Contains information about changed scores + HashMap levelData = new HashMap<>(); + + if (getCharacter().canAddToScore(Score.LUCK)) { + AttributeScore luck = getCharacter().getScore(Score.LUCK); + levelData.put(Score.LUCK, luck.getScore()); + luck.setScore(luck.getScore() + 1); + } else { + levelData.put(Score.LUCK, 20); + } + + AttributeScore selectedAttrScore = getCharacter().getScore(selectedScore); + + levelData.put(selectedScore, selectedAttrScore.getScore()); + getScoreLevelChoice().add(levelData); + + selectedAttrScore.setScore(selectedAttrScore.getScore() + 2); + setAddedHits(getAddedHits() + 4); + + setLevel(getLevel() + 1); + getCharacter().validateScores(); + } + } + + public void doLevelDown(){ + if (getLevel() > 1) { + HashMap levelData = getScoreLevelChoice().remove(getScoreLevelChoice().size() - 1); + Score lastSelectedScore = null; + for (Object rawScore: levelData.keySet().toArray()) { + Score score = (Score) rawScore; + if (score != Score.LUCK) { + lastSelectedScore = score; + break; + } + } + + AttributeScore luck = getCharacter().getScore(Score.LUCK); + AttributeScore lastScoreLeveled = getCharacter().getScore(lastSelectedScore); + + setAddedHits(getAddedHits() - 4); + luck.setScore(levelData.get(Score.LUCK)); + lastScoreLeveled.setScore(levelData.get(lastSelectedScore)); + setLevel(getLevel() - 1); + } + } + + public ArrayList> getScoreLevelChoice() { + return mScoreLevelChoice; + } + + public void setScoreLevelChoice(ArrayList> scoreLevelChoice) { + mScoreLevelChoice = scoreLevelChoice; + } + public int getBattleMightBonus(){ - return getPlayerCharacter().getCoreStatScore(Score.MIGHT).getModifier(); + return getCharacter().getScore(Score.MIGHT).getModifier(); } public int getBattleFuryBonus(){ - return getPlayerCharacter().getCoreStatScore(Score.WILL).getModifier(); + return getCharacter().getScore(Score.WILL).getModifier(); } } diff --git a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/BaseClass.java b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/BaseClass.java index 8c16db3..2e07a15 100644 --- a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/BaseClass.java +++ b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/BaseClass.java @@ -9,15 +9,33 @@ /** * Created by jusmith on 3/31/17. + * + * Level is the actual of a character + * EffectiveLevel is what level the character will be after handling leveling up + * + * Example of Usage: + * Assume: + * mLevel = 1; + * mExperience = 2000; + * mEffectiveLevel = 3; + * After calling doLevelUp + * mLevel = 2; + * mExperience = 2000; + * mEffectiveLevel = 3; + * After calling doLevelUp + * mLevel = 3; + * mExperience = 2000; + * mEffectiveLevel = 3; */ public abstract class BaseClass { - private int mAddedHits; + private int mAddedHits = 0; private int mBasicHits; private PlayerCharacter mPlayerCharacter; - private int mExperience; - private int mLevel; - private Score[] mPrimaryAttributes; + private int mExperience = 0; + private int mLevel = 1; + private int mEffectiveLevel = 1; + private ArrayList mPrimaryAttributes; private Gender mRequiredGender; private int mResId; private ArrayList mStartGear; @@ -25,22 +43,22 @@ public abstract class BaseClass { public void updateLevel(){ if (getExperience() < 1000) { - setLevel(1); + setEffectiveLevel(1); } if (getExperience() < 2000) { - setLevel(2); + setEffectiveLevel(2); } if (getExperience() < 4000) { - setLevel(3); + setEffectiveLevel(3); } if (getExperience() < 7000) { - setLevel(4); + setEffectiveLevel(4); } if (getExperience() < 10000) { - setLevel(5); + setEffectiveLevel(5); } if (getExperience() > 9999) { - setLevel(6); + setEffectiveLevel(6); } } @@ -60,19 +78,19 @@ public void setBasicHits(int basicHits) { mBasicHits = basicHits; } - public PlayerCharacter getPlayerCharacter() { + public PlayerCharacter getCharacter() { return mPlayerCharacter; } - public void setPlayerCharacter(PlayerCharacter playerCharacter) { + public void setCharacter(PlayerCharacter playerCharacter) { mPlayerCharacter = playerCharacter; } - public Score[] getPrimaryAttributes() { + public ArrayList getPrimaryAttributes() { return mPrimaryAttributes; } - public void setPrimaryAttributes(Score[] primaryAttributes) { + public void setPrimaryAttributes(ArrayList primaryAttributes) { mPrimaryAttributes = primaryAttributes; } @@ -124,9 +142,21 @@ public void setLevel(int level) { mLevel = level; } + public int getEffectiveLevel() { + return mEffectiveLevel; + } + + public void setEffectiveLevel(int effectiveLevel) { + mEffectiveLevel = effectiveLevel; + } + // Dummy Method // Returns the ResId of the level descriptions public int getLevelDescription() { return -12321; } + + // Dummy Methods + public void doLevelUp() {} + public void doLevelDown() {} } diff --git a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Level.java b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Level.java new file mode 100644 index 0000000..2dc9adb --- /dev/null +++ b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Level.java @@ -0,0 +1,13 @@ +package com.example.cis.mazeminotaurs.character.classes; + +import com.example.cis.mazeminotaurs.character.stats.Score; + +/** + * Created by jusmith on 4/10/17. + */ + +public interface Level { + void doLevelUp(); + void doLevelUp(Score score); + void doLevelDown(); +} diff --git a/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Magician.java b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Magician.java new file mode 100644 index 0000000..44d5314 --- /dev/null +++ b/MazesAndMinotaurs/app/src/main/java/com/example/cis/mazeminotaurs/character/classes/Magician.java @@ -0,0 +1,23 @@ +package com.example.cis.mazeminotaurs.character.classes; + +import com.example.cis.mazeminotaurs.character.stats.Score; + +/** + * Created by jusmith on 4/5/17. + */ + +public abstract class Magician extends BaseClass { + private int mSpecialTalentResId; + + public int getSpecialTalent(){ + int total = 0; + for (Score score: getPrimaryAttributes()) { + total += getCharacter().getScore(score).getModifier(); + } + return total; + } + + public int getMysticalStrength(){ + return 12 + getSpecialTalent(); + } +} \ No newline at end of file diff --git a/MazesAndMinotaurs/app/src/main/res/values/game_references.xml b/MazesAndMinotaurs/app/src/main/res/values/game_references.xml index 3c69b44..1ca3051 100644 --- a/MazesAndMinotaurs/app/src/main/res/values/game_references.xml +++ b/MazesAndMinotaurs/app/src/main/res/values/game_references.xml @@ -65,6 +65,11 @@ Female Either + + Copper + Silver + Gold + Local Hero