Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maghasemzadeh committed May 7, 2019
2 parents 06c3d68 + 1e8e1cd commit 4d66f62
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 33 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
10 changes: 5 additions & 5 deletions src/models/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ public List<Item> getCollectedItems() {
}

public void selectCollectableItem(String itemID) throws ItemNotFoundException {
List<CollectableItem> collectableItems = collectedItems.stream().filter(
item -> ((CollectableItem)item).getID().equals(itemID)).map(
item -> (CollectableItem)item)
List<CollectableItem> collectableItems = collectedItems.stream().filter(
item -> ((CollectableItem) item).getID().equals(itemID)).map(
item -> (CollectableItem) item)
.collect(Collectors.toList());
if(collectableItems.size() == 0)
if (collectableItems.size() == 0)
throw new ItemNotFoundException(Error.NO_ITEM.toString());
this.selectedCollectableItem = collectableItems.get(0);
}
Expand Down Expand Up @@ -212,7 +212,7 @@ public HeroDeadException(String message) {
}
}

public static class NoItemSelectedException extends Exception{
public static class NoItemSelectedException extends Exception {
public NoItemSelectedException(String message) {
super(message);
}
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
14 changes: 8 additions & 6 deletions src/models/map/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public Collection getCards() {
}

public Map() {
for(int i = 0; i < 5; i++)
for(int j = 0; j < 9; j++)
for (int i = 0; i < 5; i++)
for (int j = 0; j < 9; j++)
cells[i][j] = new Cell(i, j);
}

Expand Down Expand Up @@ -78,8 +78,8 @@ public boolean cellExist(int x, int y) {
}

public void insertCard(Card card, Cell cell) throws InvalidCellException, InvalidTargetCellException, Player.HeroDeadException {
if (cell.isFull())
throw new InvalidCellException(Error.CELL_FULL.toString());
if (cell.isFull() && (card instanceof Minion))
throw new InvalidCellException(Error.INVALID_TARGET.toString());
if (!cards.contains(card)) {
// TODO: 5/4/19 check if contains
}
Expand Down Expand Up @@ -140,7 +140,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 @@ -152,13 +152,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
2 changes: 1 addition & 1 deletion src/views/Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum Error {
OPPONENT_MINION_IS_NOT_AVAILABLE("minion opponent is not available for attack"),
CARD_NOT_IN_HAND("Card not found in hand"),
NOT_IN_GRAVEYARD("You are not in graveyard"),
ALREADY_IN_GRAVEYARD( "You were already in graveyard"),
ALREADY_IN_GRAVEYARD("You were already in graveyard"),
CARD_NOT_FOUND_IN_GRAVEYARD("Card not found in graveyard"),
NO_SELECTABLE_ITEM_SELECTED("No collectable item selected"),
CARD_SELECTED("card selected!"),
Expand Down
1 change: 1 addition & 0 deletions src/views/menus/BattleMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ public static void showCards(Matcher matcher) {
cards.forEach(Output::log);
}


public static void showMyHero(Matcher matcher) {
try {
Hero hero = Manager.getActivePlayer().getHero();
Expand Down

0 comments on commit 4d66f62

Please sign in to comment.