Skip to content

Commit

Permalink
target type json bugs fixed not completely
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiHma committed May 7, 2019
1 parent 7c88329 commit 1e8e1cd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
13 changes: 12 additions & 1 deletion src/data/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import models.cards.buff.*;
import models.cards.spell.SpecialPowerActivateTime;
import models.cards.spell.Spell;
import models.cards.spell.TargetType;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -143,6 +144,16 @@ public static List<Card> getSpells() throws FileNotFoundException, JSONException
(int) spellHashMap.get("manaPoint"),
(int) spellHashMap.get("price")
);
TargetType targetType = null;
try {
targetType = TargetType.valueOf(
(String)
spellHashMap.get("targetType")
);
} catch (Exception e) {
e.printStackTrace();
}
spell.setTargetType(targetType);
List<Object> buffs = (List<Object>) spellHashMap.get("effect");
for(Object buffObject : buffs) {
HashMap<String, Object> buffHashMap = (HashMap<String, Object>) buffObject;
Expand All @@ -151,7 +162,7 @@ public static List<Card> getSpells() throws FileNotFoundException, JSONException
public void buffEffect(Card card) {}
};

if(((String) buffHashMap.get("name")).equalsIgnoreCase("DisarmBuff")) {
if(((String) buffHashMap.get("name")).equalsIgnoreCase("DisarmBuffDisarmBuff")) {
buff = new DisarmBuff(
(int) buffHashMap.get("maxActivateTime"),
(boolean) buffHashMap.get("isContinues")
Expand Down
36 changes: 18 additions & 18 deletions src/data/spell.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"name": "DisarmBuff",
"isContinues": true,
"activeTime": 0
"maxActivateTime": 0
}
]
},
Expand Down Expand Up @@ -37,7 +37,7 @@
{
"name": "PowerBuff",
"isContinues": false,
"activeTime": 1,
"maxActivateTime": 1,
"powerPoint": 2
}
]
Expand All @@ -51,7 +51,7 @@
{
"name": "PoisonBuff",
"isContinues": false,
"activeTime": 1,
"maxActivateTime": 1,
"healthPoint": 4
}
]
Expand All @@ -65,7 +65,7 @@
{
"name": "PowerBuff",
"isContinues": false,
"activeTime": 1,
"maxActivateTime": 1,
"powerPoint": 4
}
]
Expand All @@ -86,7 +86,7 @@
{
"name": "PoisonBuff",
"isContinues": false,
"activeTime": 1,
"maxActivateTime": 1,
"healthPoint": 8
}
]
Expand All @@ -108,12 +108,12 @@
"name": "PowerBuff",
"isContinues": false,
"powerPoint": 4,
"activeTime": 3
"maxActivateTime": 3
},
{
"name": "DisarmBuff",
"isContinues": false,
"activeTime": 3
"maxActivateTime": 3
}
]
},
Expand All @@ -126,7 +126,7 @@
{
"name": "DisarmBuff",
"isContinues": false,
"activeTime": 1
"maxActivateTime": 1
}
]
},
Expand All @@ -139,7 +139,7 @@
{
"name": "PoisonBuff",
"isContinues": false,
"activeTime": 4,
"maxActivateTime": 4,
"healthPoint": 1
}
]
Expand All @@ -153,12 +153,12 @@
{
"name": "OPPONENT_BUFF_KILLER",
"isContinues": false,
"activeTime": 1
"maxActivateTime": 1
},
{
"name": "MY_BUFF_KILLER",
"isContinues": false,
"activeTime": 1
"maxActivateTime": 1
}
]
},
Expand All @@ -171,19 +171,19 @@
{
"name": "PoisonBuff",
"isContinues": false,
"activeTime": 1,
"maxActivateTime": 1,
"healthPoint": 6
},
{
"name": "HolyBuff",
"isContinues": false,
"activeTime": 3,
"maxActivateTime": 3,
"healthPoint": 1
},
{
"name": "HolyBuff",
"isContinues": false,
"activeTime": 3,
"maxActivateTime": 3,
"healthPoint": 1
}
]
Expand All @@ -197,7 +197,7 @@
{
"name": "PowerBuff",
"isContinues": false,
"activeTime": 1,
"maxActivateTime": 1,
"powerPoint": 6
}
]
Expand All @@ -211,7 +211,7 @@
{
"name": "PowerBuff",
"isContinues": true,
"activeTime": 0,
"maxActivateTime": 0,
"powerPoint": 2
}
]
Expand All @@ -234,7 +234,7 @@
"name": "Weakening",
"price": 1000,
"manaPoint": 1,
"targetType": "ONE_OPPONENT_MINION",
"targetType": "AN_OPPONENT_MINION",
"effect": [
{
"name": "WeaknessBuff",
Expand Down Expand Up @@ -275,7 +275,7 @@
"name": "Shock",
"price": 1200,
"manaPoint": 9,
"targetType": "AN_OPPONENT_HERO",
"targetType": "OPPONENT_HERO",
"effect": [
{
"name": "StunBuff",
Expand Down
4 changes: 4 additions & 0 deletions src/models/cards/spell/Spell.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public TargetType getTargetType() {
return targetType;
}

public void setTargetType(TargetType targetType) {
this.targetType = targetType;
}

public Spell(int id, String name, String description, int manaPoint, int price) {
super(id, name, description, manaPoint, price);
}
Expand Down
6 changes: 4 additions & 2 deletions src/models/cards/spell/TargetType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
public enum TargetType {
AN_OPPONENT_FORCE("attack to one enemy minion."),
SQUARE2x2("attack to a 2×2 square in map."),
ALL_OPPONENT_FORCES("attack to all enemy minion."),
ALL_OPPONENT_FORCE("attack to all enemy minion."),
MY_FORCE("apply to my force."),
MY_HERO("apply to my hero"),
OPPONENT_HERO(""),
OPPONENT_FORCE_OR_MY_FORCE(""),
SQUARE3x3("attack to a 3×3 square in map."),
ALL_MY_FORCE("apply to all attackers."),
ALL_OPPONENT_FORCES_IN_ONE_COLUMN("attack to all opponent attacker in one column."),
ALL_OPPONENT_FORCE_IN_ONE_COLUMN("attack to all opponent attacker in one column."),
AN_OPPONENT_MINION(""),
MY_MINION("");

private final String description;

TargetType(String description) {
Expand Down
6 changes: 4 additions & 2 deletions src/models/map/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private List<Cell> getEffectCells(Spell spell, Cell cell) throws InvalidTargetCe
return targetCells;
}
break;
case ALL_OPPONENT_FORCES:
case ALL_OPPONENT_FORCE:
Manager.getInActivePlayer().getActiveCards().forEach(
card -> targetCells.add(card.getCell())
);
Expand All @@ -149,13 +149,15 @@ private List<Cell> getEffectCells(Spell spell, Cell cell) throws InvalidTargetCe
return targetCells;
}
return targetCells;
case ALL_OPPONENT_FORCES_IN_ONE_COLUMN:
case ALL_OPPONENT_FORCE_IN_ONE_COLUMN:
for (int i = 0; i < 5; i++) {
if (cells[i][cell.getY()].getAttacker() != null) {
targetCells.add(cells[i][cell.getY()]);
}
}
return targetCells;
case OPPONENT_HERO:

}
throw new InvalidTargetCellException();
}
Expand Down

0 comments on commit 1e8e1cd

Please sign in to comment.