Skip to content

Commit

Permalink
Merge pull request #99 from aps2019project/Sadra
Browse files Browse the repository at this point in the history
battle update
  • Loading branch information
sadraheydari authored May 7, 2019
2 parents 27a57b9 + ed05b2b commit 6692ad9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Files/Data/Accounts.json

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions src/control/BattleHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void getOrder() {

@Override
HandlerType handleCommands() {
while (scanner.hasNext() && !game.getWhoIsHisTurn().isEndTurn()) {
while (!game.getWhoIsHisTurn().isEndTurn() && scanner.hasNext()) {
command = scanner.nextLine().toLowerCase().trim();
if (command.matches("game info")) {
BattleScreen.showGameInfo();
Expand Down Expand Up @@ -69,9 +69,9 @@ 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]))) {
,getCell(command.split(" ")[2]))) {
BattleScreen.showInvalidCardNameError();
}
}else if (command.matches("end turn")) {
Expand All @@ -85,8 +85,8 @@ HandlerType handleCommands() {
}else if (command.matches("show next card")) {
BattleScreen.showNextCardFromDeck();
}else if (command.matches("enter graveyard")) {
game.getWhoIsHisTurn().getGraveYard();
}else if (command.matches("show info \\d+")) {
game.getWhoIsHisTurn().goToGraveYard();
}else if (command.matches("show info [^ ]")) {
if(game.getWhoIsHisTurn().isInGraveYard())
BattleScreen.showCard(game.getWhoIsHisTurn().getGraveYard().find(command.split(" ")[2]));
else
Expand All @@ -98,8 +98,16 @@ HandlerType handleCommands() {
BattleScreen.showErrorYourNotInGraveYard();
}else if (command.matches("help")) {
whatYouCanDo(game.getWhoIsHisTurn().getAccount());
} else {
//
} else if (command.matches("exit")) {
if(game.getWhoIsHisTurn().isInGraveYard()) {
game.getWhoIsHisTurn().exitFromGraveYard();
}
else {
BattleScreen.showErrorYourNotInGraveYard();
}
}
else {
BattleScreen.showInvalidCommand();
}
}
return HandlerType.BATTLE;
Expand Down
72 changes: 48 additions & 24 deletions src/control/BattleMenuHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,7 @@ HandlerType handleCommands() {
while (scanner.hasNext()) {
command = scanner.nextLine().toLowerCase().trim();
System.out.println(pageState);
if(command.matches("\\d")) {
if (pageState == PageState.CHOOSE_NUMBER_OF_PLAYERS) {
handleChoosePlayer();
} else if (pageState == PageState.SINGLE_PLAYER_GAME_TYPES) {
handleSinglePlayer();
} else if (pageState == PageState.MULTI_PLAYER_GAME_TYPES_FIRST) {
handleMultiPlayerFirstMenu();
} else if (pageState == PageState.MULTI_PLAYER_GAME_TYPES_SECOND) {
handleMultiPlayerSecondMenu();
} else if (pageState == PageState.STORY) {
handleStory();
} else if (pageState == PageState.CUSTOM_FIRST) {
handleCustomFirstPage();
} else if (pageState == PageState.CUSTOM_SECOND) {
handleCustomSecondPage();
}
} else if (command.matches("exit")) {
if (command.matches("exit")) {
if (pageState == PageState.CHOOSE_NUMBER_OF_PLAYERS) {

return MENU;
Expand All @@ -66,30 +50,53 @@ HandlerType handleCommands() {
} else if (pageState == PageState.CUSTOM_SECOND) {
gotoCustomMenuFirstPage();
}
}
} else {
if (pageState == PageState.CHOOSE_NUMBER_OF_PLAYERS) {
handleChoosePlayer();
} else if (pageState == PageState.SINGLE_PLAYER_GAME_TYPES) {
handleSinglePlayer();
} else if (pageState == PageState.MULTI_PLAYER_GAME_TYPES_FIRST) {
handleMultiPlayerFirstMenu();
} else if (pageState == PageState.MULTI_PLAYER_GAME_TYPES_SECOND) {
handleMultiPlayerSecondMenu();
} else if (pageState == PageState.STORY) {
handleStory();
} else if (pageState == PageState.CUSTOM_FIRST) {
handleCustomFirstPage();
} else if (pageState == PageState.CUSTOM_SECOND) {
handleCustomSecondPage();
}
}
}
return null;
}

public void setCustomDecks() {
//
if(hero == null) return;
for(Deck deck : customDecks) {
deck.deleteCard(deck.getHero());
deck.addCard(hero);
}
}

public void setPlayersSteps() {
//customPlayer = new IntelligentPlayer(new Account("customPlayer","1234"));
Account account = new Account("firstLevelPlayer","1234");
try {
Card.makeStroyDeck(1, account);
customDecks.add(account.getAllDecks().get(0));
} catch (Exception e){}
firstLevelPlayer = new IntelligentPlayer(account);
account = new Account("secondLevelPlayer","1234");
try {
Card.makeStroyDeck(2, account);
customDecks.add(account.getAllDecks().get(0));
} catch (Exception e){}
secondLevelPlayer = new IntelligentPlayer(account);
account = new Account("thirdLevelPlayer","1234");
try {
Card.makeStroyDeck(3, account);
customDecks.add(account.getAllDecks().get(0));
} catch (Exception e){}
thirdLevelPlayer = new IntelligentPlayer(account);
}
Expand Down Expand Up @@ -144,6 +151,7 @@ private void gotoCustomMenuFirstPage() {

private void gotoCustomMenuSecondPage() {
pageState = PageState.CUSTOM_SECOND;
setCustomDecks();
BattleScreen.decks(customDecks);
}

Expand All @@ -156,14 +164,14 @@ private void showAllAccounts() {
}

private void playGame(int numberOfFlags) {
if(!secondAccount.getMainDeck().checkIfValid()) {
if(secondAccount.getMainDeck() == null || !secondAccount.getMainDeck().checkIfValid()) {
BattleScreen.showInvalidDeckInMultiPlayer();
return;
}
Game game = new Game(account,secondAccount,type,numberOfFlags);
game.startMatch();
MatchResult result = game.getResults();
//set reward
System.out.println("this account win: "+game.getWinner().getUsername());
}

private void playGame(int numberOfFlags,IntelligentPlayer player) {
Expand Down Expand Up @@ -257,18 +265,34 @@ private void handleCustomFirstPage() {

private void handleCustomSecondPage() {
if(command.matches("start game \\d+ 1")) {
if(Integer.parseInt(command.split(" ")[2]) > customDecks.size()) {
BattleScreen.showErrorInvalidDeck();
}
type = GameType.KILL_HERO;
customPlayer.setDeck(customDecks.get(Integer.parseInt(command.split(" ")[2])));
Account account = new Account("customplayer","1234");
account.setMainDeck(customDecks.get(Integer.parseInt(command.split(" ")[2])));
customPlayer = new IntelligentPlayer(account);
playGame(0,customPlayer);
}
else if(command.matches("start game \\d+ 2")) {
if(Integer.parseInt(command.split(" ")[2]) >= customDecks.size()) {
BattleScreen.showErrorInvalidDeck();
return;
}
type = GameType.CAPTURE_THE_FLAG;
customPlayer.setDeck(customDecks.get(Integer.parseInt(command.split(" ")[2])));
Account account = new Account("customplayer","1234");
account.setMainDeck(customDecks.get(Integer.parseInt(command.split(" ")[2])));
customPlayer = new IntelligentPlayer(account);
playGame(1,customPlayer);
}
else if(command.matches("start game \\d+ 3 \\d+")) {
if(Integer.parseInt(command.split(" ")[2]) > customDecks.size()) {
BattleScreen.showErrorInvalidDeck();
}
type = GameType.ROLLUP_FLAGS;
customPlayer.setDeck(customDecks.get(Integer.parseInt(command.split(" ")[2])));
Account account = new Account("customplayer","1234");
account.setMainDeck(customDecks.get(Integer.parseInt(command.split(" ")[2])));
customPlayer = new IntelligentPlayer(account);
playGame(Integer.parseInt(command.split(" ")[4]),customPlayer);
}

Expand Down
12 changes: 8 additions & 4 deletions src/model/game/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Player {
protected boolean heroKilled = false;
protected Hero hero;
protected Cell selectedCardPlace;
protected boolean InGraveYard = false;
protected boolean inGraveYard = false;
private CardsArray collectibleItem = new CardsArray();
private Item usableItem;
protected Cell selectedCellToPutFromHand;
Expand Down Expand Up @@ -73,6 +73,10 @@ public CardsArray getGraveYard() {
return graveYard;
}

public void exitFromGraveYard() {
inGraveYard = false;
}

public CardsArray getMovedCardsInThisTurn() {
return movedCardsInThisTurn;
}
Expand Down Expand Up @@ -407,11 +411,11 @@ public Army getNearestEnemy(Cell cell) {
}

public void goToGraveYard() {
InGraveYard = true;
inGraveYard = true;
}

public void ExitFromGraveYard() {
InGraveYard = false;
inGraveYard = false;
}

public CardsArray getFriendsAround(Cell cell) {
Expand All @@ -425,7 +429,7 @@ public CardsArray getEnemiesInDistance2(Cell cell) {
}

public boolean isInGraveYard() {
return InGraveYard;
return inGraveYard;
}

public Cell getOneCell() {
Expand Down
4 changes: 3 additions & 1 deletion src/model/other/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public CardsArray getCollection() {
public ArrayList<Deck> getAllDecks() {
return allDecks;
}

public void setMainDeck(Deck deck) {
this.mainDeck = deck;
}
public Deck findDeck(String name) {
for (Deck deck : allDecks) {
if (deck.getName().equals(name))
Expand Down
15 changes: 13 additions & 2 deletions src/view/BattleScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ public static void showMinion(Minion minion) {
System.out.println("Cost: "+minion.getRace());//
System.out.println("Desc:");//
}
public static void showSpell(Spell spell) {
public static void showItem(Item item) {
System.out.println("Item: ");
System.out.println("Name:"+item.getName());;
System.out.println("ID:"+item.getID());;

}
public static void showSpell(Spell spell) {
System.out.println("Spell:");
System.out.println("Name: "+spell.getName());
System.out.println("MP: ");//
Expand All @@ -76,6 +82,7 @@ public static void showCard(Card card) {
if(card instanceof Hero) showHero((Hero)card);
else if(card instanceof Minion) showMinion((Minion)card);
else if(card instanceof Spell) showSpell((Spell)card);
else if(card instanceof Item) showItem((Item)card);
}
public static void showInvalidCardIdError() {
System.out.println("Invalid card id");
Expand Down Expand Up @@ -183,7 +190,6 @@ public static void showNotEnoughMana(){

public static void showCollectibles(CardsArray array){
ArrayList<Item> items = array.getAllItems();

System.out.println("Item:");
for (int i = 1; i <= items.size(); ++i) {
Item item = items.get(i - 1);
Expand All @@ -192,4 +198,9 @@ public static void showCollectibles(CardsArray array){
item.getDescription());
}
}
public static void showItems() {
for(Item item : game.getWhoIsHisTurn().getCollectibleItem().getAllItems()) {
showCard(item);
}
}
}

0 comments on commit 6692ad9

Please sign in to comment.