Skip to content

Commit

Permalink
Merge pull request #91 from aps2019project/Sadra
Browse files Browse the repository at this point in the history
Sadra
  • Loading branch information
sadraheydari authored May 6, 2019
2 parents 7fd361e + c0bf545 commit 4f75306
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 30 deletions.
3 changes: 1 addition & 2 deletions Files/Data/Accounts.json

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions src/control/BattleHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import java.util.regex.PatternSyntaxException;

public class BattleHandler extends Handler{
private static Game game;

public static BattlesOrderType getPlayingOrder() {
return null;
//
private static Game game = Game.getCurrentGame();
{
BattleScreen.setGame();
}
public void getOrder() {
handleCommands();
}

@Override
Expand All @@ -38,7 +39,7 @@ HandlerType handleCommands() {
if(!game.getWhoIsHisTurn().setSelectedCard(game.findInTable(command.split(" ")[1]))){
BattleScreen.showInvalidCardIdError();
}
}else if (command.matches("move to(\\d+,\\d+)")) {
}else if (command.matches("move to[(]\\d+,\\d+[)]")) {
if(!game.getWhoIsHisTurn().moveArmy(game.getWhoIsHisTurn().getSelectedCardPlace()
,getCell(command.split(" ")[1]))) {
BattleScreen.showInvalidMoveError();
Expand All @@ -57,7 +58,7 @@ HandlerType handleCommands() {
counter++;
}
game.getWhoIsHisTurn().attackCombo(opponentCardCell,myCardCell,cells);
}else if (command.matches("use special power(\\d+,\\d+)")) {
}else if (command.matches("use special power[(]\\d+,\\d+[)]")) {
if(!game.getWhoIsHisTurn().heroHaveSpecialPower()) {
BattleScreen.showDoesNotHaveSpecialPower();
}
Expand All @@ -68,7 +69,7 @@ HandlerType handleCommands() {

}else if (command.matches("show hand")) {
BattleScreen.showCardArray(game.getWhoIsHisTurn().getHand());
}else if (command.matches("insert \\w+ in (\\d+,\\d+)")) {
}else if (command.matches("insert \\w+ in [(]\\d+,\\d+[)]")) {
if(!game.getWhoIsHisTurn().moveFromHandToCell(command.split(" ")[1]
,getCell(command.split(" ")[3]))) {
BattleScreen.showInvalidCardNameError();
Expand All @@ -79,7 +80,7 @@ HandlerType handleCommands() {
//
}else if (command.matches("show info")) {
//
}else if (command.matches("use (\\d+,\\d+)")) {
}else if (command.matches("use [(]\\d+,\\d+[)]")) {
//
}else if (command.matches("show next card")) {
BattleScreen.showNextCardFromDeck();
Expand Down
10 changes: 3 additions & 7 deletions src/control/BattleMenuHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ HandlerType handleCommands() {
BattleScreen.showErrorInvalidDeck();
return MENU;
}
setPlayersSteps();
gotoChoosePlayerPage();
while (scanner.hasNext()) {
command = scanner.nextLine().toLowerCase().trim();
Expand Down Expand Up @@ -70,17 +71,12 @@ HandlerType handleCommands() {
return null;
}

public Deck getDeck(int deckNumber) {
return null;
//
}

public void setCustomDecks() {
//
}

public void setPlayersSteps() {
customPlayer = new IntelligentPlayer(new Account("customPlayer","1234"));
//customPlayer = new IntelligentPlayer(new Account("customPlayer","1234"));
Account account = new Account("firstLevelPlayer","1234");
try {
Card.makeStroyDeck(1, account);
Expand Down Expand Up @@ -290,5 +286,5 @@ enum PageState {
STORY,
CUSTOM_FIRST,
CUSTOM_SECOND,
NOTHING
NOTHING,
}
1 change: 1 addition & 0 deletions src/model/cards/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public static void makeStroyDeck(int storyNumber, Account account) throws Except
deck.addCard(item);
}
account.addDeck(deck);
account.changeMainDeck(deck);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/model/game/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean isEmpty() {
return insideArmy == null;
}
public boolean put(Army army,int turnNumber) {
if(this.isEmpty() || army == null) return false;
if(!this.isEmpty() || army == null) return false;
this.insideArmy = army;
army.setWhereItIs(this);
if(flag != null) {
Expand Down
8 changes: 5 additions & 3 deletions src/model/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public class Game {
public Game(Account firstAccount, Account secondAccount, GameType type) {
firstPlayer = new Player(firstAccount);
secondPlayer = new Player(secondAccount);
for(Cell[] row : table) {
for(Cell cell : row) {
allCellsInTable.add(cell);

for(int counter1 = 0 ; counter1 < TABLE_HEIGHT ; counter1++) {
for(int counter2 = 0 ; counter2 < TABLE_WIDTH ; counter2++) {
table[counter1][counter2] = new Cell(counter1,counter2);
allCellsInTable.add(table[counter1][counter2]);
}
}
this.type = type;
Expand Down
14 changes: 7 additions & 7 deletions src/model/game/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class Player {
protected Account account;
protected Deck deck;
protected Hand hand;
protected Hand hand = new Hand();
protected int mana;
protected CardsArray graveYard = new CardsArray();
protected CardsArray inGameCards = new CardsArray();
Expand Down Expand Up @@ -128,8 +128,8 @@ public void increaseTurnNumber() {
public void setMana() {
if (turnNumber <= 7) mana = turnNumber + 1;
else mana = 9;
if (this.usableItem.getName().equals("WisdomCrown") && turnNumber<4) mana++;
if (this.usableItem.getName().equals("KingWisdom")) mana++;
if (this.usableItem != null && this.usableItem.getName().equals("WisdomCrown") && turnNumber<4) mana++;
if (this.usableItem != null && this.usableItem.getName().equals("KingWisdom")) mana++;
if (this.usedManaPotion) mana += 3;
}

Expand All @@ -153,6 +153,7 @@ public void putHeroIn(Cell cell) {
this.hero = hero;
deck.deleteCard(hero);
cell.put(hero, turnNumber);
hero.setWhereItIs(cell);
this.inGameCards.add(hero);
}
public boolean isInRange(Cell attackersCell,Cell defenderCell) {
Expand Down Expand Up @@ -257,8 +258,10 @@ public void useCollectibleItem() {

public void startMatchSetup() {
deck.fillHand(hand);
if(this.usableItem == null) return;
try {
this.usableItemEffect(this.getUsableItem().getName());

}catch (Exception e){ }
}

Expand All @@ -278,10 +281,7 @@ public void play() {
increaseTurnNumber();
setMana();
deck.transferCardTo(hand);
while (!endTurn) {
BattlesOrderType orderType = BattleHandler.getPlayingOrder();
//////////
}
new BattleHandler().getOrder();
}

public boolean haveCard(Card card) {
Expand Down
1 change: 1 addition & 0 deletions src/model/variables/CardsArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public ArrayList<Army> getArmy() {
}

public Card find(Card card) {
if(card == null) return null;
return find(card.getID().getValue());
}

Expand Down
5 changes: 4 additions & 1 deletion src/view/BattleScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import static model.game.GameType.*;

public class BattleScreen extends Screen{
private static Game game;
private static Game game = Game.getCurrentGame();
public static void setGame() {
game = Game.getCurrentGame();
}
public static void showGameInfo(){
System.out.println("firstPlayer mana is"+game.getFirstPlayer().getMana());
System.out.println("secondPlayer mana is"+game.getSecondPlayer().getMana());
Expand Down

0 comments on commit 4f75306

Please sign in to comment.